fix: Move filter setup to doctype controllers
This commit is contained in:
parent
92b3449789
commit
6b9dda5f3e
@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Budget', {
|
||||
onload: function(frm) {
|
||||
@ -11,7 +12,7 @@ frappe.ui.form.on('Budget', {
|
||||
is_group: 0
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
frm.set_query("monthly_distribution", function() {
|
||||
return {
|
||||
@ -19,7 +20,9 @@ frappe.ui.form.on('Budget', {
|
||||
fiscal_year: frm.doc.fiscal_year
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -120,6 +120,8 @@ frappe.ui.form.on("Journal Entry", {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
voucher_type: function(frm){
|
||||
@ -197,6 +199,7 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
||||
this.load_defaults();
|
||||
this.setup_queries();
|
||||
this.setup_balance_formatter();
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||
},
|
||||
|
||||
onload_post_render: function() {
|
||||
@ -397,6 +400,8 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
||||
}
|
||||
}
|
||||
cur_frm.cscript.update_totals(doc);
|
||||
|
||||
erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'accounts');
|
||||
},
|
||||
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Loyalty Program', {
|
||||
setup: function(frm) {
|
||||
var help_content =
|
||||
@ -47,11 +49,16 @@ frappe.ui.form.on('Loyalty Program', {
|
||||
});
|
||||
|
||||
frm.set_value("company", frappe.defaults.get_user_default("Company"));
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
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."));
|
||||
}
|
||||
},
|
||||
|
||||
company: function(frm) {
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
}
|
||||
});
|
||||
|
@ -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.page.set_indicator(__('In Progress'), 'orange');
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
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) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
{% include "erpnext/public/js/controllers/accounts.js" %}
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Payment Entry', {
|
||||
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_to) frm.set_value("paid_to_account_currency", null);
|
||||
}
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
setup: function(frm) {
|
||||
@ -158,6 +161,7 @@ frappe.ui.form.on('Payment Entry', {
|
||||
company: function(frm) {
|
||||
frm.events.hide_unhide_fields(frm);
|
||||
frm.events.set_dynamic_labels(frm);
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
contact_person: function(frm) {
|
||||
|
@ -48,6 +48,8 @@ frappe.ui.form.on('POS Profile', {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
@ -58,6 +60,7 @@ frappe.ui.form.on('POS Profile', {
|
||||
|
||||
company: function(frm) {
|
||||
frm.trigger("toggle_display_account_head");
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
toggle_display_account_head: function(frm) {
|
||||
|
@ -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() {
|
||||
this._super();
|
||||
|
||||
@ -31,6 +36,8 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
if (this.frm.doc.supplier && this.frm.doc.__islocal) {
|
||||
this.frm.trigger('supplier');
|
||||
}
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(doc) {
|
||||
|
@ -5,14 +5,17 @@
|
||||
cur_frm.pformat.print_heading = 'Invoice';
|
||||
|
||||
{% include 'erpnext/selling/sales_common.js' %};
|
||||
|
||||
|
||||
frappe.provide("erpnext.accounts");
|
||||
|
||||
|
||||
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
|
||||
setup: function(doc) {
|
||||
this.setup_posting_date_time_check();
|
||||
this._super(doc);
|
||||
},
|
||||
company: function() {
|
||||
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
|
||||
},
|
||||
onload: function() {
|
||||
var me = this;
|
||||
this._super();
|
||||
@ -33,6 +36,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
me.frm.refresh_fields();
|
||||
}
|
||||
erpnext.queries.setup_warehouse_query(this.frm);
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(doc, dt, dn) {
|
||||
|
@ -1,7 +1,17 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide('erpnext.accounts.dimensions');
|
||||
|
||||
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) {
|
||||
frm.set_query("account", function() {
|
||||
return {
|
||||
|
@ -2,6 +2,7 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.asset");
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Asset', {
|
||||
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) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Asset Value Adjustment', {
|
||||
setup: function(frm) {
|
||||
frm.add_fetch('company', 'cost_center', 'cost_center');
|
||||
@ -13,11 +15,19 @@ frappe.ui.form.on('Asset Value Adjustment', {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
if(frm.is_new() && frm.doc.asset) {
|
||||
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) {
|
||||
frm.trigger("set_current_asset_value");
|
||||
},
|
||||
|
@ -2,7 +2,7 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext.buying");
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
{% include 'erpnext/public/js/controllers/buying.js' %};
|
||||
|
||||
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) {
|
||||
set_schedule_date(frm);
|
||||
if (!frm.doc.transaction_date){
|
||||
@ -39,6 +43,8 @@ frappe.ui.form.on("Purchase Order", {
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
frappe.ui.form.on('Fee Schedule', {
|
||||
setup: function(frm) {
|
||||
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');
|
||||
},
|
||||
|
||||
company: function(frm) {
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
frm.set_query('receivable_account', function(doc) {
|
||||
return {
|
||||
@ -50,6 +55,8 @@ frappe.ui.form.on('Fee Schedule', {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Fee Structure', {
|
||||
setup: function(frm) {
|
||||
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');
|
||||
},
|
||||
|
||||
company: function(frm) {
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
frm.set_query('academic_term', function() {
|
||||
return {
|
||||
@ -35,6 +41,8 @@ frappe.ui.form.on('Fee Structure', {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on("Fees", {
|
||||
setup: function(frm) {
|
||||
@ -9,6 +10,10 @@ frappe.ui.form.on("Fees", {
|
||||
frm.add_fetch("fee_structure", "cost_center", "cost_center");
|
||||
},
|
||||
|
||||
company: function(frm) {
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
onload: function(frm){
|
||||
frm.set_query("academic_term",function(){
|
||||
return{
|
||||
@ -45,6 +50,8 @@ frappe.ui.form.on("Fees", {
|
||||
if (!frm.doc.posting_date) {
|
||||
frm.doc.posting_date = frappe.datetime.get_today();
|
||||
}
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -2,11 +2,21 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext.hr");
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
|
||||
expense_type: function(doc, cdt, cdn) {
|
||||
frappe.ui.form.on('Expense Claim', {
|
||||
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];
|
||||
if(!doc.company) {
|
||||
if(!frm.doc.company) {
|
||||
d.expense_type = "";
|
||||
frappe.msgprint(__("Please set the Company"));
|
||||
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",
|
||||
args: {
|
||||
"expense_claim_type": d.expense_type,
|
||||
"company": doc.company
|
||||
"company": frm.doc.company
|
||||
},
|
||||
callback: function(r) {
|
||||
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','employee_name','employee_name');
|
||||
cur_frm.add_fetch('expense_type','description','description');
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
var in_progress = false;
|
||||
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Payroll Entry', {
|
||||
onload: function (frm) {
|
||||
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) {
|
||||
@ -122,6 +126,7 @@ frappe.ui.form.on('Payroll Entry', {
|
||||
|
||||
company: function (frm) {
|
||||
frm.events.clear_employee_table(frm);
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
department: function (frm) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide('erpnext.accounts.dimensions');
|
||||
|
||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup: function() {
|
||||
this._super();
|
||||
@ -106,6 +108,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
if(!item.warehouse && frm.doc.set_warehouse) {
|
||||
item.warehouse = frm.doc.set_warehouse;
|
||||
}
|
||||
|
||||
erpnext.accounts.dimensions.copy_dimension_from_first_row(frm, cdt, cdn, 'items');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,60 +1,79 @@
|
||||
frappe.provide('frappe.ui.form');
|
||||
let default_dimensions = {};
|
||||
frappe.provide('erpnext.accounts');
|
||||
|
||||
let doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
|
||||
"Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Shipping Rule", "Loyalty Program",
|
||||
"Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool",
|
||||
"Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Asset", "Asset Value Adjustment"];
|
||||
|
||||
let child_docs = ["Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account",
|
||||
"Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction",
|
||||
"Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan",
|
||||
"Sales Taxes and Charges", "Purchase Taxes and Charges"];
|
||||
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters",
|
||||
args: {
|
||||
'with_costcenter_and_project': true
|
||||
erpnext.accounts.dimensions = {
|
||||
setup_dimension_filters(frm, doctype) {
|
||||
this.accounting_dimensions = [];
|
||||
this.default_dimensions = {};
|
||||
this.fetch_custom_dimensions(frm, doctype);
|
||||
},
|
||||
callback: function(r) {
|
||||
erpnext.dimension_filters = r.message[0];
|
||||
default_dimensions = r.message[1];
|
||||
}
|
||||
});
|
||||
|
||||
doctypes_with_dimensions.forEach((doctype) => {
|
||||
frappe.ui.form.on(doctype, {
|
||||
onload: function(frm) {
|
||||
erpnext.dimension_filters.forEach((dimension) => {
|
||||
frappe.model.with_doctype(dimension['document_type'], () => {
|
||||
let parent_fields = [];
|
||||
frappe.meta.get_docfields(doctype).forEach((df) => {
|
||||
if (df.fieldtype === 'Link' && df.options === 'Account') {
|
||||
parent_fields.push(df.fieldname);
|
||||
} else if (df.fieldtype === 'Table') {
|
||||
setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']);
|
||||
}
|
||||
fetch_custom_dimensions(frm, doctype) {
|
||||
let me = this;
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
|
||||
args: {
|
||||
'with_cost_center_and_project': true
|
||||
},
|
||||
callback: function(r) {
|
||||
me.accounting_dimensions = r.message[0];
|
||||
me.default_dimensions = r.message[1];
|
||||
me.setup_filters(frm, doctype);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setup_account_filters(frm, dimension['fieldname'], parent_fields);
|
||||
});
|
||||
setup_filters(frm, doctype) {
|
||||
this.accounting_dimensions.forEach((dimension) => {
|
||||
frappe.model.with_doctype(dimension['document_type'], () => {
|
||||
let parent_fields = [];
|
||||
frappe.meta.get_docfields(doctype).forEach((df) => {
|
||||
if (df.fieldtype === 'Link' && df.options === 'Account') {
|
||||
parent_fields.push(df.fieldname);
|
||||
} else if (df.fieldtype === 'Table') {
|
||||
this.setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']);
|
||||
}
|
||||
|
||||
if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
|
||||
this.setup_account_filters(frm, dimension['fieldname'], parent_fields);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
company: function(frm) {
|
||||
if(frm.doc.company && (Object.keys(default_dimensions || {}).length > 0)
|
||||
&& default_dimensions[frm.doc.company]) {
|
||||
frm.trigger('update_dimension');
|
||||
}
|
||||
},
|
||||
setup_child_filters(frm, doctype, parentfield, dimension) {
|
||||
let fields = [];
|
||||
|
||||
update_dimension: function(frm) {
|
||||
erpnext.dimension_filters.forEach((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);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
setup_account_filters(frm, dimension, fields) {
|
||||
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.doc.company && Object.keys(default_dimensions || {}).length > 0
|
||||
&& default_dimensions[frm.doc.company]) {
|
||||
if(frm.doc.company && Object.keys(this.default_dimensions || {}).length > 0
|
||||
&& 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 (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(frm, cdt, cdn, "accounts");
|
||||
copy_dimension_from_first_row(frm, cdt, cdn, fieldname) {
|
||||
if (frappe.meta.has_field(frm.doctype, fieldname)) {
|
||||
this.accounting_dimensions.forEach((dimension) => {
|
||||
let row = frappe.get_doc(cdt, cdn);
|
||||
frm.script_manager.copy_from_first_row(fieldname, row, [dimension['fieldname']]);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let copy_dimension = function(frm, cdt, cdn, fieldname) {
|
||||
erpnext.dimension_filters.forEach((dimension) => {
|
||||
let row = frappe.get_doc(cdt, cdn);
|
||||
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);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ cur_frm.add_fetch('customer', 'tax_id', 'tax_id');
|
||||
|
||||
frappe.provide("erpnext.stock");
|
||||
frappe.provide("erpnext.stock.delivery_note");
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on("Delivery Note", {
|
||||
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) {
|
||||
@ -305,6 +306,7 @@ frappe.ui.form.on('Delivery Note', {
|
||||
|
||||
company: function(frm) {
|
||||
frm.trigger("unhide_account_head");
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
unhide_account_head: function(frm) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
// eslint-disable-next-line
|
||||
frappe.provide("erpnext.accounts.dimensions");
|
||||
{% include 'erpnext/public/js/controllers/buying.js' %};
|
||||
|
||||
frappe.ui.form.on('Material Request', {
|
||||
@ -66,6 +67,12 @@ frappe.ui.form.on('Material Request', {
|
||||
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) {
|
||||
|
@ -46,6 +46,8 @@ frappe.ui.form.on("Purchase Receipt", {
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
@ -75,6 +77,7 @@ frappe.ui.form.on("Purchase Receipt", {
|
||||
|
||||
company: function(frm) {
|
||||
frm.trigger("toggle_display_account_head");
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
},
|
||||
|
||||
toggle_display_account_head: function(frm) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.accounts.dimensions");
|
||||
|
||||
frappe.ui.form.on('Stock Entry', {
|
||||
setup: function(frm) {
|
||||
@ -97,6 +98,7 @@ frappe.ui.form.on('Stock Entry', {
|
||||
});
|
||||
|
||||
frm.add_fetch("bom_no", "inspection_required", "inspection_required");
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
},
|
||||
|
||||
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.trigger("toggle_display_account_head");
|
||||
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext.stock");
|
||||
frappe.provide("erpnext.accounts.dimensions")
|
||||
|
||||
frappe.ui.form.on("Stock Reconciliation", {
|
||||
onload: function(frm) {
|
||||
@ -26,6 +27,12 @@ frappe.ui.form.on("Stock Reconciliation", {
|
||||
if (!frm.doc.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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user