fix: reject group-node Customer/Supplier Group / Territory upfront

Customer/Supplier require a leaf node for customer_group/supplier_group/
territory; selecting a group node makes ERPNext throw "Cannot select a
Group type ...". Creation now checks is_group during the upfront
validation and returns a clear message before touching any record.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-05-12 10:45:29 +00:00
parent aae3dfacfb
commit 8d66f2101d
1 changed files with 8 additions and 2 deletions

View File

@ -658,15 +658,19 @@ def create_unmapped_customers(settings_name=None):
if not unmapped:
return {"success": True, "created_count": 0, "message": "No unmapped customers in table to create"}
# Validate config upfront — clearer than ERPNext's cryptic
# "Could not find Customer Group" thrown deep inside party creation.
# Validate config upfront — clearer than ERPNext's errors thrown deep inside
# party creation ("Could not find Customer Group" / "Cannot select a Group type").
for mapping, _kb_customer in unmapped:
group = mapping.customer_group or doc.default_customer_group
if not group or not frappe.db.exists("Customer Group", group):
return {"success": False, "message": "Set a Default Customer Group on Kapital Bank Settings (or a Customer Group on each customer mapping row) before creating customers."}
if frappe.db.get_value("Customer Group", group, "is_group"):
return {"success": False, "message": f"Customer Group '{group}' is a group node — pick a leaf (non-group) Customer Group."}
territory = mapping.territory or doc.default_territory
if not territory or not frappe.db.exists("Territory", territory):
return {"success": False, "message": "Set a Default Territory on Kapital Bank Settings (or a Territory on each customer mapping row) before creating customers."}
if frappe.db.get_value("Territory", territory, "is_group"):
return {"success": False, "message": f"Territory '{territory}' is a group node — pick a leaf (non-group) Territory."}
created = 0
for mapping, kb_customer in unmapped:
@ -739,6 +743,8 @@ def create_unmapped_suppliers(settings_name=None):
group = mapping.supplier_group or doc.default_supplier_group
if not group or not frappe.db.exists("Supplier Group", group):
return {"success": False, "message": "Set a Default Supplier Group on Kapital Bank Settings (or a Supplier Group on each supplier mapping row) before creating suppliers."}
if frappe.db.get_value("Supplier Group", group, "is_group"):
return {"success": False, "message": f"Supplier Group '{group}' is a group node — pick a leaf (non-group) Supplier Group."}
created = 0
for mapping, kb_supplier in unmapped: