Skip to content
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
14 changes: 0 additions & 14 deletions account_statement_import/wizard/account_statement_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,6 @@ def _create_bank_statements(self, stmts_vals, result):
st_lines_to_create.append(lvals)

if len(st_lines_to_create) > 0:

for line in st_lines_to_create:
if line.get("charges_incl"):
if line.get("charges_incl") == "true":
charges = float(line.get("charges"))
line["amount"] += charges
charge_incl_line = line.copy()
charge_incl_line["amount"] = -charges
st_lines_to_create.append(charge_incl_line)
charge_incl_line.pop("charges_incl")
charge_incl_line.pop("charges")
line.pop("charges_incl")
line.pop("charges")

if not st_lines_to_create[0].get("sequence"):
for seq, vals in enumerate(st_lines_to_create, start=1):
vals["sequence"] = seq
Expand Down
27 changes: 9 additions & 18 deletions account_statement_import_camt/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ def parse_transaction_details(self, ns, node, transaction):
"ref",
)
# check if there are currency details
self.parse_amount_details(ns, node, transaction)

if not self.parse_amount_details_currency(ns, node, transaction):
amount = self.parse_amount(ns, node)
if amount != 0.0:
transaction["amount"] = amount
# remote party values
ultmtdbtr = node.xpath("./ns:RltdPties/ns:UltmtDbtr", namespaces={"ns": ns})
if ultmtdbtr:
Expand Down Expand Up @@ -255,7 +257,7 @@ def parse_transaction_details(self, ns, node, transaction):
"account_number",
)

def parse_amount_details(self, ns, node, transaction):
def parse_amount_details_currency(self, ns, node, transaction):
# search for currency information in the txdtls
add_currency = False
ntry_dtls_currency = node.xpath("ns:Amt/@Ccy", namespaces={"ns": ns})
Expand All @@ -277,6 +279,7 @@ def parse_amount_details(self, ns, node, transaction):
)
transaction["amount_currency"] = currency_amount
transaction["foreign_currency_id"] = other_currency.id
return add_currency

def generate_narration(self, transaction):
# this block ensure compatibility with v13
Expand Down Expand Up @@ -316,21 +319,6 @@ def parse_entry(self, ns, node):
transaction,
"currency",
)
# Enrich entry with charges if available
self.add_value_from_node(
ns,
node,
"./ns:Chrgs/ns:TtlChrgsAndTaxAmt",
transaction,
"charges",
)
self.add_value_from_node(
ns,
node,
"./ns:Chrgs/ns:Rcrd/ns:ChrgInclInd",
transaction,
"charges_incl",
)
amount = self.parse_amount(ns, node)

if amount != 0.0:
Expand Down Expand Up @@ -401,6 +389,9 @@ def parse_entry(self, ns, node):
)

details_nodes = node.xpath("./ns:NtryDtls/ns:TxDtls", namespaces={"ns": ns})
chrg_inc = node.xpath("./ns:Chrgs/ns:Rcrd/ns:ChrgInclInd", namespaces={"ns": ns})
if chrg_inc and chrg_inc[0].text == "true":
details_nodes += node.xpath("./ns:Chrgs/ns:Rcrd", namespaces={"ns": ns})
if len(details_nodes) == 0:
transaction.pop("currency")
self.generate_narration(transaction)
Expand Down
4 changes: 2 additions & 2 deletions account_statement_import_camt54/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def parse_transaction_details(self, ns, node, transaction):
)
return True

def parse_amount_details(self, ns, node, transaction):
def parse_amount_details_currency(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)
return super().parse_amount_details_currency(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
Expand Down
Loading