From 31cd9dcee18635e584f3cb06ec76dc8efd3ed420 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 8 Feb 2021 17:37:14 +0530 Subject: [PATCH] fix: Avoid changing Ref. Doctype in Accounting Dimension after creation --- .../accounting_dimension/accounting_dimension.js | 2 ++ .../accounting_dimension/accounting_dimension.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js index 3c12f85f938..dbe4299e5e4 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js @@ -41,6 +41,8 @@ frappe.ui.form.on('Accounting Dimension', { }); }); } + + frm.toggle_enable('document_type', doc.__islocal); }, document_type: function(frm) { diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 894ec5bdec5..e0d18f297a9 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -29,6 +29,16 @@ class AccountingDimension(Document): if exists and self.is_new(): frappe.throw("Document Type already used as a dimension") + if not self.is_new(): + self.validate_document_type_change() + + def validate_document_type_change(self): + doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type") + if doctype_before_save != self.document_type: + message = _("Cannot change Reference Document Type.") + message += _("Please create a new Accounting Dimension if required.") + frappe.throw(message) + def after_insert(self): if frappe.flags.in_test: make_dimension_in_accounting_doctypes(doc=self)