fix: Added default dimension and filter in bootinfo

This commit is contained in:
deepeshgarg007 2019-07-17 15:38:21 +05:30
parent b590f89310
commit 7d270edf79
21 changed files with 219 additions and 129 deletions

View File

@ -8,41 +8,48 @@ frappe.ui.form.on('Accounting Dimension', {
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () { frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
frappe.set_route("List", frm.doc.document_type); frappe.set_route("List", frm.doc.document_type);
}); });
}
frm.set_query('document_type', () => { frm.set_query('document_type', () => {
return { return {
filters: { filters: {
name: ['not in', ['Accounting Dimension', 'Project', 'Cost Center']] 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'});
}
}); });
});
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) { document_type: function(frm) {
frm.set_value('label', frm.doc.document_type); frm.set_value('label', frm.doc.document_type);
frm.set_value('fieldname', frappe.model.scrub(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) => { frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => {
if (r && r.document_type) { if (r && r.document_type) {
frm.set_df_property('document_type', 'description', "Document type is already set as dimension"); frm.set_df_property('document_type', 'description', "Document type is already set as dimension");
@ -50,3 +57,10 @@ frappe.ui.form.on('Accounting Dimension', {
}); });
}, },
}); });
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;
}
})

View File

@ -9,7 +9,7 @@
"document_type", "document_type",
"label", "label",
"fieldname", "fieldname",
"default_dimension", "dimension_defaults",
"mandatory_for_bs", "mandatory_for_bs",
"mandatory_for_pl", "mandatory_for_pl",
"disabled" "disabled"
@ -56,13 +56,13 @@
"label": "Mandatory For Profit and Loss Account" "label": "Mandatory For Profit and Loss Account"
}, },
{ {
"fieldname": "default_dimension", "fieldname": "dimension_defaults",
"fieldtype": "Dynamic Link", "fieldtype": "Table",
"label": "Default Dimension", "label": "Dimension Defaults",
"options": "document_type" "options": "Accounting Dimension Detail"
} }
], ],
"modified": "2019-07-14 19:16:25.405924", "modified": "2019-07-16 18:00:11.365510",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Accounting Dimension", "name": "Accounting Dimension",

View File

@ -144,6 +144,14 @@ def toggle_disabling(doc):
frappe.clear_cache(doctype=doctype) 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(): def get_doctypes_with_dimensions():
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", 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", "Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Sales Invoice Item", "Purchase Invoice Item",

View File

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

View File

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

View File

@ -258,6 +258,7 @@
"print_hide": 1 "print_hide": 1
}, },
{ {
"collapsible": 1,
"fieldname": "accounting_dimensions_section", "fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting Dimensions" "label": "Accounting Dimensions"
@ -269,12 +270,13 @@
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"modified": "2019-05-25 22:14:02.715509", "modified": "2019-07-16 17:12:08.238334",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Entry Account", "name": "Journal Entry Account",
"owner": "Administrator", "owner": "Administrator",
"permissions": [], "permissions": [],
"sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"track_changes": 1 "track_changes": 1
} }

View File

@ -764,6 +764,7 @@
"label": "Image" "label": "Image"
}, },
{ {
"collapsible": 1,
"fieldname": "accounting_dimensions_section", "fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting Dimensions" "label": "Accounting Dimensions"
@ -782,7 +783,7 @@
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"modified": "2019-06-28 17:30:12.156086", "modified": "2019-07-16 16:36:46.527606",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice Item", "name": "Sales Invoice Item",

View File

@ -115,13 +115,12 @@ frappe.query_reports["Accounts Payable"] = {
} }
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{
frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -99,13 +99,12 @@ frappe.query_reports["Accounts Payable Summary"] = {
} }
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{
frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -173,13 +173,12 @@ frappe.query_reports["Accounts Receivable"] = {
} }
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{
frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -117,13 +117,11 @@ frappe.query_reports["Accounts Receivable Summary"] = {
} }
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{
frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -63,8 +63,7 @@ frappe.query_reports["Budget Variance Report"] = {
] ]
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]);
frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]);
});
}); });

View File

@ -159,13 +159,12 @@ frappe.query_reports["General Ledger"] = {
] ]
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{
frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -105,9 +105,8 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"initial_depth": 3 "initial_depth": 3
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]);
frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]);
});
}); });
}); });

View File

@ -68,13 +68,12 @@ frappe.query_reports["Sales Register"] = {
] ]
} }
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{
frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -94,10 +94,8 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"parent_field": "parent_account", "parent_field": "parent_account",
"initial_depth": 3 "initial_depth": 3
} }
});
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => {
frappe.query_reports["Trial Balance"].filters.splice(5, 0 ,{ frappe.query_reports["Trial Balance"].filters.splice(5, 0 ,{
"fieldname": dimension["fieldname"], "fieldname": dimension["fieldname"],
"label": __(dimension["label"]), "label": __(dimension["label"]),
@ -107,3 +105,5 @@ erpnext.dimension_filters.then((dimensions) => {
}); });
}); });

View File

@ -129,14 +129,12 @@ function get_filters(){
} }
] ]
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { filters.push({
filters.push({ "fieldname": dimension["fieldname"],
"fieldname": dimension["fieldname"], "label": __(dimension["label"]),
"label": __(dimension["label"]), "fieldtype": "Link",
"fieldtype": "Link", "options": dimension["document_type"]
"options": dimension["document_type"]
});
}); });
}); });

View File

@ -63,20 +63,6 @@ $.extend(erpnext, {
me.show_serial_batch_selector(grid_row.frm, grid_row.doc); 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;
}
}); });

View File

@ -7,25 +7,40 @@ erpnext.doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoi
"Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
"Travel Request", "Fees", "POS Profile"]; "Travel Request", "Fees", "POS Profile"];
erpnext.dimension_filters = erpnext.get_dimension_filters();
erpnext.doctypes_with_dimensions.forEach((doctype) => { erpnext.doctypes_with_dimensions.forEach((doctype) => {
frappe.ui.form.on(doctype, { frappe.ui.form.on(doctype, {
onload: function(frm) { onload: function(frm) {
erpnext.dimension_filters.then((dimensions) => { frappe.boot.dimension_filters.forEach((dimension) => {
dimensions.forEach((dimension) => { frappe.model.with_doctype(dimension['document_type'], () => {
if (dimension['default_dimension']) { if (frappe.meta.has_field(dimension['document_type'], 'is_group')) {
frm.set_value(dimension['fieldname'], dimension['default_dimension']); 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']]);
});
} }
}); });
}); });

View File

@ -39,6 +39,8 @@ def boot_session(bootinfo):
party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""") party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""")
bootinfo.party_account_types = frappe._dict(party_account_types) bootinfo.party_account_types = frappe._dict(party_account_types)
load_dimension_filters(bootinfo)
load_default_dimensions(bootinfo)
def load_country_and_currency(bootinfo): def load_country_and_currency(bootinfo):
country = frappe.db.get_default("country") country = frappe.db.get_default("country")
@ -49,6 +51,22 @@ def load_country_and_currency(bootinfo):
number_format, smallest_currency_fraction_value, symbol from tabCurrency number_format, smallest_currency_fraction_value, symbol from tabCurrency
where enabled=1""", as_dict=1, update={"doctype":":Currency"}) 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): def update_page_info(bootinfo):
bootinfo.page_info.update({ bootinfo.page_info.update({
"Chart of Accounts": { "Chart of Accounts": {