fix: don't use mapping_currency as txn_currency in JE creation

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) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-03-26 21:37:21 +04:00
parent d8cf942792
commit f87db8e6de
1 changed files with 4 additions and 5 deletions

View File

@ -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()