Browse Source

account_bank_statement_import_camt: parse unique_import_id; properly select statement date; remove unexpected values like execution_date, value_date, etc. - standard Odoo does not expect those

pull/112/head
Andrius Preimantas 8 years ago
committed by Louis Bettens
parent
commit
3a1c69ea7d
  1. 32
      account_bank_statement_import_camt/camt.py

32
account_bank_statement_import_camt/camt.py

@ -64,6 +64,13 @@ class CamtParser(object):
], ],
transaction, 'ref' transaction, 'ref'
) )
# unique_import_id
self.add_value_from_node(
ns, node, [
'./ns:Refs/ns:AcctSvcrRef',
],
transaction, 'unique_import_id'
)
# remote party values # remote party values
party_type = 'Dbtr' party_type = 'Dbtr'
party_type_node = node.xpath( party_type_node = node.xpath(
@ -75,14 +82,6 @@ class CamtParser(object):
if party_node: if party_node:
self.add_value_from_node( self.add_value_from_node(
ns, party_node[0], './ns:Nm', transaction, 'partner_name') ns, party_node[0], './ns:Nm', transaction, 'partner_name')
self.add_value_from_node(
ns, party_node[0], './ns:PstlAdr/ns:Ctry', transaction,
'partner_country'
)
address_node = party_node[0].xpath(
'./ns:PstlAdr/ns:AdrLine', namespaces={'ns': ns})
if address_node:
transaction['partner_address'] = [address_node[0].text]
# Get remote_account from iban or from domestic account: # Get remote_account from iban or from domestic account:
account_node = node.xpath( account_node = node.xpath(
'./ns:RltdPties/ns:%sAcct/ns:Id' % party_type, './ns:RltdPties/ns:%sAcct/ns:Id' % party_type,
@ -93,12 +92,6 @@ class CamtParser(object):
'./ns:IBAN', namespaces={'ns': ns}) './ns:IBAN', namespaces={'ns': ns})
if iban_node: if iban_node:
transaction['account_number'] = iban_node[0].text transaction['account_number'] = iban_node[0].text
bic_node = node.xpath(
'./ns:RltdAgts/ns:%sAgt/ns:FinInstnId/ns:BIC' % party_type,
namespaces={'ns': ns}
)
if bic_node:
transaction['account_bic'] = bic_node[0].text
else: else:
self.add_value_from_node( self.add_value_from_node(
ns, account_node[0], './ns:Othr/ns:Id', transaction, ns, account_node[0], './ns:Othr/ns:Id', transaction,
@ -108,16 +101,8 @@ class CamtParser(object):
def parse_transaction(self, ns, node): def parse_transaction(self, ns, node):
"""Parse transaction (entry) node.""" """Parse transaction (entry) node."""
transaction = {} transaction = {}
self.add_value_from_node(
ns, node, './ns:BkTxCd/ns:Prtry/ns:Cd', transaction,
'transfer_type'
)
self.add_value_from_node( self.add_value_from_node(
ns, node, './ns:BookgDt/ns:Dt', transaction, 'date') ns, node, './ns:BookgDt/ns:Dt', transaction, 'date')
self.add_value_from_node(
ns, node, './ns:BookgDt/ns:Dt', transaction, 'execution_date')
self.add_value_from_node(
ns, node, './ns:ValDt/ns:Dt', transaction, 'value_date')
transaction['amount'] = self.parse_amount(ns, node) transaction['amount'] = self.parse_amount(ns, node)
@ -137,7 +122,6 @@ class CamtParser(object):
], ],
transaction, 'ref' transaction, 'ref'
) )
transaction['data'] = etree.tostring(node)
return transaction return transaction
def get_balance_amounts(self, ns, node): def get_balance_amounts(self, ns, node):
@ -185,7 +169,7 @@ class CamtParser(object):
self.add_value_from_node( self.add_value_from_node(
ns, node, './ns:Id', result, 'name') ns, node, './ns:Id', result, 'name')
self.add_value_from_node( self.add_value_from_node(
ns, node, './ns:Dt', result, 'date')
ns, node, './ns:CreDtTm', result, 'date')
self.add_value_from_node( self.add_value_from_node(
ns, node, './ns:Acct/ns:Ccy', result, 'currency') ns, node, './ns:Acct/ns:Ccy', result, 'currency')
result['balance_start'], result['balance_end_real'] = ( result['balance_start'], result['balance_end_real'] = (

Loading…
Cancel
Save