Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] camt053 import: handle currencies and ultimate debtor tag #707

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions account_statement_import_camt/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,13 @@ def parse_transaction_details(self, ns, node, transaction):
transaction,
"ref",
)
amount = self.parse_amount(ns, node)
if amount != 0.0:
transaction["amount"] = amount
self.parse_amount_details(ns, node,transaction)
# remote party values
party_type = "Dbtr"
ultimate_debtor = node.xpath("./ns:RltdPties/ns:UltmtDbtr", namespaces={"ns": ns})
if ultimate_debtor:
party_type = "UltmtDbtr"
else:
party_type = "Dbtr"
party_type_node = node.xpath("../../ns:CdtDbtInd", namespaces={"ns": ns})
if party_type_node and party_type_node[0].text != "CRDT":
party_type = "Cdtr"
Expand Down Expand Up @@ -242,6 +244,22 @@ def parse_transaction_details(self, ns, node, transaction):
"account_number",
)

def parse_amount_details(self,ns,node,transaction):
amount = self.parse_amount(ns,node)
if amount != 0.0:
if transaction["amount"] != 0 and transaction["amount"] != amount:
# Probably currencies in this transaction
ntry_dtls_currency = node.xpath("ns:Amt/@Ccy", namespaces={"ns": ns})[0]
ntry_currency = node.xpath("../../ns:Amt/@Ccy", namespaces={"ns": ns})[0]
if ntry_currency and ntry_dtls_currency and ntry_currency != ntry_dtls_currency:
other_currency = self.env["res.currency"].search(
[("name", "=", ntry_dtls_currency)], limit=1
)
transaction["amount_currency"] = amount
transaction["foreign_currency_id"] = other_currency.id
else:
transaction["amount"] = amount

def generate_narration(self, transaction):
# this block ensure compatibility with v13
transaction["narration"] = {
Expand Down
Loading