fix: GL Entry validation for dimensions
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index def9ed6..1ac6079 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -13,6 +13,8 @@
from erpnext.accounts.utils import get_fiscal_year
from erpnext.exceptions import InvalidAccountCurrency
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts
+from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import get_dimension_filter_map
+from six import iteritems
exclude_from_linked_with = True
class GLEntry(Document):
@@ -37,6 +39,7 @@
def on_update_with_args(self, adv_adj, update_outstanding = 'Yes'):
self.validate_account_details(adv_adj)
self.validate_dimensions_for_pl_and_bs()
+ self.validate_allowed_dimensions()
validate_frozen_account(self.account, adv_adj)
validate_balance_type(self.account, adv_adj)
@@ -91,6 +94,21 @@
frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Balance Sheet' account {1}.")
.format(dimension.label, self.account))
+ def validate_allowed_dimensions(self):
+ dimension_filter_map = get_dimension_filter_map()
+ for key, value in iteritems(dimension_filter_map):
+ dimension = key[0]
+ account = key[1]
+
+ if self.account == account:
+ if value['allow_or_restrict'] == 'Allow':
+ if self.get(dimension) and self.get(dimension) not in value['allowed_dimensions']:
+ frappe.throw(_("Invalid value {0} for account {1}").format(
+ frappe.bold(self.get(dimension)), frappe.bold(self.account)))
+ else:
+ if self.get(dimension) and self.get(dimension) in value['allowed_dimensions']:
+ frappe.throw(_("Invalid value {0} for account {1}").format(
+ frappe.bold(self.get(dimension)), frappe.bold(self.account)))
def check_pl_account(self):
if self.is_opening=='Yes' and \