From 68a5eae3ffa0976bd80f558417f8a0876f028a8e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 23:34:44 +0530 Subject: [PATCH] fix: warn when accounting dimension fieldname conflicts with existing fields (backport #55036) (#55062) Co-authored-by: Nabin Hait fix: warn when accounting dimension fieldname conflicts with existing fields (#55036) --- .../accounting_dimension.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 549449cce42..6dac47c085b 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -43,6 +43,7 @@ class AccountingDimension(Document): def validate(self): self.validate_doctype() validate_column_name(self.fieldname) + self.validate_fieldname_conflict() self.validate_dimension_defaults() def validate_doctype(self): @@ -74,6 +75,27 @@ class AccountingDimension(Document): message += _("Please create a new Accounting Dimension if required.") frappe.throw(message) + def validate_fieldname_conflict(self): + conflicting_doctypes = [] + for doctype in get_doctypes_with_dimensions(): + meta = frappe.get_meta(doctype, cached=False) + if any(f.fieldname == self.fieldname for f in meta.get("fields")): + conflicting_doctypes.append(doctype) + + if conflicting_doctypes: + frappe.msgprint( + _( + "Fieldname {0} already exists in the following doctypes: {1}. " + "A separate dimension field will not be added to these doctypes. " + "GL Entries will use the value of the existing field as the dimension value." + ).format( + frappe.bold(self.fieldname), + ", ".join(frappe.bold(d) for d in conflicting_doctypes), + ), + title=_("Fieldname Conflict"), + indicator="orange", + ) + def validate_dimension_defaults(self): companies = [] for default in self.get("dimension_defaults"):