Merge pull request #35594 from nikkothari22/make-accounting-dimension-filter-values-optional
feat: added support for mandatory dimensions per account without applying restrictions on dimension values
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 8a6b021..6f0b6fc 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 @@
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 0f3fbc0..2bd6c12 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": "1",
+ "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 14:59:41.869117",
"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 80f736f..de1b82c 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
@@ -8,6 +8,12 @@
class AccountingDimensionFilter(Document):
+ def before_save(self):
+ # If restriction is not applied on values, then remove all the dimensions and set allow_or_restrict to Restrict
+ if not self.apply_restriction_on_values:
+ self.allow_or_restrict = "Restrict"
+ self.set("dimensions", [])
+
def validate(self):
self.validate_applicable_accounts()
@@ -44,12 +50,12 @@
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 +82,5 @@
(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)
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
index f13f2f9..6aba2ab 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
@@ -64,6 +64,7 @@
"accounting_dimension": "Cost Center",
"allow_or_restrict": "Allow",
"company": "_Test Company",
+ "apply_restriction_on_values": 1,
"accounts": [
{
"applicable_on_account": "Sales - _TC",
@@ -85,6 +86,7 @@
"doctype": "Accounting Dimension Filter",
"accounting_dimension": "Department",
"allow_or_restrict": "Allow",
+ "apply_restriction_on_values": 1,
"company": "_Test Company",
"accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}],
"dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}],