diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js index 92cdb635da3..3d0fc0a42ce 100644 --- a/erpnext/accounts/doctype/c_form/c_form.js +++ b/erpnext/accounts/doctype/c_form/c_form.js @@ -4,24 +4,38 @@ //c-form js file // ----------------------------- +frappe.ui.form.on('C-Form', { + setup(frm) { + frm.fields_dict.invoices.grid.get_field("invoice_no").get_query = function(doc) { + return { + filters: { + "docstatus": 1, + "customer": doc.customer, + "company": doc.company, + "c_form_applicable": 'Yes', + "c_form_no": '' + } + }; + } -cur_frm.fields_dict.invoices.grid.get_field("invoice_no").get_query = function(doc) { - return { - filters: { - "docstatus": 1, - "customer": doc.customer, - "company": doc.company, - "c_form_applicable": 'Yes', - "c_form_no": '' + frm.fields_dict.state.get_query = function() { + return { + filters: { + country: "India" + } + }; } } -} +}); -cur_frm.fields_dict.state.get_query = function(doc) { - return {filters: { country: "India"}} -} +frappe.ui.form.on('C-Form Invoice Detail', { + invoice_no(frm, cdt, cdn) { + let d = frappe.get_doc(cdt, cdn); -cur_frm.cscript.invoice_no = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - return get_server_fields('get_invoice_details', d.invoice_no, 'invoices', doc, cdt, cdn, 1); -} \ No newline at end of file + frm.call('get_invoice_details', { + invoice_no: d.invoice_no + }).then(r => { + frappe.model.set_value(cdt, cdn, r.message); + }); + } +}); diff --git a/erpnext/accounts/doctype/cost_center/cost_center.js b/erpnext/accounts/doctype/cost_center/cost_center.js index 3df4da52efc..96ec57dcb0b 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.js +++ b/erpnext/accounts/doctype/cost_center/cost_center.js @@ -22,6 +22,28 @@ frappe.ui.form.on('Cost Center', { frm.trigger("update_cost_center_number"); }); } + + let intro_txt = ''; + let doc = frm.doc; + frm.toggle_display('cost_center_name', doc.__islocal); + frm.toggle_enable(['is_group', 'company'], doc.__islocal); + + if(!doc.__islocal && doc.is_group==1) { + intro_txt += __('Note: This Cost Center is a Group. Cannot make accounting entries against groups.'); + } + + frm.events.hide_unhide_group_ledger(frm); + + frm.toggle_display('sb1', doc.is_group==0); + frm.set_intro(intro_txt); + + if(!frm.doc.__islocal) { + frm.add_custom_button(__('Chart of Cost Centers'), + function() { frappe.set_route("Tree", "Cost Center"); }); + + frm.add_custom_button(__('Budget'), + function() { frappe.set_route("List", "Budget", {'cost_center': frm.doc.name}); }); + } }, update_cost_center_number: function(frm) { var d = new frappe.ui.Dialog({ @@ -64,62 +86,38 @@ frappe.ui.form.on('Cost Center', { primary_action_label: __('Update') }); d.show(); + }, + + parent_cost_center(frm) { + if(!frm.doc.company) { + frappe.msgprint(__('Please enter company name first')); + } + }, + + hide_unhide_group_ledger(frm) { + let doc = frm.doc; + if (doc.is_group == 1) { + frm.add_custom_button(__('Convert to Non-Group'), + () => frm.events.convert_to_ledger(frm)); + } else if (doc.is_group == 0) { + frm.add_custom_button(__('Convert to Group'), + () => frm.events.convert_to_group(frm)); + } + }, + + convert_to_group(frm) { + frm.call('convert_ledger_to_group').then(r => { + if(r.message === 1) { + frm.refresh(); + } + }); + }, + + convert_to_ledger(frm) { + frm.call('convert_group_to_ledger').then(r => { + if(r.message === 1) { + frm.refresh(); + } + }); } }); - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - var intro_txt = ''; - cur_frm.toggle_display('cost_center_name', doc.__islocal); - cur_frm.toggle_enable(['is_group', 'company'], doc.__islocal); - - if(!doc.__islocal && doc.is_group==1) { - intro_txt += __('Note: This Cost Center is a Group. Cannot make accounting entries against groups.'); - } - - cur_frm.cscript.hide_unhide_group_ledger(doc); - - cur_frm.toggle_display('sb1', doc.is_group==0) - cur_frm.set_intro(intro_txt); - - if(!cur_frm.doc.__islocal) { - cur_frm.add_custom_button(__('Chart of Cost Centers'), - function() { frappe.set_route("Tree", "Cost Center"); }); - - cur_frm.add_custom_button(__('Budget'), - function() { frappe.set_route("List", "Budget", {'cost_center': cur_frm.doc.name}); }); - } -} - -cur_frm.cscript.parent_cost_center = function(doc, cdt, cdn) { - if(!doc.company){ - frappe.msgprint(__('Please enter company name first')); - } -} - -cur_frm.cscript.hide_unhide_group_ledger = function(doc) { - if (doc.is_group == 1) { - cur_frm.add_custom_button(__('Convert to Non-Group'), - function() { cur_frm.cscript.convert_to_ledger(); }, "fa fa-retweet", - "btn-default") - } else if (doc.is_group == 0) { - cur_frm.add_custom_button(__('Convert to Group'), - function() { cur_frm.cscript.convert_to_group(); }, "fa fa-retweet", - "btn-default") - } -} - -cur_frm.cscript.convert_to_ledger = function(doc, cdt, cdn) { - return $c_obj(cur_frm.doc,'convert_group_to_ledger','',function(r,rt) { - if(r.message == 1) { - cur_frm.refresh(); - } - }); -} - -cur_frm.cscript.convert_to_group = function(doc, cdt, cdn) { - return $c_obj(cur_frm.doc,'convert_ledger_to_group','',function(r,rt) { - if(r.message == 1) { - cur_frm.refresh(); - } - }); -} diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js index 4dc64338ae4..152e17dbc88 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js @@ -1,37 +1,31 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -$.extend(cur_frm.cscript, { - onload: function() { - if(cur_frm.doc.__islocal) { - cur_frm.set_value("year_start_date", +frappe.ui.form.on('Fiscal Year', { + onload: function(frm) { + if(frm.doc.__islocal) { + frm.set_value("year_start_date", frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1)); } }, - refresh: function (doc, dt, dn) { - var me = this; - this.frm.toggle_enable('year_start_date', doc.__islocal) - this.frm.toggle_enable('year_end_date', doc.__islocal) + refresh: function (frm) { + let doc = frm.doc; + frm.toggle_enable('year_start_date', doc.__islocal); + frm.toggle_enable('year_end_date', doc.__islocal); if (!doc.__islocal && (doc.name != frappe.sys_defaults.fiscal_year)) { - this.frm.add_custom_button(__("Default"), - this.frm.cscript.set_as_default, "fa fa-star"); - this.frm.set_intro(__("To set this Fiscal Year as Default, click on 'Set as Default'")); + frm.add_custom_button(__("Set as Default"), () => frm.events.set_as_default(frm)); + frm.set_intro(__("To set this Fiscal Year as Default, click on 'Set as Default'")); } else { - this.frm.set_intro(""); + frm.set_intro(""); } }, - set_as_default: function() { - return frappe.call({ - doc: cur_frm.doc, - method: "set_as_default" - }); + set_as_default: function(frm) { + return frm.call('set_as_default'); }, - year_start_date: function(doc, dt, dn) { - var me = this; - - var year_end_date = - frappe.datetime.add_days(frappe.datetime.add_months(this.frm.doc.year_start_date, 12), -1); - this.frm.set_value("year_end_date", year_end_date); + year_start_date: function(frm) { + let year_end_date = + frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.year_start_date, 12), -1); + frm.set_value("year_end_date", year_end_date); }, }); diff --git a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js index 7b489de0a35..569f0084c6a 100644 --- a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js +++ b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js @@ -1,16 +1,16 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.cscript.onload = function(doc,cdt,cdn){ - if(doc.__islocal){ - var callback1 = function(r,rt){ - refresh_field('percentages'); +frappe.ui.form.on('Monthly Distribution', { + onload(frm) { + if(frm.doc.__islocal) { + return frm.call('get_months').then(() => { + frm.refresh_field('percentages'); + }); } + }, - return $c('runserverobj', {'method':'get_months', 'docs':doc}, callback1); + refresh(frm) { + frm.toggle_display('distribution_id', frm.doc.__islocal); } -} - -cur_frm.cscript.refresh = function(doc,cdt,cdn){ - cur_frm.toggle_display('distribution_id', doc.__islocal); -} +}); diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js index e1fe5a16a39..8f09bc36912 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js @@ -1,6 +1,10 @@ -cur_frm.cscript.refresh = function(doc, dt, dn){ - if(!doc.__islocal){ - var df = frappe.meta.get_docfield(doc.doctype, "payment_gateway", doc.name); - df.read_only = 1; +// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +frappe.ui.form.on('Payment Gateway Account', { + refresh(frm) { + if(!frm.doc.__islocal) { + frm.set_df_property('payment_gateway', 'read_only', 1); + } } -} \ No newline at end of file +}); diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js index e5b63367556..c92b58b5809 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js @@ -1,108 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on("Pricing Rule", "refresh", function(frm) { - var help_content = - `
- - - ${__('Notes')} --
|
- - ${__('How Pricing Rule is applied?')} --
|