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.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', {

View File

@ -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
}

View File

@ -8,6 +8,12 @@ from frappe.model.document import 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):
self.validate_applicable_accounts()
@ -44,12 +50,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 +82,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)

View File

@ -64,6 +64,7 @@ def create_accounting_dimension_filter():
"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 @@ def create_accounting_dimension_filter():
"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"}],