fix: use mapping currency for JE creation in Documents & Reconcile mode
Pass mapping_row.currency through the call chain so _create_journal_entry_for_brt uses the mapping's currency (not the bank transaction document) as txn_currency. This ensures correct exchange-rate calculation and proper multi-currency handling. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cbcd06c83b
commit
87d4578927
|
|
@ -175,13 +175,15 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
|
|||
txn_paid_to = mapping_row.paid_to
|
||||
txn_doc_type = mapping_row.document_type or "Payment Entry"
|
||||
txn_multi_currency = bool(mapping_row.multi_currency)
|
||||
txn_mapping_currency = (mapping_row.currency or "").strip()
|
||||
else:
|
||||
txn_paid_from = paid_from
|
||||
txn_paid_to = paid_to
|
||||
txn_doc_type = document_type
|
||||
txn_multi_currency = False
|
||||
txn_mapping_currency = ""
|
||||
|
||||
result = _create_and_reconcile_doc(txn, txn_paid_from, txn_paid_to, txn_doc_type, txn_multi_currency)
|
||||
result = _create_and_reconcile_doc(txn, txn_paid_from, txn_paid_to, txn_doc_type, txn_multi_currency, txn_mapping_currency)
|
||||
if result.get("success"):
|
||||
created_docs += 1
|
||||
if result.get("reconciled"):
|
||||
|
|
@ -336,14 +338,14 @@ def _find_mapping_for_txn(txn, transaction_mappings, purpose_text_cache):
|
|||
return None
|
||||
|
||||
|
||||
def _create_and_reconcile_doc(txn, paid_from, paid_to, document_type, multi_currency=False):
|
||||
def _create_and_reconcile_doc(txn, paid_from, paid_to, document_type, multi_currency=False, mapping_currency=""):
|
||||
"""Create a Payment Entry or Journal Entry and reconcile it with the bank transaction."""
|
||||
bank_transaction_name = txn.get("bank_transaction_name")
|
||||
try:
|
||||
bank_txn = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||
|
||||
if document_type == "Journal Entry":
|
||||
result = _create_journal_entry_for_brt(txn, paid_from, paid_to, bank_txn, multi_currency)
|
||||
result = _create_journal_entry_for_brt(txn, paid_from, paid_to, bank_txn, multi_currency, mapping_currency)
|
||||
else:
|
||||
result = _create_payment_entry_for_brt(txn, paid_from, paid_to, bank_txn)
|
||||
|
||||
|
|
@ -428,7 +430,7 @@ def _create_payment_entry_for_brt(txn, paid_from, paid_to, bank_txn):
|
|||
return {"success": False, "error": str(e)}
|
||||
|
||||
|
||||
def _create_journal_entry_for_brt(txn, paid_from, paid_to, bank_txn, multi_currency=False):
|
||||
def _create_journal_entry_for_brt(txn, paid_from, paid_to, bank_txn, multi_currency=False, mapping_currency=""):
|
||||
"""Create and submit a Journal Entry for a BRT transaction."""
|
||||
try:
|
||||
import erpnext
|
||||
|
|
@ -455,8 +457,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)
|
||||
# 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()
|
||||
# Use currency from the selected mapping; fall back to company currency
|
||||
txn_currency = (mapping_currency or txn.get("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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue