From 94ce72e4fbcd73ff926ff98634a28d064871e955 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Tue, 12 May 2026 10:45:21 +0000 Subject: [PATCH] fix(bank-integration): 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 ...". The upfront validation now also checks is_group and returns a clear message before any record is touched. Co-Authored-By: Claude Opus 4.7 (1M context) --- jey_erp/bank_integration/creation.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jey_erp/bank_integration/creation.py b/jey_erp/bank_integration/creation.py index 3083e42..eef270a 100644 --- a/jey_erp/bank_integration/creation.py +++ b/jey_erp/bank_integration/creation.py @@ -19,8 +19,8 @@ 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. + # 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, _bi_cust in unmapped: group = mapping.customer_group or bi.default_customer_group if not group or not frappe.db.exists("Customer Group", group): @@ -28,12 +28,20 @@ def create_unmapped_customers(bank_integration): "Set a Default Customer Group on the Bank Integration " "(or a Customer Group on each customer mapping row) before creating customers." )) + if frappe.db.get_value("Customer Group", group, "is_group"): + frappe.throw(_( + "Customer Group '{0}' is a group node — pick a leaf (non-group) Customer Group." + ).format(group)) 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." )) + if frappe.db.get_value("Territory", territory, "is_group"): + frappe.throw(_( + "Territory '{0}' is a group node — pick a leaf (non-group) Territory." + ).format(territory)) created = 0 for mapping, bi_cust in unmapped: @@ -102,6 +110,10 @@ def create_unmapped_suppliers(bank_integration): "Set a Default Supplier Group on the Bank Integration " "(or a Supplier Group on each supplier mapping row) before creating suppliers." )) + if frappe.db.get_value("Supplier Group", group, "is_group"): + frappe.throw(_( + "Supplier Group '{0}' is a group node — pick a leaf (non-group) Supplier Group." + ).format(group)) created = 0 for mapping, bi_supp in unmapped: