mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[FIX] Don't mind multiple NtryDtls entries
[FIX] Mind missing NtryDtls entry [RFR] Remove singleton [FIX] Mind missing message
This commit is contained in:
@@ -119,15 +119,15 @@ CAMT Format parser
|
||||
statement.end_balance = self.get_end_balance(node)
|
||||
number = 0
|
||||
for Ntry in self.xpath(node, './ns:Ntry'):
|
||||
for transaction_detail in self.parse_Ntry(Ntry):
|
||||
if number == 0:
|
||||
# Take the statement date from the first transaction
|
||||
statement.date = str2date(
|
||||
transaction_detail['execution_date'], "%Y-%m-%d")
|
||||
number += 1
|
||||
transaction_detail['id'] = str(number).zfill(4)
|
||||
statement.transactions.append(
|
||||
transaction(transaction_detail))
|
||||
transaction_detail = self.parse_Ntry(Ntry)
|
||||
if number == 0:
|
||||
# Take the statement date from the first transaction
|
||||
statement.date = str2date(
|
||||
transaction_detail['execution_date'], "%Y-%m-%d")
|
||||
number += 1
|
||||
transaction_detail['id'] = str(number).zfill(4)
|
||||
statement.transactions.append(
|
||||
transaction(transaction_detail))
|
||||
return statement
|
||||
|
||||
def get_entry_description(self, node):
|
||||
@@ -150,17 +150,12 @@ CAMT Format parser
|
||||
'transfer_type': bt.ORDER,
|
||||
'transferred_amount': self.parse_amount(node)
|
||||
}
|
||||
amount_sign = -1 if node.find(self.ns + 'CdtDbtInd').text == 'CRDT' else 1
|
||||
transaction_details = []
|
||||
for NtryDtl in self.xpath(node, './ns:NtryDtls'):
|
||||
TxDtls = self.xpath(NtryDtl, './ns:TxDtls')
|
||||
# Todo: process Btch tag on entry-detail level
|
||||
if len(TxDtls) == 1:
|
||||
vals = self.parse_TxDtls(TxDtls[0], entry_details, amount_sign)
|
||||
else:
|
||||
vals = entry_details
|
||||
transaction_details.append(vals)
|
||||
return transaction_details
|
||||
TxDtls = self.xpath(node, './ns:NtryDtls/ns:TxDtls')
|
||||
if len(TxDtls) == 1:
|
||||
vals = self.parse_TxDtls(TxDtls[0], entry_details)
|
||||
else:
|
||||
vals = entry_details
|
||||
return vals
|
||||
|
||||
def get_party_values(self, TxDtls):
|
||||
"""
|
||||
@@ -196,12 +191,11 @@ CAMT Format parser
|
||||
domestic_node.text if domestic_node is not None else False)
|
||||
return vals
|
||||
|
||||
def parse_TxDtls(self, TxDtls, entry_values, amount_sign):
|
||||
def parse_TxDtls(self, TxDtls, entry_values):
|
||||
"""
|
||||
Parse a single TxDtls node
|
||||
"""
|
||||
vals = dict(entry_values)
|
||||
# amount = amount_sign * float(node.find(self.ns + 'Amt').text)
|
||||
unstructured = self.xpath(TxDtls, './ns:RmtInf/ns:Ustrd')
|
||||
if unstructured:
|
||||
vals['message'] = ' '.join([x.text for x in unstructured])
|
||||
@@ -209,7 +203,7 @@ CAMT Format parser
|
||||
if structured is not None:
|
||||
vals['reference'] = structured.text
|
||||
else:
|
||||
if vals['message'] and re.match('^[^\s]+$', vals['message']):
|
||||
if vals.get('message') and re.match('^[^\s]+$', vals['message']):
|
||||
vals['reference'] = vals['message']
|
||||
vals.update(self.get_party_values(TxDtls))
|
||||
return vals
|
||||
|
||||
Reference in New Issue
Block a user