From eaf144a545699b13affabdaef5e0fa9ad3d29fce Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 1 Mar 2012 13:05:04 +0530 Subject: [PATCH] form cleanup in pur cycle --- .../payable_voucher/payable_voucher.js | 13 +++-- .../payable_voucher/payable_voucher.py | 3 - .../purchase_common/purchase_common.js | 55 ++++++++++--------- .../purchase_common/purchase_common.py | 5 -- .../doctype/purchase_order/purchase_order.js | 11 ++-- .../doctype/purchase_order/purchase_order.py | 4 -- .../purchase_receipt/purchase_receipt.js | 14 +++-- .../purchase_receipt/purchase_receipt.py | 4 -- 8 files changed, 53 insertions(+), 56 deletions(-) diff --git a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js index a465ec07db..99bd24c6b8 100644 --- a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js +++ b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js @@ -45,11 +45,14 @@ cur_frm.cscript.onload = function(doc,dt,dn) { //------------------------ cur_frm.cscript.onload_post_render = function(doc, dt, dn) { var callback = function(doc, dt, dn) { - if(doc.__islocal && doc.supplier) cur_frm.cscript.supplier(doc,dt,dn); + var callback1 = function(doc, dt, dn) { + if(doc.__islocal && doc.supplier) cur_frm.cscript.supplier(doc,dt,dn); + } + + // defined in purchase_common.js + cur_frm.cscript.update_item_details(doc, dt, dn, callback1); } - - // defined in purchase_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn, callback); + cur_frm.cscript.dynamic_label(doc, dt, dn, callback); } // Refresh @@ -58,7 +61,7 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { cur_frm.clear_custom_buttons(); - cur_frm.cscript.dynamic_label(doc, cdt, cdn); + if (!cur_frm.cscript.is_onload) cur_frm.cscript.dynamic_label(doc, dt, dn); // Show / Hide button diff --git a/erpnext/accounts/doctype/payable_voucher/payable_voucher.py b/erpnext/accounts/doctype/payable_voucher/payable_voucher.py index fe733f7782..1a09a451c7 100644 --- a/erpnext/accounts/doctype/payable_voucher/payable_voucher.py +++ b/erpnext/accounts/doctype/payable_voucher/payable_voucher.py @@ -168,9 +168,6 @@ class DocType(TransactionBase): return ret - def get_comp_base_currency(self): - return get_obj('Purchase Common').get_comp_base_currency(self.doc.company) - # *************************** Server Utility Functions ***************************** # Get Company abbr diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 52f8e539fc..317df513c2 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -92,39 +92,36 @@ var set_dynamic_label_par = function(doc, cdt, cdn, base_curr) { var set_dynamic_label_child = function(doc, cdt, cdn, base_curr) { - // item table flds - item_cols_base = {'purchase_ref_rate': 'Ref Rate', 'amount': 'Amount'}; - item_cols_import = {'import_rate': 'Rate', 'import_ref_rate': 'Ref Rate', 'import_amount': 'Amount'}; + // item table flds + item_cols_base = {'purchase_ref_rate': 'Ref Rate', 'amount': 'Amount'}; + item_cols_import = {'import_rate': 'Rate', 'import_ref_rate': 'Ref Rate', 'import_amount': 'Amount'}; - for (d in item_cols_base) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_base[d]+' ('+base_curr+')'); - for (d in item_cols_import) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_import[d]+' ('+doc.currency+')'); + for (d in item_cols_base) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_base[d]+' ('+base_curr+')'); + for (d in item_cols_import) $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-'+d+'"]').html(item_cols_import[d]+' ('+doc.currency+')'); - var hide = (doc.currency == sys_defaults['currency']) ? false : true; - for (f in item_cols_base) cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp(f, hide); - - if (doc.doctype == 'Payable Voucher') { - $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-rate"]').html('Rate ('+base_curr+')'); - cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('rate', hide); - // advance table flds - adv_cols = {'advance_amount': 'Advance Amount', 'allocated_amount': 'Allocated Amount', 'tds_amount': 'TDS Amount', 'tds_allocated': 'TDS Allocated'} - for (d in adv_cols) $('[data-grid-fieldname="Advance Allocation Detail-'+d+'"]').html(adv_cols[d]+' ('+base_curr+')'); - } - else { - $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-purchase_rate"]').html('Rate ('+base_curr+')'); - cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('purchase_rate', hide); - } - - //tax table flds - tax_cols = {'tax_amount': 'Amount', 'total': 'Aggregate Total'}; - for (d in tax_cols) $('[data-grid-fieldname="Purchase Tax Detail-'+d+'"]').html(tax_cols[d]+' ('+base_curr+')'); - + var hide = (doc.currency == sys_defaults['currency']) ? false : true; + for (f in item_cols_base) cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp(f, hide); + if (doc.doctype == 'Payable Voucher') { + $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-rate"]').html('Rate ('+base_curr+')'); + cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('rate', hide); + // advance table flds + adv_cols = {'advance_amount': 'Advance Amount', 'allocated_amount': 'Allocated Amount', 'tds_amount': 'TDS Amount', 'tds_allocated': 'TDS Allocated'} + for (d in adv_cols) $('[data-grid-fieldname="Advance Allocation Detail-'+d+'"]').html(adv_cols[d]+' ('+base_curr+')'); + } + else { + $('[data-grid-fieldname="'+cur_frm.cscript.tname+'-purchase_rate"]').html('Rate ('+base_curr+')'); + cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp('purchase_rate', hide); + } + //tax table flds + tax_cols = {'tax_amount': 'Amount', 'total': 'Aggregate Total'}; + for (d in tax_cols) $('[data-grid-fieldname="Purchase Tax Detail-'+d+'"]').html(tax_cols[d]+' ('+base_curr+')'); } // Change label dynamically based on currency //------------------------------------------------------------------ -cur_frm.cscript.dynamic_label = function(doc, cdt, cdn) { +cur_frm.cscript.dynamic_label = function(doc, cdt, cdn, callback1) { var callback = function(r, rt) { if (r.message) base_curr = r.message; else base_curr = sys_defaults['currency']; @@ -136,10 +133,16 @@ cur_frm.cscript.dynamic_label = function(doc, cdt, cdn) { set_dynamic_label_par(doc, cdt, cdn, base_curr); set_dynamic_label_child(doc, cdt, cdn, base_curr); + + if(callback1) callback1(doc, cdt, cdn); } if (doc.company == sys_defaults['company']) callback('', ''); - else $c_obj(make_doclist(doc.doctype, doc.name), 'get_comp_base_currency', '', callback); + else wn.call({ + method: 'selling.doctype.sales_common.sales_common.get_comp_base_currency', + args: {company: doc.company}, + callback: callback + }); } cur_frm.cscript.currency = function(doc, cdt, cdn) { diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index 16afb02ccf..ca9181f154 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -197,11 +197,6 @@ class DocType(TransactionBase): msgprint("%s has no Last Purchase Rate."% d.item_code) - def get_comp_base_currency(self, comp): - """ get default currency of company""" - return webnotes.conn.sql("select default_currency from `tabCompany` where name = %s", comp)[0][0] - - # validation # ------------------------------------------------------------------------------------------------------- diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 0a6c547978..7af1204fa4 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -41,9 +41,12 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { - if(doc.__islocal){ - cur_frm.cscript.get_default_schedule_date(doc); - } + var callback = function(doc, cdt, cdn) { + if(doc.__islocal){ + cur_frm.cscript.get_default_schedule_date(doc); + } + } + cur_frm.cscript.dynamic_label(doc, cdt, cdn, callback); } // ================================== Refresh ========================================== @@ -52,7 +55,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { // --------------------------------- cur_frm.clear_custom_buttons(); - cur_frm.cscript.dynamic_label(doc, cdt, cdn); + if (!cur_frm.cscript.is_onload) cur_frm.cscript.dynamic_label(doc, cdt, cdn); if(doc.docstatus == 1 && doc.status != 'Stopped'){ var ch = getchildren('PO Detail',doc.name,'po_details'); diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index efa05244c0..794580724b 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -100,10 +100,6 @@ class DocType(TransactionBase): return get_obj('Purchase Common').get_tc_details(self) - def get_comp_base_currency(self): - return get_obj('Purchase Common').get_comp_base_currency(self.doc.company) - - # validate if indent has been pulled twice def validate_prev_docname(self): diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index 0f6d1a8a80..7ad9d91928 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -40,12 +40,15 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.onload_post_render = function(doc, dt, dn) { var callback = function(doc, dt, dn) { - if(doc.__islocal){ - cur_frm.cscript.get_default_schedule_date(doc); + var callback1 = function(doc, dt, dn) { + if(doc.__islocal){ + cur_frm.cscript.get_default_schedule_date(doc); + } } + // defined in purchase_common.js + cur_frm.cscript.update_item_details(doc, dt, dn, callback1); } - // defined in purchase_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn, callback); + cur_frm.cscript.dynamic_label(doc, dt, dn, callback); } //========================== Refresh =============================================================== @@ -55,7 +58,8 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { // --------------------------------- cur_frm.clear_custom_buttons(); - cur_frm.cscript.dynamic_label(doc, cdt, cdn); + if (!cur_frm.cscript.is_onload) cur_frm.cscript.dynamic_label(doc, cdt, cdn); + if(doc.docstatus == 1){ var ch = getchildren('Purchase Receipt Detail',doc.name,'purchase_receipt_details'); diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 530afcf09d..f3e5d7737d 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -88,10 +88,6 @@ class DocType(TransactionBase): def get_tc_details(self): return get_obj('Purchase Common').get_tc_details(self) - def get_comp_base_currency(self): - return get_obj('Purchase Common').get_comp_base_currency(self.doc.company) - - # get available qty at warehouse def get_bin_details(self, arg = ''):