From f1f79ff1e14308cd31ef752469278f79bc1f7cf1 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Thu, 18 Jul 2019 08:54:15 +0530 Subject: [PATCH] fix: Remove dimensions from boot --- .../accounting_dimension.json | 18 +--------- .../accounting_dimension.py | 34 ++++++++++++++----- .../accounting_dimension_detail.json | 24 +++++++++++-- erpnext/accounts/doctype/gl_entry/gl_entry.py | 16 ++++----- .../accounts_payable/accounts_payable.js | 2 +- .../accounts_payable_summary.js | 2 +- .../accounts_receivable.js | 2 +- .../accounts_receivable_summary.js | 2 +- .../budget_variance_report.js | 2 +- .../report/general_ledger/general_ledger.js | 2 +- .../profitability_analysis.js | 2 +- .../report/sales_register/sales_register.js | 2 +- .../report/trial_balance/trial_balance.js | 2 +- erpnext/public/js/financial_statements.js | 2 +- .../public/js/utils/dimension_tree_filter.js | 18 +++++++--- erpnext/startup/boot.py | 18 ---------- 16 files changed, 79 insertions(+), 69 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json index 19fa9bf837..cf6dc7a8fa 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json @@ -1,6 +1,4 @@ { - "_comments": "[]", - "_liked_by": "[]", "autoname": "field:label", "creation": "2019-05-04 18:13:37.002352", "doctype": "DocType", @@ -10,8 +8,6 @@ "label", "fieldname", "dimension_defaults", - "mandatory_for_bs", - "mandatory_for_pl", "disabled" ], "fields": [ @@ -43,18 +39,6 @@ "label": "Disable", "read_only": 1 }, - { - "default": "0", - "fieldname": "mandatory_for_bs", - "fieldtype": "Check", - "label": "Mandatory For Balance Sheet" - }, - { - "default": "0", - "fieldname": "mandatory_for_pl", - "fieldtype": "Check", - "label": "Mandatory For Profit and Loss Account" - }, { "fieldname": "dimension_defaults", "fieldtype": "Table", @@ -62,7 +46,7 @@ "options": "Accounting Dimension Detail" } ], - "modified": "2019-07-16 18:00:11.365510", + "modified": "2019-07-17 16:49:31.134385", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Dimension", diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 218ab596e3..90cc50d419 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -144,14 +144,6 @@ def toggle_disabling(doc): frappe.clear_cache(doctype=doctype) - dimension_filters = frappe.db.sql(""" - SELECT label, fieldname, document_type - FROM `tabAccounting Dimension` - WHERE disabled = 0 - """, as_dict=1) - - return dimension_filters - def get_doctypes_with_dimensions(): doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", "Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Sales Invoice Item", "Purchase Invoice Item", @@ -163,9 +155,33 @@ def get_doctypes_with_dimensions(): return doclist def get_accounting_dimensions(as_list=True): - accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "mandatory_for_pl", "mandatory_for_bs", "disabled"], filters={"disabled": 0}) + accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled"]) if as_list: return [d.fieldname for d in accounting_dimensions] else: return accounting_dimensions + +def get_checks_for_pl_and_bs_accounts(): + dimensions = frappe.db.sql("""SELECT parent, company, mandatory_for_pl, mandatory_for_bs + FROM `tabAccounting Dimension Detail`""", as_dict=1) + + return dimensions + +@frappe.whitelist() +def get_dimension_filters(): + dimension_filters = frappe.db.sql(""" + SELECT label, fieldname, document_type + FROM `tabAccounting Dimension` + WHERE disabled = 0 + """, as_dict=1) + + default_dimensions = frappe.db.sql("""SELECT parent, company, default_dimension + FROM `tabAccounting Dimension Detail`""", as_dict=1) + + default_dimensions_map = {} + for dimension in default_dimensions: + default_dimensions_map.setdefault(dimension['company'], {}) + default_dimensions_map[dimension['company']][dimension['parent']] = dimension['default_dimension'] + + return dimension_filters, default_dimensions_map diff --git a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json index f46a065271..1ccef6cc7a 100644 --- a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json +++ b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json @@ -6,10 +6,13 @@ "field_order": [ "company", "reference_document", - "default_dimension" + "default_dimension", + "mandatory_for_bs", + "mandatory_for_pl" ], "fields": [ { + "columns": 2, "fieldname": "company", "fieldtype": "Link", "in_list_view": 1, @@ -26,16 +29,33 @@ "read_only": 1 }, { + "columns": 2, "fieldname": "default_dimension", "fieldtype": "Dynamic Link", "in_list_view": 1, "label": "Default Dimension", "options": "reference_document", "reqd": 1 + }, + { + "columns": 3, + "default": "0", + "fieldname": "mandatory_for_bs", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Mandatory For Balance Sheet" + }, + { + "columns": 3, + "default": "0", + "fieldname": "mandatory_for_pl", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Mandatory For Profit and Loss Account" } ], "istable": 1, - "modified": "2019-07-16 18:54:52.202378", + "modified": "2019-07-17 23:34:33.026883", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Dimension Detail", diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 84276eae10..80e518644d 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -12,7 +12,7 @@ from erpnext.accounts.party import validate_party_gle_currency, validate_party_f from erpnext.accounts.utils import get_account_currency from erpnext.accounts.utils import get_fiscal_year from erpnext.exceptions import InvalidAccountCurrency -from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions +from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts exclude_from_linked_with = True class GLEntry(Document): @@ -86,19 +86,19 @@ class GLEntry(Document): account_type = frappe.db.get_value("Account", self.account, "report_type") - for dimension in get_accounting_dimensions(as_list=False): + for dimension in get_checks_for_pl_and_bs_accounts(): if account_type == "Profit and Loss" \ - and dimension.mandatory_for_pl and not dimension.disabled: - if not self.get(dimension.fieldname): + and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled: + if not self.get(frappe.scrub(dimension.parent)): frappe.throw(_("Accounting Dimension {0} is required for 'Profit and Loss' account {1}.") - .format(dimension.label, self.account)) + .format(dimension.parent, self.account)) if account_type == "Balance Sheet" \ - and dimension.mandatory_for_bs and not dimension.disabled: - if not self.get(dimension.fieldname): + and self.company == dimension.company and dimension.mandatory_for_bs and not dimension.disabled: + if not self.get(frappe.scrub(dimension.parent)): frappe.throw(_("Accounting Dimension {0} is required for 'Balance Sheet' account {1}.") - .format(dimension.label, self.account)) + .format(dimension.parent, self.account)) def check_pl_account(self): diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js index 5e07d080fb..8eb670de51 100644 --- a/erpnext/accounts/report/accounts_payable/accounts_payable.js +++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js @@ -115,7 +115,7 @@ frappe.query_reports["Accounts Payable"] = { } } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js index 426de6782d..5f0fdc9f2c 100644 --- a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js +++ b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js @@ -99,7 +99,7 @@ frappe.query_reports["Accounts Payable Summary"] = { } } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js index 816e43898a..4551973ac6 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js @@ -173,7 +173,7 @@ frappe.query_reports["Accounts Receivable"] = { } } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js index d63af8b3f3..0120608a8f 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js +++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js @@ -117,7 +117,7 @@ frappe.query_reports["Accounts Receivable Summary"] = { } } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js index 33dc555a95..24511871fd 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js @@ -63,7 +63,7 @@ frappe.query_reports["Budget Variance Report"] = { ] } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]); }); diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index 74a1ea70ac..4a287060b3 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -159,7 +159,7 @@ frappe.query_reports["General Ledger"] = { ] } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js index 2656a7e7b5..889ede5a82 100644 --- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js +++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js @@ -105,7 +105,7 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { "initial_depth": 3 } - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]); }); diff --git a/erpnext/accounts/report/sales_register/sales_register.js b/erpnext/accounts/report/sales_register/sales_register.js index 105f5a29c1..9dee656d4a 100644 --- a/erpnext/accounts/report/sales_register/sales_register.js +++ b/erpnext/accounts/report/sales_register/sales_register.js @@ -68,7 +68,7 @@ frappe.query_reports["Sales Register"] = { ] } -frappe.boot.dimension_filters.forEach((dimension) => { +erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js index dc6d07e2bb..f15b5b1a19 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.js +++ b/erpnext/accounts/report/trial_balance/trial_balance.js @@ -95,7 +95,7 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { "initial_depth": 3 } - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { frappe.query_reports["Trial Balance"].filters.splice(5, 0 ,{ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index 5feedd3e15..63e057c39d 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -129,7 +129,7 @@ function get_filters(){ } ] - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { filters.push({ "fieldname": dimension["fieldname"], "label": __(dimension["label"]), diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index 22b4834dfb..9d4c435240 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -7,10 +7,18 @@ erpnext.doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoi "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile"]; +frappe.call({ + method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters", + callback: function(r){ + erpnext.dimension_filters = r.message[0]; + erpnext.default_dimensions = r.message[1]; + } +}); + erpnext.doctypes_with_dimensions.forEach((doctype) => { frappe.ui.form.on(doctype, { onload: function(frm) { - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { frappe.model.with_doctype(dimension['document_type'], () => { if (frappe.meta.has_field(dimension['document_type'], 'is_group')) { frm.set_query(dimension['fieldname'], { @@ -23,21 +31,21 @@ erpnext.doctypes_with_dimensions.forEach((doctype) => { company: function(frm) { if(frm.doc.company) { - frappe.boot.dimension_filters.forEach((dimension) => { - frm.set_value(dimension['fieldname'], frappe.boot.default_dimensions[frm.doc.company][dimension['document_type']]); + erpnext.dimension_filters.forEach((dimension) => { + frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); }); } }, items_add: function(frm, cdt, cdn) { - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { var row = frappe.get_doc(cdt, cdn); frm.script_manager.copy_from_first_row("items", row, [dimension['fieldname']]); }); }, accounts_add: function(frm, cdt, cdn) { - frappe.boot.dimension_filters.forEach((dimension) => { + erpnext.dimension_filters.forEach((dimension) => { var row = frappe.get_doc(cdt, cdn); frm.script_manager.copy_from_first_row("accounts", row, [dimension['fieldname']]); }); diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index 7d70cc2349..4ca43a89b8 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -39,8 +39,6 @@ def boot_session(bootinfo): party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""") bootinfo.party_account_types = frappe._dict(party_account_types) - load_dimension_filters(bootinfo) - load_default_dimensions(bootinfo) def load_country_and_currency(bootinfo): country = frappe.db.get_default("country") @@ -51,22 +49,6 @@ def load_country_and_currency(bootinfo): number_format, smallest_currency_fraction_value, symbol from tabCurrency where enabled=1""", as_dict=1, update={"doctype":":Currency"}) -def load_dimension_filters(bootinfo): - bootinfo.dimension_filters = frappe.db.sql(""" - SELECT label, fieldname, document_type - FROM `tabAccounting Dimension` - WHERE disabled = 0 - """, as_dict=1) - -def load_default_dimensions(bootinfo): - default_dimensions = frappe.db.sql("""SELECT parent, company, default_dimension - FROM `tabAccounting Dimension Detail`""", as_dict=1) - - bootinfo.default_dimensions = {} - for dimension in default_dimensions: - bootinfo.default_dimensions.setdefault(dimension['company'], {}) - bootinfo.default_dimensions[dimension['company']][dimension['parent']] = dimension['default_dimension'] - def update_page_info(bootinfo): bootinfo.page_info.update({ "Chart of Accounts": {