From f87db8e6dee0c0c85024c05d63c5a7f89550c3bd Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Thu, 26 Mar 2026 21:37:21 +0400 Subject: [PATCH] fix: don't use mapping_currency as txn_currency in JE creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mapping_currency is a filter field (which transactions the rule matches), not the denomination of the BT amount. Using it as txn_currency caused 700 AZN to be treated as 700 USD → 1190 AZN in the Journal Entry. Now txn_currency comes from bank_txn.currency (= GL account currency), which always matches the BT deposit/withdrawal amount. Co-Authored-By: Claude Opus 4.6 (1M context) --- kapital_bank/mapping.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kapital_bank/mapping.py b/kapital_bank/mapping.py index 9e34594..03ee90c 100644 --- a/kapital_bank/mapping.py +++ b/kapital_bank/mapping.py @@ -459,12 +459,11 @@ def _create_journal_entry_for_brt(txn, paid_from, paid_to, bank_txn, multi_curre is_multi = from_currency != company_currency or to_currency != company_currency currency_precision = cint(frappe.db.get_single_value("System Settings", "currency_precision") or 2) - # Use currency from: mapping row → txn dict → bank transaction currency → company currency - # NOTE: use bank_txn.currency (= GL account currency, matches the BT amount), - # NOT kb_currency (= the foreign currency from the bank API, may differ from BT amount). + # txn_currency = the currency the BT amount is denominated in. + # mapping_currency is a FILTER (which transactions this rule matches), NOT the amount's currency. + # bank_txn.currency = GL account currency = currency of deposit/withdrawal = correct. txn_currency = ( - mapping_currency - or txn.get("currency") + txn.get("currency") or (getattr(bank_txn, "currency", None) or "") or company_currency ).strip()