fix: Added default dimension and filter in bootinfo
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
index ffb6d5e..bb4d514 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
@@ -8,41 +8,48 @@
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
frappe.set_route("List", frm.doc.document_type);
});
- }
- frm.set_query('document_type', () => {
- return {
- filters: {
- name: ['not in', ['Accounting Dimension', 'Project', 'Cost Center']]
- }
- };
- });
-
- let button = frm.doc.disabled ? "Enable" : "Disable";
-
- frm.add_custom_button(__(button), function() {
-
- frm.set_value('disabled', 1 - frm.doc.disabled);
-
- frappe.call({
- method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension",
- args: {
- doc: frm.doc
- },
- freeze: true,
- callback: function(r) {
- let message = frm.doc.disabled ? "Dimension Disabled" : "Dimension Enabled";
- frm.save();
- frappe.show_alert({message:__(message), indicator:'green'});
- }
+ frm.set_query('document_type', () => {
+ return {
+ filters: {
+ name: ['not in', ['Accounting Dimension', 'Project', 'Cost Center']]
+ }
+ };
});
- });
+
+ let button = frm.doc.disabled ? "Enable" : "Disable";
+
+ frm.add_custom_button(__(button), function() {
+
+ frm.set_value('disabled', 1 - frm.doc.disabled);
+
+ frappe.call({
+ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension",
+ args: {
+ doc: frm.doc
+ },
+ freeze: true,
+ callback: function(r) {
+ let message = frm.doc.disabled ? "Dimension Disabled" : "Dimension Enabled";
+ frm.save();
+ frappe.show_alert({message:__(message), indicator:'green'});
+ }
+ });
+ });
+ }
},
document_type: function(frm) {
+
frm.set_value('label', frm.doc.document_type);
frm.set_value('fieldname', frappe.model.scrub(frm.doc.document_type));
+ if (frm.is_new()){
+ let row = frappe.model.add_child(frm.doc, "Accounting Dimension Detail", "dimension_defaults");
+ row.reference_document = frm.doc.document_type;
+ frm.refresh_fields("dimension_defaults");
+ }
+
frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => {
if (r && r.document_type) {
frm.set_df_property('document_type', 'description', "Document type is already set as dimension");
@@ -50,3 +57,10 @@
});
},
});
+
+frappe.ui.form.on('Accounting Dimension Detail', {
+ dimension_defaults_add: function(frm, cdt, cdn) {
+ let row = locals[cdt][cdn];
+ row.reference_document = frm.doc.document_type;
+ }
+})
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
index 0fab74d..19fa9bf 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.json
@@ -9,7 +9,7 @@
"document_type",
"label",
"fieldname",
- "default_dimension",
+ "dimension_defaults",
"mandatory_for_bs",
"mandatory_for_pl",
"disabled"
@@ -56,13 +56,13 @@
"label": "Mandatory For Profit and Loss Account"
},
{
- "fieldname": "default_dimension",
- "fieldtype": "Dynamic Link",
- "label": "Default Dimension",
- "options": "document_type"
+ "fieldname": "dimension_defaults",
+ "fieldtype": "Table",
+ "label": "Dimension Defaults",
+ "options": "Accounting Dimension Detail"
}
],
- "modified": "2019-07-14 19:16:25.405924",
+ "modified": "2019-07-16 18:00:11.365510",
"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 3148498..218ab59 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
@@ -144,6 +144,14 @@
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",
diff --git a/erpnext/accounts/doctype/accounting_dimension_detail/__init__.py b/erpnext/accounts/doctype/accounting_dimension_detail/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/accounting_dimension_detail/__init__.py
diff --git a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json
new file mode 100644
index 0000000..f46a065
--- /dev/null
+++ b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json
@@ -0,0 +1,47 @@
+{
+ "creation": "2019-07-16 17:53:18.718831",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "company",
+ "reference_document",
+ "default_dimension"
+ ],
+ "fields": [
+ {
+ "fieldname": "company",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "Company",
+ "options": "Company",
+ "reqd": 1
+ },
+ {
+ "fieldname": "reference_document",
+ "fieldtype": "Link",
+ "hidden": 1,
+ "label": "Reference Document",
+ "options": "DocType",
+ "read_only": 1
+ },
+ {
+ "fieldname": "default_dimension",
+ "fieldtype": "Dynamic Link",
+ "in_list_view": 1,
+ "label": "Default Dimension",
+ "options": "reference_document",
+ "reqd": 1
+ }
+ ],
+ "istable": 1,
+ "modified": "2019-07-16 18:54:52.202378",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Accounting Dimension Detail",
+ "owner": "Administrator",
+ "permissions": [],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.py b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.py
new file mode 100644
index 0000000..17cf549
--- /dev/null
+++ b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+# import frappe
+from frappe.model.document import Document
+
+class AccountingDimensionDetail(Document):
+ pass
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index e4acf5a..8728950 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -258,6 +258,7 @@
"print_hide": 1
},
{
+ "collapsible": 1,
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
@@ -269,12 +270,13 @@
],
"idx": 1,
"istable": 1,
- "modified": "2019-05-25 22:14:02.715509",
+ "modified": "2019-07-16 17:12:08.238334",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry Account",
"owner": "Administrator",
"permissions": [],
+ "sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 465df27..779ac4f 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -764,6 +764,7 @@
"label": "Image"
},
{
+ "collapsible": 1,
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
@@ -782,7 +783,7 @@
],
"idx": 1,
"istable": 1,
- "modified": "2019-06-28 17:30:12.156086",
+ "modified": "2019-07-16 16:36:46.527606",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js
index cfcc575..5e07d08 100644
--- a/erpnext/accounts/report/accounts_payable/accounts_payable.js
+++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js
@@ -115,13 +115,12 @@
}
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
+
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 006068a..426de67 100644
--- a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js
+++ b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js
@@ -99,13 +99,12 @@
}
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
+
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
index 2a45454..816e438 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
@@ -173,13 +173,12 @@
}
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
+
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 a7c0787..d63af8b 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
@@ -117,13 +117,11 @@
}
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
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 f2a33a8..33dc555 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
@@ -63,8 +63,7 @@
]
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]);
- });
+frappe.boot.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 ea82575..74a1ea7 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -159,13 +159,12 @@
]
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
+
diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
index d6864b5..2656a7e 100644
--- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
+++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js
@@ -105,9 +105,8 @@
"initial_depth": 3
}
- erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]);
- });
+ frappe.boot.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 442aa12..105f5a2 100644
--- a/erpnext/accounts/report/sales_register/sales_register.js
+++ b/erpnext/accounts/report/sales_register/sales_register.js
@@ -68,13 +68,12 @@
]
}
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+frappe.boot.dimension_filters.forEach((dimension) => {
+ frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
+
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js
index 73d2ab3..dc6d07e 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.js
+++ b/erpnext/accounts/report/trial_balance/trial_balance.js
@@ -94,10 +94,8 @@
"parent_field": "parent_account",
"initial_depth": 3
}
-});
-erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
+ frappe.boot.dimension_filters.forEach((dimension) => {
frappe.query_reports["Trial Balance"].filters.splice(5, 0 ,{
"fieldname": dimension["fieldname"],
"label": __(dimension["label"]),
@@ -107,3 +105,5 @@
});
});
+
+
diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js
index 89cb13d..5feedd3 100644
--- a/erpnext/public/js/financial_statements.js
+++ b/erpnext/public/js/financial_statements.js
@@ -129,14 +129,12 @@
}
]
- erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- filters.push({
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
+ frappe.boot.dimension_filters.forEach((dimension) => {
+ filters.push({
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
});
});
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 1c5e98e..0a363a0 100755
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -63,20 +63,6 @@
me.show_serial_batch_selector(grid_row.frm, grid_row.doc);
});
},
-
- get_dimension_filters: async function() {
- if (!frappe.model.can_read('Accounting Dimension')) {
- return [];
- }
- let dimensions = await frappe.db.get_list('Accounting Dimension', {
- fields: ['label', 'fieldname', 'document_type', 'default_dimension'],
- filters: {
- disabled: 0
- }
- });
-
- return dimensions;
- }
});
diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js
index 4a82edd..22b4834 100644
--- a/erpnext/public/js/utils/dimension_tree_filter.js
+++ b/erpnext/public/js/utils/dimension_tree_filter.js
@@ -7,25 +7,40 @@
"Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
"Travel Request", "Fees", "POS Profile"];
-erpnext.dimension_filters = erpnext.get_dimension_filters();
-
erpnext.doctypes_with_dimensions.forEach((doctype) => {
frappe.ui.form.on(doctype, {
onload: function(frm) {
- erpnext.dimension_filters.then((dimensions) => {
- dimensions.forEach((dimension) => {
- if (dimension['default_dimension']) {
- frm.set_value(dimension['fieldname'], dimension['default_dimension']);
+ frappe.boot.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'], {
+ "is_group": 0
+ });
}
- frappe.model.with_doctype(dimension['document_type'], () => {
- if (frappe.meta.has_field(dimension['document_type'], 'is_group')) {
- frm.set_query(dimension['fieldname'], {
- "is_group": 0
- });
- }
- });
});
});
+ },
+
+ 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']]);
+ });
+ }
+ },
+
+ items_add: function(frm, cdt, cdn) {
+ frappe.boot.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) => {
+ var row = frappe.get_doc(cdt, cdn);
+ frm.script_manager.copy_from_first_row("accounts", row, [dimension['fieldname']]);
+ });
}
});
});
\ No newline at end of file
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index 4ca43a8..7d70cc2 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -39,6 +39,8 @@
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")
@@ -49,6 +51,22 @@
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": {