From e7d3c97729edc6c89ef4a6e53d460b6ee72ef099 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 24 Mar 2020 15:23:07 +0100 Subject: [PATCH] [12.0][IMP] - support Camt 053 in account_payment_return_import_iso20022 --- .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 +- .../test_files/test-sepa-camt-053-unpaid.xml | 111 +++++++++ ...paid.xml => test-sepa-camt-054-unpaid.xml} | 220 +++++++++--------- .../tests/test_import_iso20022.py | 21 +- .../wizard/camt_parser.py | 16 +- 6 files changed, 253 insertions(+), 118 deletions(-) create mode 100644 account_payment_return_import_iso20022/test_files/test-sepa-camt-053-unpaid.xml rename account_payment_return_import_iso20022/test_files/{test-sepa-camt-unpaid.xml => test-sepa-camt-054-unpaid.xml} (97%) diff --git a/account_payment_return_import_iso20022/readme/CONTRIBUTORS.rst b/account_payment_return_import_iso20022/readme/CONTRIBUTORS.rst index a531800e7d1b..52f80934c41d 100644 --- a/account_payment_return_import_iso20022/readme/CONTRIBUTORS.rst +++ b/account_payment_return_import_iso20022/readme/CONTRIBUTORS.rst @@ -3,3 +3,4 @@ * David Vidal * Luis M. Ontalba * Thomas Binsfeld +* Souheil Bejaoui diff --git a/account_payment_return_import_iso20022/readme/DESCRIPTION.rst b/account_payment_return_import_iso20022/readme/DESCRIPTION.rst index dfbbcf7c2ec7..2998990b0e58 100644 --- a/account_payment_return_import_iso20022/readme/DESCRIPTION.rst +++ b/account_payment_return_import_iso20022/readme/DESCRIPTION.rst @@ -1 +1 @@ -Module to import payment returns from pain.002.001.03 and camt.054.001.02 files. +Module to import payment returns from pain.002.001.03, camt.053.001.02 and camt.054.001.02 files. diff --git a/account_payment_return_import_iso20022/test_files/test-sepa-camt-053-unpaid.xml b/account_payment_return_import_iso20022/test_files/test-sepa-camt-053-unpaid.xml new file mode 100644 index 000000000000..55dd29b2dfe0 --- /dev/null +++ b/account_payment_return_import_iso20022/test_files/test-sepa-camt-053-unpaid.xml @@ -0,0 +1,111 @@ + + + + + MSGID99345678912 + 2016-10-08T20:49:00 + + + ZY08XXXXXXIS634C + 2016-10-08T20:49:00 + + + NL77ABNA0574908765 + + EUR + + + BOFIIE2D + + + + + + 0 + 0.00 + + + 1 + 100 + + + + 100.00 + DBIT + BOOK + +
2016-10-08
+
+ + + PMNT + + IDDT + UPDD + + + + B3/0811 + + + + + + FA031615104 + E2EID1 + MANDATEID2 + + + + 100.00 + + + + + DEBTOR4 + + + + IE16AIBK93110187654321 + + + + CREDITOR + + + + IE03ZZZ123456 + + SEPA + + + + + + + + FACTURE DU 15.03.16 + + + 2016-10-09 + + + + + + BOFIIE2D + + + + + AC06 + + /RTYP/RTRN + + /SQTP/RCUR/DTOFSGNT/2013-11-14 + + +
+
+
+
diff --git a/account_payment_return_import_iso20022/test_files/test-sepa-camt-unpaid.xml b/account_payment_return_import_iso20022/test_files/test-sepa-camt-054-unpaid.xml similarity index 97% rename from account_payment_return_import_iso20022/test_files/test-sepa-camt-unpaid.xml rename to account_payment_return_import_iso20022/test_files/test-sepa-camt-054-unpaid.xml index 321b2c6f0327..68e1e22a8e7c 100644 --- a/account_payment_return_import_iso20022/test_files/test-sepa-camt-unpaid.xml +++ b/account_payment_return_import_iso20022/test_files/test-sepa-camt-054-unpaid.xml @@ -1,111 +1,111 @@ - - - - - MSGID99345678912 - 2016-10-08T20:49:00 - - - ZY08XXXXXXIS634C - 2016-10-08T20:49:00 - - - NL77ABNA0574908765 - - EUR - - - BOFIIE2D - - - - - - 0 - 0.00 - - - 1 - 100 - - - - 100.00 - DBIT - BOOK - -
2016-10-08
-
- - - PMNT - - IDDT - UPDD - - - - B3/0811 - - - - - - FA031615104 - E2EID1 - MANDATEID2 - - - - 100.00 - - - - - DEBTOR4 - - - - IE16AIBK93110187654321 - - - - CREDITOR - - - - IE03ZZZ123456 - - SEPA - - - - - - - - FACTURE DU 15.03.16 - - - 2016-10-09 - - - - - - BOFIIE2D - - - - - AC06 - - /RTYP/RTRN - - /SQTP/RCUR/DTOFSGNT/2013-11-14 - - -
-
-
+ + + + + MSGID99345678912 + 2016-10-08T20:49:00 + + + ZY08XXXXXXIS634C + 2016-10-08T20:49:00 + + + NL77ABNA0574908765 + + EUR + + + BOFIIE2D + + + + + + 0 + 0.00 + + + 1 + 100 + + + + 100.00 + DBIT + BOOK + +
2016-10-08
+
+ + + PMNT + + IDDT + UPDD + + + + B3/0811 + + + + + + FA031615104 + E2EID1 + MANDATEID2 + + + + 100.00 + + + + + DEBTOR4 + + + + IE16AIBK93110187654321 + + + + CREDITOR + + + + IE03ZZZ123456 + + SEPA + + + + + + + + FACTURE DU 15.03.16 + + + 2016-10-09 + + + + + + BOFIIE2D + + + + + AC06 + + /RTYP/RTRN + + /SQTP/RCUR/DTOFSGNT/2013-11-14 + + +
+
+
\ No newline at end of file diff --git a/account_payment_return_import_iso20022/tests/test_import_iso20022.py b/account_payment_return_import_iso20022/tests/test_import_iso20022.py index 9361d95c50be..10c3e6415d54 100644 --- a/account_payment_return_import_iso20022/tests/test_import_iso20022.py +++ b/account_payment_return_import_iso20022/tests/test_import_iso20022.py @@ -74,7 +74,7 @@ def test_zip_import_pain(self): date='2016-10-08' ) - def test_payment_return_import_camt(self): + def test_payment_return_import_camt_053(self): """Test correct creation of single payment return.""" transactions = [ { @@ -85,7 +85,24 @@ def test_payment_return_import_camt(self): ] self._test_return_import( 'account_payment_return_import_iso20022', - 'test-sepa-camt-unpaid.xml', + 'test-sepa-camt-053-unpaid.xml', + 'ZY08XXXXXXIS634C', + local_account='NL77ABNA0574908765', + date='2016-10-08', transactions=transactions + ) + + def test_payment_return_import_camt_054(self): + """Test correct creation of single payment return.""" + transactions = [ + { + 'returned_amount': 100.00, + 'reference': 'E2EID1', + 'reason_add_info': '/RTYP/RTRN', + }, + ] + self._test_return_import( + 'account_payment_return_import_iso20022', + 'test-sepa-camt-054-unpaid.xml', 'ZY08XXXXXXIS634C', local_account='NL77ABNA0574908765', date='2016-10-08', transactions=transactions diff --git a/account_payment_return_import_iso20022/wizard/camt_parser.py b/account_payment_return_import_iso20022/wizard/camt_parser.py index c4e8c1229da8..0004269a6e09 100644 --- a/account_payment_return_import_iso20022/wizard/camt_parser.py +++ b/account_payment_return_import_iso20022/wizard/camt_parser.py @@ -10,7 +10,9 @@ ) RE_CAMT_VERSION = re.compile( r'(^urn:iso:std:iso:20022:tech:xsd:camt.054.001.02' - r'|^ISO:camt.054.001.02)' + r'|^ISO:camt.054.001.02' + r'|^urn:iso:std:iso:20022:tech:xsd:camt.053.001.02' + r'|^ISO:camt.053.001.02)' ) @@ -24,7 +26,8 @@ def parse_amount(ns, node): return 0.0 amount = 0.0 amount_node = node.xpath( - './ns:AmtDtls/ns:InstdAmt/ns:Amt', namespaces={'ns': ns}) + './ns:AmtDtls/ns:InstdAmt/ns:Amt | ./ns:AmtDtls/ns:TxAmt/ns:Amt', + namespaces={'ns': ns}) if amount_node: amount = float(amount_node[0].text) return amount @@ -86,6 +89,7 @@ def parse_transactions(self, ns, node, transactions): """ details_nodes = node.xpath( './ns:NtryDtls/ns:TxDtls', namespaces={'ns': ns}) + entry_date = node.xpath('./ns:BookgDt/ns:Dt', namespaces={'ns': ns}) for details_node in details_nodes: return_info = details_node.xpath( './ns:RtrInf', namespaces={'ns': ns}) @@ -95,6 +99,8 @@ def parse_transactions(self, ns, node, transactions): transaction['amount'] = self.parse_amount(ns, details_node) self.parse_transaction_details(ns, details_node, transaction) transaction['raw_import_data'] = etree.tostring(details_node) + if not transaction.get('date'): + transaction['date'] = entry_date transactions.append(transaction) return transactions @@ -105,7 +111,7 @@ def parse_payment_returns(self, ns, node): return_date = self.parse_date(ns, node) payment_returns = [] notification_nodes = node.xpath( - './ns:Ntfctn', namespaces={'ns': ns}) + './ns:Ntfctn | ./ns:Stmt', namespaces={'ns': ns}) for notification_node in notification_nodes: entry_nodes = notification_node.xpath( './ns:Ntry', namespaces={'ns': ns}) @@ -135,7 +141,7 @@ def parse_payment_returns(self, ns, node): def check_version(self, ns, root): """ - Check whether the validity of the camt.054.001.02 file. + Check whether the validity of the camt file. :raise: ValueError if not valid """ # Check whether it's a CAMT Bank to Customer Debit Credit Notification @@ -151,7 +157,7 @@ def check_version(self, ns, root): def parse(self, data): """ - Parse a camt.054.001.02 file. + Parse camt.054.001.02 file and camt.053 .001.02 files. :param data: :return: account.payment.return records list :raise: ValueError if parsing failed