10
10
)
11
11
RE_CAMT_VERSION = re .compile (
12
12
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)'
14
16
)
15
17
16
18
@@ -24,7 +26,8 @@ def parse_amount(ns, node):
24
26
return 0.0
25
27
amount = 0.0
26
28
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 })
28
31
if amount_node :
29
32
amount = float (amount_node [0 ].text )
30
33
return amount
@@ -105,15 +108,22 @@ def parse_payment_returns(self, ns, node):
105
108
return_date = self .parse_date (ns , node )
106
109
payment_returns = []
107
110
notification_nodes = node .xpath (
108
- './ns:Ntfctn' , namespaces = {'ns' : ns })
111
+ './ns:Ntfctn | ./ns:Stmt ' , namespaces = {'ns' : ns })
109
112
for notification_node in notification_nodes :
110
113
entry_nodes = notification_node .xpath (
111
114
'./ns:Ntry' , namespaces = {'ns' : ns })
112
115
for i , entry_node in enumerate (entry_nodes ):
113
116
payment_return = {}
114
117
self .add_value_from_node (
115
118
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
117
127
self .add_value_from_node (
118
128
ns , notification_node , './ns:Acct/ns:Id/ns:IBAN' ,
119
129
payment_return , 'account_number' )
@@ -123,6 +133,8 @@ def parse_payment_returns(self, ns, node):
123
133
payment_return ['transactions' ].extend (transactions )
124
134
subno = 0
125
135
for transaction in payment_return ['transactions' ]:
136
+ if not transaction .get ('date' ):
137
+ transaction ['date' ] = entry_date
126
138
subno += 1
127
139
transaction ['unique_import_id' ] = \
128
140
"{return_name}{entry_subno}{transaction_subno}" .format (
@@ -135,7 +147,7 @@ def parse_payment_returns(self, ns, node):
135
147
136
148
def check_version (self , ns , root ):
137
149
"""
138
- Check whether the validity of the camt.054.001.02 file.
150
+ Check whether the validity of the camt file.
139
151
:raise: ValueError if not valid
140
152
"""
141
153
# Check whether it's a CAMT Bank to Customer Debit Credit Notification
@@ -151,7 +163,7 @@ def check_version(self, ns, root):
151
163
152
164
def parse (self , data ):
153
165
"""
154
- Parse a camt.054.001.02 file.
166
+ Parse camt.054.001.02 file and camt.053 .001.02 files .
155
167
:param data:
156
168
:return: account.payment.return records list
157
169
:raise: ValueError if parsing failed
0 commit comments