fix: Move filter setup to doctype controllers

This commit is contained in:
Deepesh Garg 2020-11-25 14:49:10 +05:30
parent 92b3449789
commit 6b9dda5f3e
24 changed files with 218 additions and 101 deletions

View File

@ -1,5 +1,6 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Budget', { frappe.ui.form.on('Budget', {
onload: function(frm) { onload: function(frm) {
@ -11,7 +12,7 @@ frappe.ui.form.on('Budget', {
is_group: 0 is_group: 0
} }
} }
}) });
frm.set_query("monthly_distribution", function() { frm.set_query("monthly_distribution", function() {
return { return {
@ -19,7 +20,9 @@ frappe.ui.form.on('Budget', {
fiscal_year: frm.doc.fiscal_year fiscal_year: frm.doc.fiscal_year
} }
} }
}) });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {

View File

@ -120,6 +120,8 @@ frappe.ui.form.on("Journal Entry", {
} }
} }
}); });
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
voucher_type: function(frm){ voucher_type: function(frm){
@ -197,6 +199,7 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
this.load_defaults(); this.load_defaults();
this.setup_queries(); this.setup_queries();
this.setup_balance_formatter(); this.setup_balance_formatter();
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}, },
onload_post_render: function() { onload_post_render: function() {
@ -397,6 +400,8 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
} }
} }
cur_frm.cscript.update_totals(doc); cur_frm.cscript.update_totals(doc);
erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'accounts');
}, },
}); });

View File

@ -1,6 +1,8 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Loyalty Program', { frappe.ui.form.on('Loyalty Program', {
setup: function(frm) { setup: function(frm) {
var help_content = var help_content =
@ -47,11 +49,16 @@ frappe.ui.form.on('Loyalty Program', {
}); });
frm.set_value("company", frappe.defaults.get_user_default("Company")); frm.set_value("company", frappe.defaults.get_user_default("Company"));
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {
if (frm.doc.loyalty_program_type === "Single Tier Program" && frm.doc.collection_rules.length > 1) { if (frm.doc.loyalty_program_type === "Single Tier Program" && frm.doc.collection_rules.length > 1) {
frappe.throw(__("Please select the Multiple Tier Program type for more than one collection rules.")); frappe.throw(__("Please select the Multiple Tier Program type for more than one collection rules."));
} }
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
} }
}); });

View File

@ -36,6 +36,8 @@ frappe.ui.form.on('Opening Invoice Creation Tool', {
frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message); frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message);
frm.page.set_indicator(__('In Progress'), 'orange'); frm.page.set_indicator(__('In Progress'), 'orange');
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {
@ -100,6 +102,7 @@ frappe.ui.form.on('Opening Invoice Creation Tool', {
} }
}) })
} }
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
invoice_type: function(frm) { invoice_type: function(frm) {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
{% include "erpnext/public/js/controllers/accounts.js" %} {% include "erpnext/public/js/controllers/accounts.js" %}
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Payment Entry', { frappe.ui.form.on('Payment Entry', {
onload: function(frm) { onload: function(frm) {
@ -8,6 +9,8 @@ frappe.ui.form.on('Payment Entry', {
if (!frm.doc.paid_from) frm.set_value("paid_from_account_currency", null); if (!frm.doc.paid_from) frm.set_value("paid_from_account_currency", null);
if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null); if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null);
} }
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
setup: function(frm) { setup: function(frm) {
@ -158,6 +161,7 @@ frappe.ui.form.on('Payment Entry', {
company: function(frm) { company: function(frm) {
frm.events.hide_unhide_fields(frm); frm.events.hide_unhide_fields(frm);
frm.events.set_dynamic_labels(frm); frm.events.set_dynamic_labels(frm);
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
contact_person: function(frm) { contact_person: function(frm) {

View File

@ -48,6 +48,8 @@ frappe.ui.form.on('POS Profile', {
} }
}; };
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {
@ -58,6 +60,7 @@ frappe.ui.form.on('POS Profile', {
company: function(frm) { company: function(frm) {
frm.trigger("toggle_display_account_head"); frm.trigger("toggle_display_account_head");
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
toggle_display_account_head: function(frm) { toggle_display_account_head: function(frm) {

View File

@ -16,6 +16,11 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}); });
} }
}, },
company: function() {
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
},
onload: function() { onload: function() {
this._super(); this._super();
@ -31,6 +36,8 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
if (this.frm.doc.supplier && this.frm.doc.__islocal) { if (this.frm.doc.supplier && this.frm.doc.__islocal) {
this.frm.trigger('supplier'); this.frm.trigger('supplier');
} }
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}, },
refresh: function(doc) { refresh: function(doc) {

View File

@ -5,14 +5,17 @@
cur_frm.pformat.print_heading = 'Invoice'; cur_frm.pformat.print_heading = 'Invoice';
{% include 'erpnext/selling/sales_common.js' %}; {% include 'erpnext/selling/sales_common.js' %};
frappe.provide("erpnext.accounts"); frappe.provide("erpnext.accounts");
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
setup: function(doc) { setup: function(doc) {
this.setup_posting_date_time_check(); this.setup_posting_date_time_check();
this._super(doc); this._super(doc);
}, },
company: function() {
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
},
onload: function() { onload: function() {
var me = this; var me = this;
this._super(); this._super();
@ -33,6 +36,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
me.frm.refresh_fields(); me.frm.refresh_fields();
} }
erpnext.queries.setup_warehouse_query(this.frm); erpnext.queries.setup_warehouse_query(this.frm);
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
}, },
refresh: function(doc, dt, dn) { refresh: function(doc, dt, dn) {

View File

@ -1,7 +1,17 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide('erpnext.accounts.dimensions');
frappe.ui.form.on('Shipping Rule', { frappe.ui.form.on('Shipping Rule', {
onload: function(frm) {
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
refresh: function(frm) { refresh: function(frm) {
frm.set_query("account", function() { frm.set_query("account", function() {
return { return {

View File

@ -2,6 +2,7 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.asset"); frappe.provide("erpnext.asset");
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Asset', { frappe.ui.form.on('Asset', {
onload: function(frm) { onload: function(frm) {
@ -31,6 +32,12 @@ frappe.ui.form.on('Asset', {
} }
}; };
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
setup: function(frm) { setup: function(frm) {

View File

@ -1,6 +1,8 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Asset Value Adjustment', { frappe.ui.form.on('Asset Value Adjustment', {
setup: function(frm) { setup: function(frm) {
frm.add_fetch('company', 'cost_center', 'cost_center'); frm.add_fetch('company', 'cost_center', 'cost_center');
@ -13,11 +15,19 @@ frappe.ui.form.on('Asset Value Adjustment', {
} }
}); });
}, },
onload: function(frm) { onload: function(frm) {
if(frm.is_new() && frm.doc.asset) { if(frm.is_new() && frm.doc.asset) {
frm.trigger("set_current_asset_value"); frm.trigger("set_current_asset_value");
} }
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
asset: function(frm) { asset: function(frm) {
frm.trigger("set_current_asset_value"); frm.trigger("set_current_asset_value");
}, },

View File

@ -2,7 +2,7 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.buying"); frappe.provide("erpnext.buying");
frappe.provide("erpnext.accounts.dimensions");
{% include 'erpnext/public/js/controllers/buying.js' %}; {% include 'erpnext/public/js/controllers/buying.js' %};
frappe.ui.form.on("Purchase Order", { frappe.ui.form.on("Purchase Order", {
@ -30,6 +30,10 @@ frappe.ui.form.on("Purchase Order", {
}, },
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
onload: function(frm) { onload: function(frm) {
set_schedule_date(frm); set_schedule_date(frm);
if (!frm.doc.transaction_date){ if (!frm.doc.transaction_date){
@ -39,6 +43,8 @@ frappe.ui.form.on("Purchase Order", {
erpnext.queries.setup_queries(frm, "Warehouse", function() { erpnext.queries.setup_queries(frm, "Warehouse", function() {
return erpnext.queries.warehouse(frm.doc); return erpnext.queries.warehouse(frm.doc);
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
} }
}); });

View File

@ -1,6 +1,7 @@
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Fee Schedule', { frappe.ui.form.on('Fee Schedule', {
setup: function(frm) { setup: function(frm) {
frm.add_fetch('fee_structure', 'receivable_account', 'receivable_account'); frm.add_fetch('fee_structure', 'receivable_account', 'receivable_account');
@ -8,6 +9,10 @@ frappe.ui.form.on('Fee Schedule', {
frm.add_fetch('fee_structure', 'cost_center', 'cost_center'); frm.add_fetch('fee_structure', 'cost_center', 'cost_center');
}, },
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
onload: function(frm) { onload: function(frm) {
frm.set_query('receivable_account', function(doc) { frm.set_query('receivable_account', function(doc) {
return { return {
@ -50,6 +55,8 @@ frappe.ui.form.on('Fee Schedule', {
} }
} }
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {

View File

@ -1,6 +1,8 @@
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Fee Structure', { frappe.ui.form.on('Fee Structure', {
setup: function(frm) { setup: function(frm) {
frm.add_fetch('company', 'default_receivable_account', 'receivable_account'); frm.add_fetch('company', 'default_receivable_account', 'receivable_account');
@ -8,6 +10,10 @@ frappe.ui.form.on('Fee Structure', {
frm.add_fetch('company', 'cost_center', 'cost_center'); frm.add_fetch('company', 'cost_center', 'cost_center');
}, },
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
onload: function(frm) { onload: function(frm) {
frm.set_query('academic_term', function() { frm.set_query('academic_term', function() {
return { return {
@ -35,6 +41,8 @@ frappe.ui.form.on('Fee Structure', {
} }
}; };
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on("Fees", { frappe.ui.form.on("Fees", {
setup: function(frm) { setup: function(frm) {
@ -9,6 +10,10 @@ frappe.ui.form.on("Fees", {
frm.add_fetch("fee_structure", "cost_center", "cost_center"); frm.add_fetch("fee_structure", "cost_center", "cost_center");
}, },
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
onload: function(frm){ onload: function(frm){
frm.set_query("academic_term",function(){ frm.set_query("academic_term",function(){
return{ return{
@ -45,6 +50,8 @@ frappe.ui.form.on("Fees", {
if (!frm.doc.posting_date) { if (!frm.doc.posting_date) {
frm.doc.posting_date = frappe.datetime.get_today(); frm.doc.posting_date = frappe.datetime.get_today();
} }
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {

View File

@ -2,11 +2,21 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.hr"); frappe.provide("erpnext.hr");
frappe.provide("erpnext.accounts.dimensions");
erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({ frappe.ui.form.on('Expense Claim', {
expense_type: function(doc, cdt, cdn) { onload: function(frm) {
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
});
frappe.ui.form.on('Expense Claim Detail', {
expense_type: function(frm, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(!doc.company) { if(!frm.doc.company) {
d.expense_type = ""; d.expense_type = "";
frappe.msgprint(__("Please set the Company")); frappe.msgprint(__("Please set the Company"));
this.frm.refresh_fields(); this.frm.refresh_fields();
@ -20,7 +30,7 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center", method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center",
args: { args: {
"expense_claim_type": d.expense_type, "expense_claim_type": d.expense_type,
"company": doc.company "company": frm.doc.company
}, },
callback: function(r) { callback: function(r) {
if (r.message) { if (r.message) {
@ -32,8 +42,6 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
} }
}); });
$.extend(cur_frm.cscript, new erpnext.hr.ExpenseClaimController({frm: cur_frm}));
cur_frm.add_fetch('employee', 'company', 'company'); cur_frm.add_fetch('employee', 'company', 'company');
cur_frm.add_fetch('employee','employee_name','employee_name'); cur_frm.add_fetch('employee','employee_name','employee_name');
cur_frm.add_fetch('expense_type','description','description'); cur_frm.add_fetch('expense_type','description','description');

View File

@ -3,6 +3,8 @@
var in_progress = false; var in_progress = false;
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Payroll Entry', { frappe.ui.form.on('Payroll Entry', {
onload: function (frm) { onload: function (frm) {
if (!frm.doc.posting_date) { if (!frm.doc.posting_date) {
@ -17,6 +19,8 @@ frappe.ui.form.on('Payroll Entry', {
} }
}; };
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {
@ -122,6 +126,7 @@ frappe.ui.form.on('Payroll Entry', {
company: function (frm) { company: function (frm) {
frm.events.clear_employee_table(frm); frm.events.clear_employee_table(frm);
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
department: function (frm) { department: function (frm) {

View File

@ -1,6 +1,8 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide('erpnext.accounts.dimensions');
erpnext.TransactionController = erpnext.taxes_and_totals.extend({ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
setup: function() { setup: function() {
this._super(); this._super();
@ -106,6 +108,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
if(!item.warehouse && frm.doc.set_warehouse) { if(!item.warehouse && frm.doc.set_warehouse) {
item.warehouse = frm.doc.set_warehouse; item.warehouse = frm.doc.set_warehouse;
} }
erpnext.accounts.dimensions.copy_dimension_from_first_row(frm, cdt, cdn, 'items');
} }
}); });

View File

@ -1,60 +1,79 @@
frappe.provide('frappe.ui.form'); frappe.provide('erpnext.accounts');
let default_dimensions = {};
let doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", erpnext.accounts.dimensions = {
"Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Shipping Rule", "Loyalty Program", setup_dimension_filters(frm, doctype) {
"Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", this.accounting_dimensions = [];
"Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Asset", "Asset Value Adjustment"]; this.default_dimensions = {};
this.fetch_custom_dimensions(frm, doctype);
},
let child_docs = ["Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", fetch_custom_dimensions(frm, doctype) {
"Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", let me = this;
"Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan", frappe.call({
"Sales Taxes and Charges", "Purchase Taxes and Charges"]; method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
frappe.call({
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters",
args: { args: {
'with_costcenter_and_project': true 'with_cost_center_and_project': true
}, },
callback: function(r) { callback: function(r) {
erpnext.dimension_filters = r.message[0]; me.accounting_dimensions = r.message[0];
default_dimensions = r.message[1]; me.default_dimensions = r.message[1];
me.setup_filters(frm, doctype);
} }
}); });
},
doctypes_with_dimensions.forEach((doctype) => { setup_filters(frm, doctype) {
frappe.ui.form.on(doctype, { this.accounting_dimensions.forEach((dimension) => {
onload: function(frm) {
erpnext.dimension_filters.forEach((dimension) => {
frappe.model.with_doctype(dimension['document_type'], () => { frappe.model.with_doctype(dimension['document_type'], () => {
let parent_fields = []; let parent_fields = [];
frappe.meta.get_docfields(doctype).forEach((df) => { frappe.meta.get_docfields(doctype).forEach((df) => {
if (df.fieldtype === 'Link' && df.options === 'Account') { if (df.fieldtype === 'Link' && df.options === 'Account') {
parent_fields.push(df.fieldname); parent_fields.push(df.fieldname);
} else if (df.fieldtype === 'Table') { } else if (df.fieldtype === 'Table') {
setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']); this.setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']);
} }
setup_account_filters(frm, dimension['fieldname'], parent_fields); if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
this.setup_account_filters(frm, dimension['fieldname'], parent_fields);
}
}); });
}); });
}); });
}, },
company: function(frm) { setup_child_filters(frm, doctype, parentfield, dimension) {
if(frm.doc.company && (Object.keys(default_dimensions || {}).length > 0) let fields = [];
&& default_dimensions[frm.doc.company]) {
frm.trigger('update_dimension'); if (frappe.meta.has_field(doctype, dimension)) {
frappe.model.with_doctype(doctype, () => {
frappe.meta.get_docfields(doctype).forEach((df) => {
if (df.fieldtype === 'Link' && df.options === 'Account') {
fields.push(df.fieldname);
}
});
frm.set_query(dimension, parentfield, function(doc, cdt, cdn) {
let row = locals[cdt][cdn];
return erpnext.queries.get_filtered_dimensions(row, fields, dimension, doc.company);
});
});
} }
}, },
update_dimension: function(frm) { setup_account_filters(frm, dimension, fields) {
erpnext.dimension_filters.forEach((dimension) => { frm.set_query(dimension, function(doc) {
return erpnext.queries.get_filtered_dimensions(doc, fields, dimension, doc.company);
});
},
update_dimension(frm, doctype) {
if (this.accounting_dimensions) {
this.accounting_dimensions.forEach((dimension) => {
if(frm.is_new()) { if(frm.is_new()) {
if(frm.doc.company && Object.keys(default_dimensions || {}).length > 0 if(frm.doc.company && Object.keys(this.default_dimensions || {}).length > 0
&& default_dimensions[frm.doc.company]) { && this.default_dimensions[frm.doc.company]) {
let default_dimension = default_dimensions[frm.doc.company][dimension['fieldname']]; let default_dimension = this.default_dimensions[frm.doc.company][dimension['fieldname']];
if(default_dimension) { if(default_dimension) {
if (frappe.meta.has_field(doctype, dimension['fieldname'])) { if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
@ -69,47 +88,14 @@ doctypes_with_dimensions.forEach((doctype) => {
} }
}); });
} }
});
});
child_docs.forEach((doctype) => {
frappe.ui.form.on(doctype, {
items_add: function(frm, cdt, cdn) {
copy_dimension(frm, cdt, cdn, "items");
}, },
accounts_add: function(frm, cdt, cdn) { copy_dimension_from_first_row(frm, cdt, cdn, fieldname) {
copy_dimension(frm, cdt, cdn, "accounts"); if (frappe.meta.has_field(frm.doctype, fieldname)) {
} this.accounting_dimensions.forEach((dimension) => {
});
});
let copy_dimension = function(frm, cdt, cdn, fieldname) {
erpnext.dimension_filters.forEach((dimension) => {
let row = frappe.get_doc(cdt, cdn); let row = frappe.get_doc(cdt, cdn);
frm.script_manager.copy_from_first_row(fieldname, row, [dimension['fieldname']]); frm.script_manager.copy_from_first_row(fieldname, row, [dimension['fieldname']]);
}); });
};
let setup_child_filters = function(frm, doctype, parentfield, dimension) {
let fields = [];
frappe.model.with_doctype(doctype, () => {
frappe.meta.get_docfields(doctype).forEach((df) => {
if (df.fieldtype === 'Link' && df.options === 'Account') {
fields.push(df.fieldname);
} }
}); }
}
frm.set_query(dimension, parentfield, function(doc, cdt, cdn) {
let row = locals[cdt][cdn];
return erpnext.queries.get_filtered_dimensions(row, fields, dimension, doc.company);
});
});
};
let setup_account_filters = function(frm, dimension, fields) {
frm.set_query(dimension, function(doc) {
return erpnext.queries.get_filtered_dimensions(doc, fields, dimension, doc.company);
});
};

View File

@ -7,6 +7,7 @@ cur_frm.add_fetch('customer', 'tax_id', 'tax_id');
frappe.provide("erpnext.stock"); frappe.provide("erpnext.stock");
frappe.provide("erpnext.stock.delivery_note"); frappe.provide("erpnext.stock.delivery_note");
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on("Delivery Note", { frappe.ui.form.on("Delivery Note", {
setup: function(frm) { setup: function(frm) {
@ -75,7 +76,7 @@ frappe.ui.form.on("Delivery Note", {
} }
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
print_without_amount: function(frm) { print_without_amount: function(frm) {
@ -305,6 +306,7 @@ frappe.ui.form.on('Delivery Note', {
company: function(frm) { company: function(frm) {
frm.trigger("unhide_account_head"); frm.trigger("unhide_account_head");
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
unhide_account_head: function(frm) { unhide_account_head: function(frm) {

View File

@ -2,6 +2,7 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// eslint-disable-next-line // eslint-disable-next-line
frappe.provide("erpnext.accounts.dimensions");
{% include 'erpnext/public/js/controllers/buying.js' %}; {% include 'erpnext/public/js/controllers/buying.js' %};
frappe.ui.form.on('Material Request', { frappe.ui.form.on('Material Request', {
@ -66,6 +67,12 @@ frappe.ui.form.on('Material Request', {
filters: {'company': doc.company} filters: {'company': doc.company}
}; };
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
onload_post_render: function(frm) { onload_post_render: function(frm) {

View File

@ -46,6 +46,8 @@ frappe.ui.form.on("Purchase Receipt", {
erpnext.queries.setup_queries(frm, "Warehouse", function() { erpnext.queries.setup_queries(frm, "Warehouse", function() {
return erpnext.queries.warehouse(frm.doc); return erpnext.queries.warehouse(frm.doc);
}); });
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {
@ -75,6 +77,7 @@ frappe.ui.form.on("Purchase Receipt", {
company: function(frm) { company: function(frm) {
frm.trigger("toggle_display_account_head"); frm.trigger("toggle_display_account_head");
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
toggle_display_account_head: function(frm) { toggle_display_account_head: function(frm) {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.stock"); frappe.provide("erpnext.stock");
frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Stock Entry', { frappe.ui.form.on('Stock Entry', {
setup: function(frm) { setup: function(frm) {
@ -97,6 +98,7 @@ frappe.ui.form.on('Stock Entry', {
}); });
frm.add_fetch("bom_no", "inspection_required", "inspection_required"); frm.add_fetch("bom_no", "inspection_required", "inspection_required");
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
}, },
setup_quality_inspection: function(frm) { setup_quality_inspection: function(frm) {
@ -312,6 +314,8 @@ frappe.ui.form.on('Stock Entry', {
frm.set_value("letter_head", company_doc.default_letter_head); frm.set_value("letter_head", company_doc.default_letter_head);
} }
frm.trigger("toggle_display_account_head"); frm.trigger("toggle_display_account_head");
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
} }
}, },

View File

@ -2,6 +2,7 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.stock"); frappe.provide("erpnext.stock");
frappe.provide("erpnext.accounts.dimensions")
frappe.ui.form.on("Stock Reconciliation", { frappe.ui.form.on("Stock Reconciliation", {
onload: function(frm) { onload: function(frm) {
@ -26,6 +27,12 @@ frappe.ui.form.on("Stock Reconciliation", {
if (!frm.doc.expense_account) { if (!frm.doc.expense_account) {
frm.trigger("set_expense_account"); frm.trigger("set_expense_account");
} }
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
company: function(frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}, },
refresh: function(frm) { refresh: function(frm) {