Skip to content

Commit 61bf0d4

Browse files
committed
[12.0][IMP] - support Camt 053 in account_payment_return_import_iso20022
1 parent 4f7c56d commit 61bf0d4

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

account_payment_return_import_iso20022/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Account Payment Return Import Iso20022
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
2727

28-
Module to import payment returns from pain.002.001.03 and camt.054.001.02 files.
28+
Module to import payment returns from pain.002.001.03, camt.053.001.02 and camt.054.001.02 files.
2929

3030
**Table of contents**
3131

@@ -65,6 +65,7 @@ Contributors
6565
* David Vidal <[email protected]>
6666
* Luis M. Ontalba <[email protected]>
6767
* Thomas Binsfeld <[email protected]>
68+
* Souheil Bejaoui <[email protected]>
6869

6970
Maintainers
7071
~~~~~~~~~~~

account_payment_return_import_iso20022/readme/CONTRIBUTORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
* David Vidal <[email protected]>
44
* Luis M. Ontalba <[email protected]>
55
* Thomas Binsfeld <[email protected]>
6+
* Souheil Bejaoui <[email protected]>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Module to import payment returns from pain.002.001.03 and camt.054.001.02 files.
1+
Module to import payment returns from pain.002.001.03, camt.053.001.02 and camt.054.001.02 files.

account_payment_return_import_iso20022/wizard/camt_parser.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
)
1111
RE_CAMT_VERSION = re.compile(
1212
r'(^urn:iso:std:iso:20022:tech:xsd:camt.054.001.02'
13-
r'|^ISO:camt.054.001.02)'
13+
r'|^ISO:camt.054.001.02'
14+
r'|^urn:iso:std:iso:20022:tech:xsd:camt.053.001.02'
15+
r'|^ISO:camt.053.001.02)'
1416
)
1517

1618

@@ -24,7 +26,8 @@ def parse_amount(ns, node):
2426
return 0.0
2527
amount = 0.0
2628
amount_node = node.xpath(
27-
'./ns:AmtDtls/ns:InstdAmt/ns:Amt', namespaces={'ns': ns})
29+
'./ns:AmtDtls/ns:InstdAmt/ns:Amt | ./ns:AmtDtls/ns:TxAmt/ns:Amt',
30+
namespaces={'ns': ns})
2831
if amount_node:
2932
amount = float(amount_node[0].text)
3033
return amount
@@ -105,15 +108,22 @@ def parse_payment_returns(self, ns, node):
105108
return_date = self.parse_date(ns, node)
106109
payment_returns = []
107110
notification_nodes = node.xpath(
108-
'./ns:Ntfctn', namespaces={'ns': ns})
111+
'./ns:Ntfctn | ./ns:Stmt', namespaces={'ns': ns})
109112
for notification_node in notification_nodes:
110113
entry_nodes = notification_node.xpath(
111114
'./ns:Ntry', namespaces={'ns': ns})
112115
for i, entry_node in enumerate(entry_nodes):
113116
payment_return = {}
114117
self.add_value_from_node(
115118
ns, notification_node, './ns:Id', payment_return, 'name')
116-
payment_return['date'] = return_date
119+
self.add_value_from_node(
120+
ns, notification_node, './ns:ValDt/ns:Dt',
121+
payment_return, 'date')
122+
if payment_return.get('date'):
123+
entry_date = payment_return['date']
124+
else:
125+
entry_date = return_date
126+
payment_return['date'] = entry_date
117127
self.add_value_from_node(
118128
ns, notification_node, './ns:Acct/ns:Id/ns:IBAN',
119129
payment_return, 'account_number')
@@ -123,6 +133,8 @@ def parse_payment_returns(self, ns, node):
123133
payment_return['transactions'].extend(transactions)
124134
subno = 0
125135
for transaction in payment_return['transactions']:
136+
if not transaction.get('date'):
137+
transaction['date'] = entry_date
126138
subno += 1
127139
transaction['unique_import_id'] = \
128140
"{return_name}{entry_subno}{transaction_subno}".format(
@@ -135,7 +147,7 @@ def parse_payment_returns(self, ns, node):
135147

136148
def check_version(self, ns, root):
137149
"""
138-
Check whether the validity of the camt.054.001.02 file.
150+
Check whether the validity of the camt file.
139151
:raise: ValueError if not valid
140152
"""
141153
# Check whether it's a CAMT Bank to Customer Debit Credit Notification
@@ -151,7 +163,7 @@ def check_version(self, ns, root):
151163

152164
def parse(self, data):
153165
"""
154-
Parse a camt.054.001.02 file.
166+
Parse camt.054.001.02 file and camt.053 .001.02 files.
155167
:param data:
156168
:return: account.payment.return records list
157169
:raise: ValueError if parsing failed

0 commit comments

Comments
 (0)