fix: use bt.currency fallback in _find_mapping_for_txn + fix txn_currency in JE creation

- _find_mapping_for_txn: kb_currency could be empty on bank transactions not
  imported through KB; fall back to standard currency field so USD-specific
  mappings are not skipped when matching in Documents & Reconcile mode
- _create_journal_entry_for_brt: JS does not pass currency in txn dict;
  fall back to bank_txn.currency so exchange-rate calculations are correct

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ali 2026-03-16 18:05:47 +04:00
parent 57c8cb0925
commit cbcd06c83b
1 changed files with 7 additions and 2 deletions

View File

@ -276,7 +276,11 @@ def _find_mapping_for_txn(txn, transaction_mappings, purpose_text_cache):
txn_party = (txn.get("party") or "").lower()
bt_name = txn.get("bank_transaction_name")
txn_kb_currency = (frappe.db.get_value("Bank Transaction", bt_name, "kb_currency") or "").strip().upper() if bt_name else ""
if bt_name:
_bt_cur = frappe.db.get_value("Bank Transaction", bt_name, ["kb_currency", "currency"], as_dict=True) or {}
txn_kb_currency = (_bt_cur.get("kb_currency") or _bt_cur.get("currency") or "").strip().upper()
else:
txn_kb_currency = ""
both_rules = []
purpose_only_rules = []
@ -451,7 +455,8 @@ 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)
txn_currency = (txn.get("currency") or company_currency).strip()
# JS does not pass currency; fall back to bank transaction's currency field
txn_currency = (txn.get("currency") or bank_txn.currency or company_currency).strip()
# Exchange rates: account_currency → company_currency
from_rate = 1 if from_currency == company_currency else get_exchange_rate(from_currency, company_currency, posting_date)