fix: use lcyAmount for cross-currency transactions on AZN accounts
Root cause: get_statement_transactions() used fcyAmount (foreign currency amount) but tagged it with account_currency. For AZN-to-USD exchanges on AZN accounts, this picked the USD amount (e.g. 400) but labelled it as AZN, causing wrong BT amounts and cascading JE errors. Fix: parse acCcy from API and use lcyAmount (always AZN per API docs) when acCcy differs from account_currency. Also revert txn_currency fallback in JE creation from kb_currency back to bank_txn.currency so the amount and currency stay consistent throughout the pipeline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b76cdd355e
commit
d8cf942792
|
|
@ -1283,8 +1283,21 @@ def get_statement_transactions(from_date, to_date, account_iban, login_name=None
|
|||
if not parsed_date:
|
||||
continue
|
||||
|
||||
# Amount and currency (use account currency, not the counterparty/operation currency from API)
|
||||
amount = abs(flt(txn.get("fcyAmount") or txn.get("lcyAmount") or 0))
|
||||
# acCcy = transaction currency per the bank; fcyAmount is in acCcy; lcyAmount is always AZN.
|
||||
# We need the amount in account_currency so BT deposit/withdrawal is correct.
|
||||
ac_ccy = (txn.get("acCcy") or "").strip().upper()
|
||||
fcy_amount = abs(flt(txn.get("fcyAmount") or 0))
|
||||
lcy_amount = abs(flt(txn.get("lcyAmount") or 0))
|
||||
|
||||
if not ac_ccy or ac_ccy == account_currency.upper():
|
||||
# Same currency — fcyAmount is in account_currency
|
||||
amount = fcy_amount or lcy_amount
|
||||
elif account_currency.upper() == "AZN":
|
||||
# Cross-currency on AZN account: lcyAmount gives the correct AZN value
|
||||
amount = lcy_amount or fcy_amount
|
||||
else:
|
||||
# Non-AZN account with different acCcy: lcyAmount (AZN) as fallback
|
||||
amount = lcy_amount or fcy_amount
|
||||
currency = account_currency
|
||||
|
||||
# Direction
|
||||
|
|
|
|||
|
|
@ -459,11 +459,13 @@ 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 → bank transaction kb_currency → company currency
|
||||
# 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 = (
|
||||
mapping_currency
|
||||
or txn.get("currency")
|
||||
or (getattr(bank_txn, "kb_currency", None) or "")
|
||||
or (getattr(bank_txn, "currency", None) or "")
|
||||
or company_currency
|
||||
).strip()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue