Merge pull request #58414 from frappe/mergify/bp/version-16-hotfix/pr-58412

fix(accounts): prevent child table doctypes as accounting dimensions (backport #58412)
This commit is contained in:
Khushi Rawat
2026-08-26 11:35:41 +05:30
committed by GitHub
4 changed files with 32 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ frappe.ui.form.on("Accounting Dimension", {
return { return {
filters: { filters: {
name: ["not in", invalid_doctypes], name: ["not in", invalid_doctypes],
istable: 0,
issingle: 0,
}, },
}; };
}); });

View File

@@ -60,6 +60,14 @@ class AccountingDimension(Document):
msg = _("Not allowed to create accounting dimension for {0}").format(self.document_type) msg = _("Not allowed to create accounting dimension for {0}").format(self.document_type)
frappe.throw(msg) frappe.throw(msg)
meta = frappe.get_meta(self.document_type)
if meta.istable or meta.issingle:
frappe.throw(
_(
"{0} cannot be used as an accounting dimension as it is not a standalone document type."
).format(frappe.bold(self.document_type))
)
exists = frappe.db.get_value("Accounting Dimension", {"document_type": self.document_type}, ["name"]) exists = frappe.db.get_value("Accounting Dimension", {"document_type": self.document_type}, ["name"])
if exists and self.is_new(): if exists and self.is_new():

View File

@@ -52,6 +52,23 @@ class TestAccountingDimension(ERPNextTestSuite):
self.assertEqual(gle.get("department"), "_Test Department - _TC") self.assertEqual(gle.get("department"), "_Test Department - _TC")
self.assertEqual(gle1.get("department"), "_Test Department - _TC") self.assertEqual(gle1.get("department"), "_Test Department - _TC")
def test_child_table_not_allowed_as_dimension(self):
dimension = frappe.get_doc({"doctype": "Accounting Dimension", "document_type": "Sales Team"})
self.assertRaises(frappe.ValidationError, dimension.insert)
def test_single_doctype_not_allowed_as_dimension(self):
dimension = frappe.get_doc({"doctype": "Accounting Dimension", "document_type": "Selling Settings"})
self.assertRaises(frappe.ValidationError, dimension.insert)
def test_non_scalar_dimension_value_skipped_in_gl_dict(self):
si = create_sales_invoice(do_not_save=1)
si.department = "_Test Department - _TC"
self.assertEqual(si.get_gl_dict({}).get("department"), "_Test Department - _TC")
si.department = ["_Test Department - _TC"]
self.assertNotIn("department", si.get_gl_dict({}))
def test_mandatory(self): def test_mandatory(self):
location = frappe.get_doc("Accounting Dimension", "Location") location = frappe.get_doc("Accounting Dimension", "Location")
location.dimension_defaults[0].mandatory_for_bs = True location.dimension_defaults[0].mandatory_for_bs = True

View File

@@ -1421,9 +1421,12 @@ class AccountsController(TransactionBase):
dimension_dict = frappe._dict() dimension_dict = frappe._dict()
for dimension in accounting_dimensions: for dimension in accounting_dimensions:
dimension_dict[dimension] = self.get(dimension) value = self.get(dimension)
if item and item.get(dimension): if item and item.get(dimension):
dimension_dict[dimension] = item.get(dimension) value = item.get(dimension)
if isinstance(value, list | dict):
continue
dimension_dict[dimension] = value
gl_dict.update(dimension_dict) gl_dict.update(dimension_dict)
gl_dict.update(args) gl_dict.update(args)