fixed bug

This commit is contained in:
Ali 2026-03-13 22:06:27 +04:00
parent 3e90e872a1
commit d17982c81a
1 changed files with 20 additions and 10 deletions

View File

@ -37,12 +37,12 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
if do_mappings:
existing_purpose = {
(row.purpose_keyword, row.payment_type)
(row.purpose_keyword, row.payment_type, (row.currency or "").upper())
for row in settings.transaction_mappings
if row.purpose_keyword and row.payment_type
}
existing_party_only = {
(row.counterparty_type or "", row.counterparty or "", row.payment_type)
(row.counterparty_type or "", row.counterparty or "", row.payment_type, (row.currency or "").upper())
for row in settings.transaction_mappings
if not row.purpose_keyword and row.counterparty and row.payment_type
}
@ -57,12 +57,15 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
party = (txn.get("party") or "").strip()
payment_type = "Pay" if txn.get("drcr") == "D" else "Receive"
bt_name = txn.get("bank_transaction_name")
kb_currency = (frappe.db.get_value("Bank Transaction", bt_name, "kb_currency") or "").strip().upper() if bt_name else ""
if not purpose and not party:
skipped_no_data += 1
continue
if purpose:
key = (purpose, payment_type)
key = (purpose, payment_type, kb_currency)
if key not in unique_purposes:
unique_purposes[key] = {
"count": 0,
@ -73,7 +76,7 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
unique_purposes[key]["count"] += 1
else:
# Party-only mapping (no purpose)
key = (party_type, party, payment_type)
key = (party_type, party, payment_type, kb_currency)
if key not in unique_parties:
unique_parties[key] = {
"count": 0,
@ -83,10 +86,11 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
}
unique_parties[key]["count"] += 1
for (purpose_text, payment_type), data in unique_purposes.items():
for (purpose_text, payment_type, kb_currency), data in unique_purposes.items():
purpose_name = _ensure_purpose(purpose_text)
is_foreign = kb_currency and kb_currency != "AZN"
if (purpose_name, payment_type) in existing_purpose:
if (purpose_name, payment_type, kb_currency) in existing_purpose:
already_mapped += 1
continue
@ -98,12 +102,16 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
"document_type": document_type,
"counterparty_type": data["counterparty_type"] or None,
"counterparty": data["counterparty"] or None,
"currency": kb_currency or None,
"multi_currency": 1 if is_foreign else 0,
})
existing_purpose.add((purpose_name, payment_type))
existing_purpose.add((purpose_name, payment_type, kb_currency))
created_mappings += 1
for (party_type_k, party_k, payment_type), data in unique_parties.items():
if (party_type_k, party_k, payment_type) in existing_party_only:
for (party_type_k, party_k, payment_type, kb_currency), data in unique_parties.items():
is_foreign = kb_currency and kb_currency != "AZN"
if (party_type_k, party_k, payment_type, kb_currency) in existing_party_only:
already_mapped += 1
continue
@ -115,8 +123,10 @@ def create_purpose_mappings(transactions, paid_from=None, paid_to=None, document
"document_type": document_type,
"counterparty_type": data["counterparty_type"] or None,
"counterparty": data["counterparty"] or None,
"currency": kb_currency or None,
"multi_currency": 1 if is_foreign else 0,
})
existing_party_only.add((party_type_k, party_k, payment_type))
existing_party_only.add((party_type_k, party_k, payment_type, kb_currency))
created_mappings += 1
if created_mappings > 0: