fix(bank-integration): clear validation message when default groups aren't set
Creating customers/suppliers/bank accounts from unmapped rows fell back
to "All Customer Groups" / "All Territories" / "All Supplier Groups",
which don't exist on localized sites — ERPNext then threw a cryptic
"Could not find Customer Group: All Customer Groups". Now creation
validates upfront and returns a clear message ("Set a Default Customer
Group on the Bank Integration ...") before touching any records. Same
for Territory, Supplier Group, and (for Bank Accounts) Company / Bank.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1d6bdc8424
commit
2dba6908b0
|
|
@ -19,6 +19,22 @@ def create_unmapped_customers(bank_integration):
|
|||
if not unmapped:
|
||||
return {"success": True, "created_count": 0, "message": "No unmapped customers in table"}
|
||||
|
||||
# Validate config upfront — a clear message beats ERPNext's cryptic
|
||||
# "Could not find Customer Group" thrown deep inside party creation.
|
||||
for mapping, _bi_cust in unmapped:
|
||||
group = mapping.customer_group or bi.default_customer_group
|
||||
if not group or not frappe.db.exists("Customer Group", group):
|
||||
frappe.throw(_(
|
||||
"Set a Default Customer Group on the Bank Integration "
|
||||
"(or a Customer Group on each customer mapping row) before creating customers."
|
||||
))
|
||||
territory = mapping.territory or bi.default_territory
|
||||
if not territory or not frappe.db.exists("Territory", territory):
|
||||
frappe.throw(_(
|
||||
"Set a Default Territory on the Bank Integration "
|
||||
"(or a Territory on each customer mapping row) before creating customers."
|
||||
))
|
||||
|
||||
created = 0
|
||||
for mapping, bi_cust in unmapped:
|
||||
try:
|
||||
|
|
@ -29,16 +45,8 @@ def create_unmapped_customers(bank_integration):
|
|||
party = frappe.new_doc("Customer")
|
||||
party.customer_name = customer_name
|
||||
party.customer_type = "Company"
|
||||
|
||||
customer_group = mapping.customer_group or bi.default_customer_group or "All Customer Groups"
|
||||
if not frappe.db.exists("Customer Group", customer_group):
|
||||
customer_group = "All Customer Groups"
|
||||
party.customer_group = customer_group
|
||||
|
||||
territory = mapping.territory or bi.default_territory or "All Territories"
|
||||
if not frappe.db.exists("Territory", territory):
|
||||
territory = "All Territories"
|
||||
party.territory = territory
|
||||
party.customer_group = mapping.customer_group or bi.default_customer_group
|
||||
party.territory = mapping.territory or bi.default_territory
|
||||
|
||||
if bi_cust.tax_id:
|
||||
party.tax_id = bi_cust.tax_id
|
||||
|
|
@ -87,6 +95,14 @@ def create_unmapped_suppliers(bank_integration):
|
|||
if not unmapped:
|
||||
return {"success": True, "created_count": 0, "message": "No unmapped suppliers in table"}
|
||||
|
||||
for mapping, _bi_supp in unmapped:
|
||||
group = mapping.supplier_group or bi.default_supplier_group
|
||||
if not group or not frappe.db.exists("Supplier Group", group):
|
||||
frappe.throw(_(
|
||||
"Set a Default Supplier Group on the Bank Integration "
|
||||
"(or a Supplier Group on each supplier mapping row) before creating suppliers."
|
||||
))
|
||||
|
||||
created = 0
|
||||
for mapping, bi_supp in unmapped:
|
||||
try:
|
||||
|
|
@ -97,11 +113,7 @@ def create_unmapped_suppliers(bank_integration):
|
|||
party = frappe.new_doc("Supplier")
|
||||
party.supplier_name = supplier_name
|
||||
party.supplier_type = "Company"
|
||||
|
||||
supplier_group = mapping.supplier_group or bi.default_supplier_group or "All Supplier Groups"
|
||||
if not frappe.db.exists("Supplier Group", supplier_group):
|
||||
supplier_group = "All Supplier Groups"
|
||||
party.supplier_group = supplier_group
|
||||
party.supplier_group = mapping.supplier_group or bi.default_supplier_group
|
||||
|
||||
if bi_supp.tax_id:
|
||||
party.tax_id = bi_supp.tax_id
|
||||
|
|
@ -147,6 +159,13 @@ def create_unmapped_accounts(bank_integration):
|
|||
default_bank = bi.default_bank
|
||||
default_company = bi.default_company
|
||||
|
||||
# Only need these for accounts that don't already exist as Bank Accounts.
|
||||
if any(not frappe.db.exists("Bank Account", {"bank_account_no": r.iban}) for r in unmapped):
|
||||
if not default_company:
|
||||
frappe.throw(_("Set a Default Company on the Bank Integration before creating Bank Accounts."))
|
||||
if not default_bank:
|
||||
frappe.throw(_("Set a Default Bank on the Bank Integration before creating Bank Accounts."))
|
||||
|
||||
created = 0
|
||||
for row in unmapped:
|
||||
try:
|
||||
|
|
@ -169,9 +188,7 @@ def create_unmapped_accounts(bank_integration):
|
|||
ba.account_name = account_name
|
||||
ba.bank_account_no = row.iban
|
||||
ba.iban = row.iban
|
||||
if default_bank:
|
||||
ba.bank = default_bank
|
||||
if default_company:
|
||||
ba.company = default_company
|
||||
ba.bank_integration_type = "Bank Integration"
|
||||
ba.bank_integration = bi.name
|
||||
|
|
|
|||
Loading…
Reference in New Issue