bug fix
This commit is contained in:
parent
5f440c1b66
commit
c674fed28b
|
|
@ -1450,6 +1450,9 @@ def _build_import_lookups(settings):
|
|||
getattr(row, "cost_center", None) or "",
|
||||
))
|
||||
|
||||
# Each key maps to a dict with optional "Customer" and "Supplier" entries.
|
||||
# This preserves both when the same name/VOEN exists in both registries,
|
||||
# allowing payment_type-aware selection at import time.
|
||||
voen_to_party = {}
|
||||
name_to_party = {}
|
||||
|
||||
|
|
@ -1458,22 +1461,22 @@ def _build_import_lookups(settings):
|
|||
continue
|
||||
entry = {"party_type": "Customer", "erp_party": row.erp_customer}
|
||||
if row.tax_id:
|
||||
voen_to_party[row.tax_id.strip()] = entry
|
||||
voen_to_party.setdefault(row.tax_id.strip(), {})["Customer"] = entry
|
||||
if row.kb_customer_name:
|
||||
kb_customer_name = frappe.db.get_value("Kapital Bank Customer", row.kb_customer_name, "customer_name")
|
||||
if kb_customer_name:
|
||||
name_to_party[kb_customer_name.strip()] = entry
|
||||
name_to_party.setdefault(kb_customer_name.strip(), {})["Customer"] = entry
|
||||
|
||||
for row in settings.supplier_mappings:
|
||||
if not row.erp_supplier:
|
||||
continue
|
||||
entry = {"party_type": "Supplier", "erp_party": row.erp_supplier}
|
||||
if row.tax_id:
|
||||
voen_to_party[row.tax_id.strip()] = entry
|
||||
voen_to_party.setdefault(row.tax_id.strip(), {})["Supplier"] = entry
|
||||
if row.kb_supplier_name:
|
||||
kb_supplier_name = frappe.db.get_value("Kapital Bank Supplier", row.kb_supplier_name, "supplier_name")
|
||||
if kb_supplier_name:
|
||||
name_to_party[kb_supplier_name.strip()] = entry
|
||||
name_to_party.setdefault(kb_supplier_name.strip(), {})["Supplier"] = entry
|
||||
|
||||
return purpose_rules, voen_to_party, name_to_party
|
||||
|
||||
|
|
@ -1568,14 +1571,19 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
|||
}
|
||||
|
||||
# Party mapping: VOEN → name → None
|
||||
# When a key maps to both Customer and Supplier, prefer the one matching payment_type.
|
||||
def _resolve_party(candidates):
|
||||
preferred = "Customer" if payment_type == "Receive" else "Supplier"
|
||||
fallback = "Supplier" if preferred == "Customer" else "Customer"
|
||||
entry = candidates.get(preferred) or candidates.get(fallback)
|
||||
return (entry["party_type"], entry["erp_party"]) if entry else (None, None)
|
||||
|
||||
party_type = None
|
||||
erp_party = None
|
||||
if contr_voen and contr_voen in voen_to_party:
|
||||
party_type = voen_to_party[contr_voen]["party_type"]
|
||||
erp_party = voen_to_party[contr_voen]["erp_party"]
|
||||
party_type, erp_party = _resolve_party(voen_to_party[contr_voen])
|
||||
elif contr_name and contr_name in name_to_party:
|
||||
party_type = name_to_party[contr_name]["party_type"]
|
||||
erp_party = name_to_party[contr_name]["erp_party"]
|
||||
party_type, erp_party = _resolve_party(name_to_party[contr_name])
|
||||
|
||||
if not party_type or not erp_party:
|
||||
if source_type == "card" and not contr_name and not contr_voen:
|
||||
|
|
@ -2086,14 +2094,19 @@ def _import_one_bank_transaction(txn_data, settings, voen_to_party, name_to_part
|
|||
}
|
||||
|
||||
# Optional party mapping: VÖEN → name → None
|
||||
# C (credit, money in) → prefer Customer; D (debit, money out) → prefer Supplier
|
||||
def _resolve_party(candidates):
|
||||
preferred = "Customer" if dr_cr == "C" else "Supplier"
|
||||
fallback = "Supplier" if preferred == "Customer" else "Customer"
|
||||
entry = candidates.get(preferred) or candidates.get(fallback)
|
||||
return (entry["party_type"], entry["erp_party"]) if entry else (None, None)
|
||||
|
||||
party_type = None
|
||||
erp_party = None
|
||||
if contr_voen and contr_voen in voen_to_party:
|
||||
party_type = voen_to_party[contr_voen]["party_type"]
|
||||
erp_party = voen_to_party[contr_voen]["erp_party"]
|
||||
party_type, erp_party = _resolve_party(voen_to_party[contr_voen])
|
||||
elif contr_name and contr_name in name_to_party:
|
||||
party_type = name_to_party[contr_name]["party_type"]
|
||||
erp_party = name_to_party[contr_name]["erp_party"]
|
||||
party_type, erp_party = _resolve_party(name_to_party[contr_name])
|
||||
|
||||
# Create Bank Transaction
|
||||
bt = frappe.new_doc("Bank Transaction")
|
||||
|
|
|
|||
Loading…
Reference in New Issue