Skip to content

update to use currencies info from wise camt statement#36

Merged
ecino merged 2 commits into
CompassionCH:14.0-allfrom
davidwul:14.0-all
Apr 27, 2026
Merged

update to use currencies info from wise camt statement#36
ecino merged 2 commits into
CompassionCH:14.0-allfrom
davidwul:14.0-all

Conversation

@davidwul
Copy link
Copy Markdown

update the currencies function to retrieve from camt wise statement (already in prod)

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the CAMT statement parser by introducing a more robust parse_entry method and improving currency detection logic, particularly for foreign currency transactions and exchange rates. Key feedback includes addressing a shallow copy bug where multiple transactions could share the same narration dictionary, preventing potential KeyError exceptions when removing the currency key, and optimizing XPath queries for better performance. Additionally, a minor PEP 8 formatting adjustment for method separation was recommended.

Comment thread account_statement_import_camt/models/parser.py
Comment thread account_statement_import_camt/models/parser.py Outdated
Comment thread account_statement_import_camt/models/parser.py Outdated
Comment on lines +342 to +351
ccy_nodes = node.xpath(".//ns:AmtDtls//@Ccy", namespaces={"ns": ns})
for ccy in ccy_nodes:
if ccy != transaction.get("currency"):
val_node = node.xpath(f".//ns:AmtDtls//*[@Ccy='{ccy}']",
namespaces={"ns": ns})
if val_node:
ntry_dtls_currency = ccy
currency_amount = float(val_node[0].text)
add_currency = True
break
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop is inefficient because it performs a new XPath search (.//ns:AmtDtls//*[@Ccy='{ccy}']) for every currency attribute found. It is better to select the nodes that have the attribute directly and then access the attribute and text from those nodes.

            ccy_nodes = node.xpath(".//ns:AmtDtls//*[@Ccy]", namespaces={"ns": ns})
            for ccy_node in ccy_nodes:
                ccy = ccy_node.get("Ccy")
                if ccy != transaction.get("currency"):
                    ntry_dtls_currency = ccy
                    currency_amount = float(ccy_node.text)
                    add_currency = True
                    break

transaction.pop("currency")
self.generate_narration(transaction)
yield transaction
def add_value_from_node(self, ns, node, xpath_str, obj, attr_name, join_str=None):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to PEP 8, method definitions inside a class should be separated by a single blank line. Please add a blank line before add_value_from_node.

    def add_value_from_node(self, ns, node, xpath_str, obj, attr_name, join_str=None):
References
  1. Method definitions inside a class are separated by a single blank line. (link)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ecino ecino merged commit 11d3a4d into CompassionCH:14.0-all Apr 27, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants