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 c0c34000ddbf7a3cb449126cdbf1e0efc0ff50fc..9db8d853e8937cc3bc0f8148852357adfa120888 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"