From 83c46085fbb56e1cfb2981a7d57b8ed313b4979a Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Wed, 7 Jun 2023 14:14:57 +0530 Subject: [PATCH] feat: added support for mandatory dimensions per account --- .../accounting_dimension_filter.js | 10 ++++ .../accounting_dimension_filter.json | 60 ++++++++----------- .../accounting_dimension_filter.py | 7 ++- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js index 8a6b021b8a..6f0b6fcd91 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js @@ -68,6 +68,16 @@ frappe.ui.form.on('Accounting Dimension Filter', { frm.refresh_field("dimensions"); frm.trigger('setup_filters'); }, + apply_restriction_on_values: function(frm) { + /** If restriction on values is not applied, we should set "allow_or_restrict" to "Restrict" with an empty allowed dimension table. + * Hence it's not "restricted" on any value. + */ + if (!frm.doc.apply_restriction_on_values) { + frm.set_value("allow_or_restrict", "Restrict"); + frm.clear_table("dimensions"); + frm.refresh_field("dimensions"); + } + } }); frappe.ui.form.on('Allowed Dimension', { diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json index 0f3fbc0b8d..1f320b0a1a 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json @@ -10,6 +10,7 @@ "disabled", "column_break_2", "company", + "apply_restriction_on_values", "allow_or_restrict", "section_break_4", "accounts", @@ -24,94 +25,80 @@ "fieldtype": "Select", "in_list_view": 1, "label": "Accounting Dimension", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "column_break_2", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { "fieldname": "section_break_4", "fieldtype": "Section Break", - "hide_border": 1, - "show_days": 1, - "show_seconds": 1 + "hide_border": 1 }, { "fieldname": "column_break_6", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Column Break" }, { + "depends_on": "eval:doc.apply_restriction_on_values == 1;", "fieldname": "allow_or_restrict", "fieldtype": "Select", "label": "Allow Or Restrict Dimension", "options": "Allow\nRestrict", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "accounts", "fieldtype": "Table", "label": "Applicable On Account", "options": "Applicable On Account", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { - "depends_on": "eval:doc.accounting_dimension", + "depends_on": "eval:doc.accounting_dimension && doc.apply_restriction_on_values", "fieldname": "dimensions", "fieldtype": "Table", "label": "Applicable Dimension", - "options": "Allowed Dimension", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "mandatory_depends_on": "eval:doc.apply_restriction_on_values == 1;", + "options": "Allowed Dimension" }, { "default": "0", "fieldname": "disabled", "fieldtype": "Check", - "label": "Disabled", - "show_days": 1, - "show_seconds": 1 + "label": "Disabled" }, { "fieldname": "company", "fieldtype": "Link", "label": "Company", "options": "Company", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "dimension_filter_help", "fieldtype": "HTML", - "label": "Dimension Filter Help", - "show_days": 1, - "show_seconds": 1 + "label": "Dimension Filter Help" }, { "fieldname": "section_break_10", - "fieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "apply_restriction_on_values", + "fieldtype": "Check", + "label": "Apply restriction on dimension values" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-02-03 12:04:58.678402", + "modified": "2023-06-07 13:41:36.736175", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Dimension Filter", + "naming_rule": "Expression", "owner": "Administrator", "permissions": [ { @@ -154,5 +141,6 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py index 80f736fa5b..c0573a703c 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py @@ -44,12 +44,12 @@ def get_dimension_filter_map(): a.applicable_on_account, d.dimension_value, p.accounting_dimension, p.allow_or_restrict, a.is_mandatory FROM - `tabApplicable On Account` a, `tabAllowed Dimension` d, + `tabApplicable On Account` a, `tabAccounting Dimension Filter` p + LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name WHERE p.name = a.parent AND p.disabled = 0 - AND p.name = d.parent """, as_dict=1, ) @@ -76,4 +76,5 @@ def build_map(map_object, dimension, account, filter_value, allow_or_restrict, i (dimension, account), {"allowed_dimensions": [], "is_mandatory": is_mandatory, "allow_or_restrict": allow_or_restrict}, ) - map_object[(dimension, account)]["allowed_dimensions"].append(filter_value) + if filter_value: + map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)