From 1d884408fc979b24191ac881ba51238d5c46c40a Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Mon, 22 Apr 2024 14:45:49 +0200 Subject: [PATCH] fix: Auto determine party based on dedicated accounts --- .../fec_import_document.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/erpnext/regional/doctype/fec_import_document/fec_import_document.py b/erpnext/regional/doctype/fec_import_document/fec_import_document.py index c0c34000dd..9db8d853e8 100644 --- a/erpnext/regional/doctype/fec_import_document/fec_import_document.py +++ b/erpnext/regional/doctype/fec_import_document/fec_import_document.py @@ -126,7 +126,7 @@ class FECImportDocument(Document): row.account = accounts.get(row.comptenum) def get_party(self, row): - if not row.compauxnum or (row.party_type and row.party): + if row.party_type and row.party: return journal_type = frappe.get_cached_value("Accounting Journal", row.accounting_journal, "type") @@ -135,12 +135,32 @@ class FECImportDocument(Document): compte_aux = None compte_aux_type = None if journal_type in ("Sales", "Bank") or account_type == "Receivable": - if compte_aux := frappe.db.exists("Customer", row.compauxnum): + if compte_aux := ( + frappe.db.exists("Customer", row.compauxnum) + or frappe.db.get_value( + "Party Account", + dict(company=self.company, account=row.account, parenttype="Customer"), + "parent", + ) + ): compte_aux_type = "Customer" - elif journal_type in ("Purchase", "Bank") or account_type == "Payable": - if compte_aux := frappe.db.exists("Supplier", row.compauxnum): + + if (journal_type == "Purchase" or account_type == "Payable") or ( + not compte_aux and journal_type == "Bank" + ): + if compte_aux := ( + frappe.db.exists("Supplier", row.compauxnum) + or frappe.db.get_value( + "Party Account", + dict(company=self.company, account=row.account, parenttype="Supplier"), + "parent", + ) + ): compte_aux_type = "Supplier" + if not row.compauxnum and not (compte_aux and compte_aux_type): + return + if account_type in ["Receivable", "Payable"] and not (compte_aux and compte_aux_type): if account_type == "Receivable": compte_aux_type = "Customer" -- GitLab