From 702f174265d8bace6411773ea3ca9aaa2545869d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 13 Feb 2012 15:29:41 +0530 Subject: [PATCH] call update item details in post render --- .../receivable_voucher/receivable_voucher.js | 28 +++++++++---------- .../selling/doctype/quotation/quotation.js | 8 ++---- .../doctype/sales_common/sales_common.js | 19 +++++++++---- .../doctype/sales_order/sales_order.js | 7 ++--- .../doctype/delivery_note/delivery_note.js | 5 ++-- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js index b8789b304f..c12c2fb303 100644 --- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js +++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js @@ -23,9 +23,6 @@ cur_frm.cscript.onload = function(doc,dt,dn) { hide_field(['customer_address', 'contact_person', 'customer_name', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']); - // defined in sales_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn); - //for previously created sales invoice, set required field related to pos if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn); @@ -33,21 +30,22 @@ cur_frm.cscript.onload = function(doc,dt,dn) { } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { + var callback = null; if(doc.customer && doc.__islocal) { // called from mapper, update the account names for items and customer - $c_obj(make_doclist(doc.doctype,doc.name), - 'load_default_accounts','', - function(r,rt) { - refresh_field('entries'); - cur_frm.cscript.customer(doc,dt,dn); - } - ); - } - - if(!doc.customer && doc.__islocal) { - // new -- load default taxes - cur_frm.cscript.load_taxes(doc, cdt, cdn); + callback = function(doc, dt, dn) { + $c_obj(make_doclist(doc.doctype,doc.name), + 'load_default_accounts','', + function(r,rt) { + refresh_field('entries'); + cur_frm.cscript.customer(doc,dt,dn); + } + ); + } } + // defined in sales_common.js + cur_frm.cscript.update_item_details(doc, cdt, cdn, callback); + } diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 9ba743d5ae..e39b5f06c1 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -32,15 +32,11 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } } - // defined in sales_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn); - } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { - // load default charges - if(doc.__islocal && !getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length) - cur_frm.cscript.load_taxes(doc, cdt, cdn); + // defined in sales_common.js + cur_frm.cscript.update_item_details(doc, cdt, cdn); } // hide - unhide fields based on lead or customer.. diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js index 57f379cf8d..cdcec5b958 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.js +++ b/erpnext/selling/doctype/sales_common/sales_common.js @@ -6,18 +6,23 @@ // cur_frm.cscript.sales_team_fname - Sales Team fieldname // ============== Load Default Taxes =================== -cur_frm.cscript.load_taxes = function(doc, cdt, cdn) { +cur_frm.cscript.load_taxes = function(doc, cdt, cdn, callback) { // run if this is not executed from dt_map... - if(doc.customer) return; + doc = locals[doc.doctype][doc.name]; + if(doc.customer || getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length) { + if(callback) callback(doc, cdt, cdn); + return; + } $c_obj([doc],'load_default_taxes','',function(r,rt){ - refresh_field('other_charges'); + refresh_field('other_charges'); + if(callback) callback(doc, cdt, cdn); }); } // Gets called after existing item details are update to fill in // remaining default values -cur_frm.cscript.load_defaults = function(doc, dt, dn) { +cur_frm.cscript.load_defaults = function(doc, dt, dn, callback) { if(!cur_frm.doc.__islocal) { return; } doc = locals[doc.doctype][doc.name]; @@ -31,11 +36,13 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn) { LocalDB.set_default_values(children[i]); } refresh_field(cur_frm.cscript.fname); + cur_frm.cscript.load_taxes(doc, dt, dn, callback); } // Update existing item details -cur_frm.cscript.update_item_details = function(doc, dt, dn) { +cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) { + doc = locals[doc.doctype][doc.name]; if(!cur_frm.doc.__islocal) return; var children = getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname); if(children) { @@ -44,7 +51,7 @@ cur_frm.cscript.update_item_details = function(doc, dt, dn) { if(!r.exc) { refresh_field(cur_frm.cscript.fname); doc = locals[doc.doctype][doc.name]; - cur_frm.cscript.load_defaults(doc, dt, dn); + cur_frm.cscript.load_defaults(doc, dt, dn, callback); } }); } diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 59f8b8439b..f5f8b58b15 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -23,15 +23,12 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group','shipping_address']); } - // defined in sales_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn); } cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { if(doc.__islocal) { - if(doc.quotation) cur_frm.cscript['Pull Quotation Details'](doc,cdt,cdn); - } else { - cur_frm.cscript.load_taxes(doc, cdt, cdn); + // defined in sales_common.js + cur_frm.cscript.update_item_details(doc, cdt, cdn, callback); } } diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index 4099174d5d..b6329c50d3 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -24,12 +24,13 @@ cur_frm.cscript.onload = function(doc, dt, dn) { hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); } - // defined in sales_common.js - //cur_frm.cscript.update_item_details(doc, cdt, cdn); } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { + // defined in sales_common.js + //cur_frm.cscript.update_item_details(doc, cdt, cdn); + // load default charges if(doc.__islocal && !getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length) cur_frm.cscript.load_taxes(doc, cdt, cdn);