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

14 amt dtl camt54 #25

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
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
33 changes: 19 additions & 14 deletions account_statement_import_camt/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def parse_amount(self, ns, node):
amount = sign * float(amount_node[0].text)
return amount


def add_value_from_node(self, ns, node, xpath_str, obj, attr_name, join_str=None):
"""Add value to object from first or all nodes found with xpath.

Expand Down Expand Up @@ -188,20 +189,8 @@ def parse_transaction_details(self, ns, node, transaction):
transaction,
"ref",
)
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
self.parse_amount_details(ns, node,transaction)

# remote party values
ultmtdbtr = node.xpath("./ns:RltdPties/ns:UltmtDbtr", namespaces={"ns": ns})
if ultmtdbtr:
Expand Down Expand Up @@ -266,6 +255,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
10 changes: 10 additions & 0 deletions account_statement_import_camt54/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ def parse_transaction_details(self, ns, node, transaction):
)
return True

def parse_amount_details(self,ns,node,transaction):
re_camt_version = re.compile(
r"(^urn:iso:std:iso:20022:tech:xsd:camt.054."
r"|^ISO:camt.054.)"
)
if re_camt_version.search(ns):
#camt54 use amounts only from txdtls
transaction['amount'] = self.parse_amount(ns,node)
super().parse_amount_details(ns,node,transaction)

def parse_statement(self, ns, node):
"""In case of a camt54 file, the QR-IBAN to be used as the account_number
is found in another place than the IBAN."""
Expand Down
Loading