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
This commit is contained in:
Deepesh Garg 2023-06-25 17:55:26 +05:30 committed by GitHub
commit ebeb5e0cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 39 deletions

View File

@ -68,6 +68,16 @@ frappe.ui.form.on('Accounting Dimension Filter', {
frm.refresh_field("dimensions"); frm.refresh_field("dimensions");
frm.trigger('setup_filters'); 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', { frappe.ui.form.on('Allowed Dimension', {

View File

@ -10,6 +10,7 @@
"disabled", "disabled",
"column_break_2", "column_break_2",
"company", "company",
"apply_restriction_on_values",
"allow_or_restrict", "allow_or_restrict",
"section_break_4", "section_break_4",
"accounts", "accounts",
@ -24,94 +25,80 @@
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1, "in_list_view": 1,
"label": "Accounting Dimension", "label": "Accounting Dimension",
"reqd": 1, "reqd": 1
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_2", "fieldname": "column_break_2",
"fieldtype": "Column Break", "fieldtype": "Column Break"
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_4", "fieldname": "section_break_4",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hide_border": 1, "hide_border": 1
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_6", "fieldname": "column_break_6",
"fieldtype": "Column Break", "fieldtype": "Column Break"
"show_days": 1,
"show_seconds": 1
}, },
{ {
"depends_on": "eval:doc.apply_restriction_on_values == 1;",
"fieldname": "allow_or_restrict", "fieldname": "allow_or_restrict",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Allow Or Restrict Dimension", "label": "Allow Or Restrict Dimension",
"options": "Allow\nRestrict", "options": "Allow\nRestrict",
"reqd": 1, "reqd": 1
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "accounts", "fieldname": "accounts",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Applicable On Account", "label": "Applicable On Account",
"options": "Applicable On Account", "options": "Applicable On Account",
"reqd": 1, "reqd": 1
"show_days": 1,
"show_seconds": 1
}, },
{ {
"depends_on": "eval:doc.accounting_dimension", "depends_on": "eval:doc.accounting_dimension && doc.apply_restriction_on_values",
"fieldname": "dimensions", "fieldname": "dimensions",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Applicable Dimension", "label": "Applicable Dimension",
"options": "Allowed Dimension", "mandatory_depends_on": "eval:doc.apply_restriction_on_values == 1;",
"reqd": 1, "options": "Allowed Dimension"
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
"fieldname": "disabled", "fieldname": "disabled",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Disabled", "label": "Disabled"
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Company", "label": "Company",
"options": "Company", "options": "Company",
"reqd": 1, "reqd": 1
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "dimension_filter_help", "fieldname": "dimension_filter_help",
"fieldtype": "HTML", "fieldtype": "HTML",
"label": "Dimension Filter Help", "label": "Dimension Filter Help"
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_10", "fieldname": "section_break_10",
"fieldtype": "Section Break", "fieldtype": "Section Break"
"show_days": 1, },
"show_seconds": 1 {
"default": "1",
"fieldname": "apply_restriction_on_values",
"fieldtype": "Check",
"label": "Apply restriction on dimension values"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-02-03 12:04:58.678402", "modified": "2023-06-07 14:59:41.869117",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Accounting Dimension Filter", "name": "Accounting Dimension Filter",
"naming_rule": "Expression",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
@ -154,5 +141,6 @@
"quick_entry": 1, "quick_entry": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"states": [],
"track_changes": 1 "track_changes": 1
} }

View File

@ -8,6 +8,12 @@ from frappe.model.document import Document
class AccountingDimensionFilter(Document): 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): def validate(self):
self.validate_applicable_accounts() self.validate_applicable_accounts()
@ -44,12 +50,12 @@ def get_dimension_filter_map():
a.applicable_on_account, d.dimension_value, p.accounting_dimension, a.applicable_on_account, d.dimension_value, p.accounting_dimension,
p.allow_or_restrict, a.is_mandatory p.allow_or_restrict, a.is_mandatory
FROM FROM
`tabApplicable On Account` a, `tabAllowed Dimension` d, `tabApplicable On Account` a,
`tabAccounting Dimension Filter` p `tabAccounting Dimension Filter` p
LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name
WHERE WHERE
p.name = a.parent p.name = a.parent
AND p.disabled = 0 AND p.disabled = 0
AND p.name = d.parent
""", """,
as_dict=1, as_dict=1,
) )
@ -76,4 +82,5 @@ def build_map(map_object, dimension, account, filter_value, allow_or_restrict, i
(dimension, account), (dimension, account),
{"allowed_dimensions": [], "is_mandatory": is_mandatory, "allow_or_restrict": allow_or_restrict}, {"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)

View File

@ -64,6 +64,7 @@ def create_accounting_dimension_filter():
"accounting_dimension": "Cost Center", "accounting_dimension": "Cost Center",
"allow_or_restrict": "Allow", "allow_or_restrict": "Allow",
"company": "_Test Company", "company": "_Test Company",
"apply_restriction_on_values": 1,
"accounts": [ "accounts": [
{ {
"applicable_on_account": "Sales - _TC", "applicable_on_account": "Sales - _TC",
@ -85,6 +86,7 @@ def create_accounting_dimension_filter():
"doctype": "Accounting Dimension Filter", "doctype": "Accounting Dimension Filter",
"accounting_dimension": "Department", "accounting_dimension": "Department",
"allow_or_restrict": "Allow", "allow_or_restrict": "Allow",
"apply_restriction_on_values": 1,
"company": "_Test Company", "company": "_Test Company",
"accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}], "accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}],
"dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}], "dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}],