From 6d517ff0057555c19864d5e778c24b8d8415002a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 1 Mar 2012 10:57:23 +0530 Subject: [PATCH] form cleanup: fixed callback issues --- css/all-app.css | 2 +- css/all-web.css | 2 +- .../receivable_voucher/receivable_voucher.js | 49 +++++++------ .../receivable_voucher/receivable_voucher.py | 19 ++--- .../selling/doctype/quotation/quotation.js | 12 ++-- .../selling/doctype/quotation/quotation.py | 13 ++-- .../doctype/sales_common/sales_common.js | 72 +++++++++---------- .../doctype/sales_common/sales_common.py | 26 +++---- .../doctype/sales_order/sales_order.js | 17 +++-- .../doctype/sales_order/sales_order.py | 15 ++-- .../doctype/delivery_note/delivery_note.js | 12 ++-- .../doctype/delivery_note/delivery_note.py | 15 ++-- version.num | 2 +- 13 files changed, 121 insertions(+), 135 deletions(-) diff --git a/css/all-app.css b/css/all-app.css index b49caedee9..b2fd2e5732 100644 --- a/css/all-app.css +++ b/css/all-app.css @@ -1043,7 +1043,7 @@ div.dialog_head { } div.dialog_body { - padding: 8px 8px 16px; + padding: 8px 4px 16px 4px; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; diff --git a/css/all-web.css b/css/all-web.css index bebfe9a334..9359de898e 100644 --- a/css/all-web.css +++ b/css/all-web.css @@ -362,7 +362,7 @@ div.dialog_head { } div.dialog_body { - padding: 8px 8px 16px; + padding: 8px 4px 16px 4px; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js index bc0a145173..391bbcd8ae 100644 --- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js +++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js @@ -42,27 +42,31 @@ cur_frm.cscript.onload = function(doc,dt,dn) { } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { - var callback2 = null; - if(doc.customer && doc.__islocal) { + var callback = function(doc, dt, dn) { // called from mapper, update the account names for items and customer - callback2 = 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,onload=true); - } - ); + var callback2 = function(doc, dt, dn) { + if(doc.customer && doc.__islocal) { + $c_obj(make_doclist(doc.doctype,doc.name), + 'load_default_accounts','', + function(r,rt) { + refresh_field('entries'); + cur_frm.cscript.customer(doc,dt,dn,onload=true); + } + ); + } + } + // defined in sales_common.js + var callback1 = function(doc, dt, dn) { + //for previously created sales invoice, set required field related to pos + cur_frm.cscript.update_item_details(doc, dt, dn, callback2); } - } - // defined in sales_common.js - var callback1 = function(doc, dt, dn) { - //for previously created sales invoice, set required field related to pos - cur_frm.cscript.update_item_details(doc, dt, dn, callback2); - } - if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn,callback1); - else cur_frm.cscript.update_item_details(doc, dt, dn, callback2); + if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn,callback1); + else cur_frm.cscript.update_item_details(doc, dt, dn, callback2); + } + + cur_frm.cscript.hide_price_list_currency(doc, dt, dn, callback); + } @@ -97,16 +101,11 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { cur_frm.cscript.refresh = function(doc, dt, dn) { cur_frm.cscript.is_opening(doc, dt, dn); cur_frm.cscript.hide_fields(doc, dt, dn); - - var callback = function() { - cur_frm.cscript.dynamic_label(doc, dt, dn); - } - cur_frm.cscript.hide_price_list_currency(doc, dt, dn, callback); - - // Show / Hide button cur_frm.clear_custom_buttons(); + if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, dt, dn); + if(doc.docstatus==1) { cur_frm.add_custom_button('View Ledger', cur_frm.cscript['View Ledger Entry']); cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']); diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py index 03fd7620ca..d09adc2e64 100644 --- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py +++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py @@ -167,16 +167,19 @@ class DocType(TransactionBase): # Item Details # ------------- def get_item_details(self, args=None): - args = eval(args) - if args['item_code']: + args = args and eval(args) or {} + if args.get('item_code'): ret = get_obj('Sales Common').get_item_details(args, self) return self.get_pos_details(args, ret) else: obj = get_obj('Sales Common') for doc in self.doclist: if doc.fields.get('item_code'): - ret = obj.get_item_details(doc.item_code, self) - ret = self.get_pos_details(doc.item_code, ret) + arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), + 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; + + ret = obj.get_item_details(arg, self) + ret = self.get_pos_details(arg, ret) for r in ret: if not doc.fields.get(r): doc.fields[r] = ret[r] @@ -205,14 +208,6 @@ class DocType(TransactionBase): get_obj('Sales Common').get_adj_percent(self) - def get_comp_base_currency(self): - return get_obj('Sales Common').get_comp_base_currency(self.doc.company) - - def get_price_list_currency(self): - return get_obj('Sales Common').get_price_list_currency(self.doc.price_list_name, self.doc.company) - - - # Get tax rate if account type is tax # ------------------------------------ def get_rate(self,arg): diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 2a130a59cb..7f40782d0c 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -50,8 +50,11 @@ cur_frm.cscript.onload = function(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); + var callback = function(doc, dt, dn) { + // defined in sales_common.js + cur_frm.cscript.update_item_details(doc, dt, dn); + } + cur_frm.cscript.hide_price_list_currency(doc, dt, dn, callback); } // hide - unhide fields based on lead or customer.. @@ -83,10 +86,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.clear_custom_buttons(); - var callback = function() { - cur_frm.cscript.dynamic_label(doc, cdt, cdn); - } - cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn, callback); + if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn); if(doc.docstatus == 1 && doc.status!='Order Lost') { diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 531de21ed4..de4056d2d6 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -77,14 +77,16 @@ class DocType(TransactionBase): # Get Item Details # ----------------- def get_item_details(self, args=None): - args = eval(args) - if args['item_code']: + args = args and eval(args) or {} + if args.get('item_code'): return get_obj('Sales Common').get_item_details(args, self) else: obj = get_obj('Sales Common') for doc in self.doclist: if doc.fields.get('item_code'): - ret = obj.get_item_details(doc.item_code, self) + arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), + 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; + ret = obj.get_item_details(arg, self) for r in ret: if not doc.fields.get(r): doc.fields[r] = ret[r] @@ -96,11 +98,6 @@ class DocType(TransactionBase): get_obj('Sales Common').get_adj_percent(self) - def get_comp_base_currency(self): - return get_obj('Sales Common').get_comp_base_currency(self.doc.company) - - def get_price_list_currency(self): - return get_obj('Sales Common').get_price_list_currency(self.doc.price_list_name, self.doc.company) # OTHER CHARGES TRIGGER FUNCTIONS diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js index 5d88c3034b..b9bff5c37a 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.js +++ b/erpnext/selling/doctype/sales_common/sales_common.js @@ -75,7 +75,6 @@ cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) { - // ============== Customer and its primary contact Details ============================ cur_frm.cscript.customer = function(doc, cdt, cdn) { if(doc.customer){ @@ -136,17 +135,11 @@ var set_dynamic_label_child = function(doc, cdt, cdn, base_curr) { // Change label dynamically based on currency //------------------------------------------------------------------ -cur_frm.cscript.dynamic_label = function(doc, cdt, cdn) { - var callback = function(r, rt) { - if (r.message) base_curr = r.message; - else base_curr = sys_defaults['currency']; +cur_frm.cscript.dynamic_label = function(doc, cdt, cdn, base_curr, callback) { + set_dynamic_label_par(doc, cdt, cdn, base_curr); + set_dynamic_label_child(doc, cdt, cdn, base_curr); - set_dynamic_label_par(doc, cdt, cdn, base_curr); - set_dynamic_label_child(doc, cdt, cdn, base_curr); - } - - if (doc.company == sys_defaults['company']) callback('', ''); - else $c_obj(make_doclist(doc.doctype, doc.name), 'get_comp_base_currency', '', callback); + if (callback) callback(doc, cdt, cdn); } @@ -155,27 +148,30 @@ cur_frm.cscript.dynamic_label = function(doc, cdt, cdn) { cur_frm.cscript.hide_price_list_currency = function(doc, cdt, cdn, callback1) { if (doc.price_list_name && doc.currency) { - var callback = function(r, rt) { - pl_currency = r.message[0]?r.message[0]:[]; - if (pl_currency.length==1) { - if (pl_currency[0] == doc.currency) set_multiple(cdt, cdn, {price_list_currency:doc.currency, plc_conversion_rate:doc.conversion_rate}); - else if (pl_currency[0] = r.message[1]) set_multiple(cdt, cdn, {price_list_currency:pl_currency[0], plc_conversion_rate:1}) - hide_field(['price_list_currency', 'plc_conversion_rate']); - } else unhide_field(['price_list_currency', 'plc_conversion_rate']); + wn.call({ + method: 'selling.doctype.sales_common.sales_common.get_price_list_currency', + args: {'price_list':doc.price_list_name, 'company': doc.company}, + callback: function(r, rt) { + pl_currency = r.message[0]?r.message[0]:[]; + if (pl_currency.length==1) { + if (pl_currency[0] == doc.currency) set_multiple(cdt, cdn, {price_list_currency:doc.currency, plc_conversion_rate:doc.conversion_rate}); + else if (pl_currency[0] = r.message[1]) set_multiple(cdt, cdn, {price_list_currency:pl_currency[0], plc_conversion_rate:1}) + hide_field(['price_list_currency', 'plc_conversion_rate']); + } else unhide_field(['price_list_currency', 'plc_conversion_rate']); - if (r.message[1] == doc.currency) { - set_multiple(cdt, cdn, {conversion_rate:1}); - hide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); - } else unhide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); + if (r.message[1] == doc.currency) { + set_multiple(cdt, cdn, {conversion_rate:1}); + hide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); + } else unhide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); - if (r.message[1] == doc.price_list_currency) { - set_multiple(cdt, cdn, {plc_conversion_rate:1}); - hide_field('plc_conversion_rate'); - } else unhide_field('plc_conversion_rate'); - - callback1() - } - $c_obj(make_doclist(doc.doctype, doc.name), 'get_price_list_currency', '', callback); + if (r.message[1] == doc.price_list_currency) { + set_multiple(cdt, cdn, {plc_conversion_rate:1}); + hide_field('plc_conversion_rate'); + } else unhide_field('plc_conversion_rate'); + + cur_frm.cscript.dynamic_label(doc, cdt, cdn, r.message[1], callback1); + } + }) } } @@ -213,12 +209,15 @@ cur_frm.cscript.conversion_rate = cur_frm.cscript.currency; cur_frm.cscript.plc_conversion_rate = cur_frm.cscript.currency; cur_frm.cscript.company = function(doc, dt, dn) { - var callback = function(r, rt) { - var doc = locals[dt][dn]; - set_multiple(doc.doctype, doc.name, {currency:r.message,price_list_currency:r.message}); - cur_frm.cscript.currency(doc, cdt, cdn); - } - $c_obj(make_doclist(doc.doctype, doc.name), 'get_comp_base_currency', '', callback); + wn.call({ + method: 'selling.doctype.sales_common.sales_common.get_comp_base_currency', + args: {company:doc.company}, + callback: function(r, rt) { + var doc = locals[dt][dn]; + set_multiple(doc.doctype, doc.name, {currency:r.message, price_list_currency:r.message}); + cur_frm.cscript.currency(doc, cdt, cdn); + } + }); } @@ -234,7 +233,6 @@ cur_frm.cscript.price_list_name = function(doc, cdt, cdn) { refresh_field(fname); var doc = locals[cdt][cdn]; cur_frm.cscript.recalc(doc,3); //this is to re-calculate BASIC RATE and AMOUNT on basis of changed REF RATE - cur_frm.cscript.dynamic_label(doc, cdt, cdn); } ); } diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py index 003c3bd7f3..a5017c2ef0 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.py +++ b/erpnext/selling/doctype/sales_common/sales_common.py @@ -178,18 +178,6 @@ class DocType(TransactionBase): d.export_amount = flt(d.qty)*flt(base_ref_rate)/flt(obj.doc.conversion_rate) - 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] - - def get_price_list_currency(self, price_list, comp): - """ Get all currency in which price list is maintained""" - plc = webnotes.conn.sql("select distinct ref_currency from `tabRef Rate Detail` where price_list_name = %s", price_list) - plc = [d[0] for d in plc] - base_currency = self.get_comp_base_currency(comp) - return plc, base_currency - - # Load Default Taxes # ==================== def load_default_taxes(self, obj): @@ -781,3 +769,17 @@ class StatusUpdater: where name="%(name)s" """ % args) + + +@webnotes.whitelist() +def get_comp_base_currency(arg=None): + """ get default currency of company""" + return webnotes.conn.sql("select default_currency from `tabCompany` where name = %s", webnotes.form_dict['company'])[0][0] + +@webnotes.whitelist() +def get_price_list_currency(arg=None): + """ Get all currency in which price list is maintained""" + plc = webnotes.conn.sql("select distinct ref_currency from `tabRef Rate Detail` where price_list_name = %s", webnotes.form_dict['price_list']) + plc = [d[0] for d in plc] + base_currency = get_comp_base_currency(webnotes.form_dict['company']) + return plc, base_currency diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 4a724d2add..a04423dd25 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -41,10 +41,15 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { - if(doc.__islocal) { - // defined in sales_common.js - cur_frm.cscript.update_item_details(doc, cdt, cdn); + var callback = function(doc, cdt, cdn) { + if(doc.__islocal) { + // defined in sales_common.js + cur_frm.cscript.update_item_details(doc, cdt, cdn); + } } + + cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn, callback); + } @@ -52,10 +57,8 @@ cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { //================== cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.clear_custom_buttons(); - var callback = function() { - cur_frm.cscript.dynamic_label(doc, cdt, cdn); - } - cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn, callback); + + if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn); if(doc.docstatus==1) { diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 943a1fd8e0..c886ec38b6 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -102,14 +102,16 @@ class DocType(TransactionBase): # Get Item Details # ---------------- def get_item_details(self, args=None): - args = eval(args) - if args['item_code']: + args = args and eval(args) or {} + if args.get('item_code'): return get_obj('Sales Common').get_item_details(args, self) else: obj = get_obj('Sales Common') for doc in self.doclist: if doc.fields.get('item_code'): - ret = obj.get_item_details(doc.item_code, self) + arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), + 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; + ret = obj.get_item_details(arg, self) for r in ret: if not doc.fields.get(r): doc.fields[r] = ret[r] @@ -120,13 +122,6 @@ class DocType(TransactionBase): def get_adj_percent(self, arg=''): get_obj('Sales Common').get_adj_percent(self) - def get_comp_base_currency(self): - return get_obj('Sales Common').get_comp_base_currency(self.doc.company) - - def get_price_list_currency(self): - return get_obj('Sales Common').get_price_list_currency(self.doc.price_list_name, self.doc.company) - - # Get projected qty of item based on warehouse selected diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index 3a8931e1e7..b0569fcaaf 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -43,17 +43,19 @@ cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.onload_post_render = function(doc, dt, dn) { // defined in sales_common.js - if(doc.__islocal) cur_frm.cscript.update_item_details(doc, dt, dn); + var callback = function(doc, dt, dn) { + if(doc.__islocal) cur_frm.cscript.update_item_details(doc, dt, dn); + } + + cur_frm.cscript.hide_price_list_currency(doc, dt, dn, callback); } // REFRESH // ================================================================================================ cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.clear_custom_buttons(); - var callback = function() { - cur_frm.cscript.dynamic_label(doc, cdt, cdn); - } - cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn, callback); + + if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn); if(doc.per_billed < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']); diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index a94531b555..0bca9d0e9e 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -117,14 +117,16 @@ class DocType(TransactionBase): # ***************** Get Item Details ****************************** def get_item_details(self, args=None): - args = eval(args) - if args['item_code']: + args = args and eval(args) or {} + if args.get('item_code'): return get_obj('Sales Common').get_item_details(args, self) else: obj = get_obj('Sales Common') for doc in self.doclist: if doc.fields.get('item_code'): - ret = obj.get_item_details(doc.item_code, self) + arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'), + 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')}; + ret = obj.get_item_details(arg, self) for r in ret: if not doc.fields.get(r): doc.fields[r] = ret[r] @@ -135,13 +137,6 @@ class DocType(TransactionBase): get_obj('Sales Common').get_adj_percent(self) - def get_comp_base_currency(self): - return get_obj('Sales Common').get_comp_base_currency(self.doc.company) - - def get_price_list_currency(self): - return get_obj('Sales Common').get_price_list_currency(self.doc.price_list_name, self.doc.company) - - # ********** Get Actual Qty of item in warehouse selected ************* def get_actual_qty(self,args): args = eval(args) diff --git a/version.num b/version.num index 3879e48b52..5d1d1b123b 100644 --- a/version.num +++ b/version.num @@ -1 +1 @@ -753 \ No newline at end of file +755 \ No newline at end of file