From df3f452a14fd03bcd87f827642dd9ad71198f5b7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 8 Feb 2012 16:22:59 +0530 Subject: [PATCH] Fix in Purchase Invoice creation due to item tax stringify issue --- .../doctype/payable_voucher/payable_voucher.js | 10 +++++++--- .../doctype/payable_voucher/payable_voucher.py | 6 ++++-- .../buying/doctype/purchase_common/purchase_common.js | 2 +- erpnext/selling/doctype/sales_common/sales_common.py | 6 ++++-- .../doctype/landed_cost_wizard/landed_cost_wizard.py | 7 ++++++- .../stock/doctype/purchase_receipt/purchase_receipt.js | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js index 44dea8a598..3bdeadddd8 100644 --- a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js +++ b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js @@ -61,12 +61,16 @@ cur_frm.cscript.supplier = function(doc,dt,dn) { } var callback2 = function(r,rt){ - var doc = locals[cur_frm.doctype][cur_frm.docname]; + var doc = locals[cur_frm.doctype][cur_frm.docname]; var el = getchildren('PV Detail',doc.name,'entries'); for(var i in el){ if(el[i].item_code && (!el[i].expense_head || !el[i].cost_center)){ - args = "{'item_code':'" + el[i].item_code + "','expense_head':'" + el[i].expense_head + "','cost_center':'" + el[i].cost_center + "'}"; - get_server_fields('get_default_values', args, 'entries', doc, el[i].doctype, el[i].name, 1); + args = { + item_code: el[i].item_code, + expense_head: el[i].expense_head, + cost_center: el[i].cost_center + }; + get_server_fields('get_default_values', JSON.stringify(args), 'entries', doc, el[i].doctype, el[i].name, 1); } } cur_frm.cscript.calc_amount(doc, 1); diff --git a/erpnext/accounts/doctype/payable_voucher/payable_voucher.py b/erpnext/accounts/doctype/payable_voucher/payable_voucher.py index e220756a81..14d5e5e863 100644 --- a/erpnext/accounts/doctype/payable_voucher/payable_voucher.py +++ b/erpnext/accounts/doctype/payable_voucher/payable_voucher.py @@ -61,7 +61,8 @@ class DocType(TransactionBase): # Get Default Cost Center and Expense Head from Item Master # ---------------------------------------------------------- def get_default_values(self,args): - args = eval(args) + import json + args = json.loads(args) ret = {} if sql("select name from `tabItem` where name = '%s'" % args['item_code']): if not args['expense_head'] or args['expense_head'] == 'undefined': @@ -105,6 +106,7 @@ class DocType(TransactionBase): def get_pv_details(self, arg): + import json item_det = sql("select item_name, brand, description, item_group,purchase_account,cost_center from tabItem where name=%s",arg,as_dict=1) tax = sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , arg) t = {} @@ -119,7 +121,7 @@ class DocType(TransactionBase): 'amount' : 0.00, 'expense_head' : item_det and item_det[0]['purchase_account'] or '', 'cost_center' : item_det and item_det[0]['cost_center'] or '', - 'item_tax_rate' : str(t) + 'item_tax_rate' : json.dumps(t) } return ret diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 541a225e36..d7d88bbbc2 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -34,7 +34,7 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn) { // Update existing item details cur_frm.cscript.update_item_details = function(doc, dt, dn) { - if(!cur_frm.doc.__islocal) return; + if(!cur_frm.doc.__islocal) { return; } var children = getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname); if(children) { $c_obj(make_doclist(doc.doctype, doc.name), 'get_item_details', '', diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py index 1420ad6664..2498381d06 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.py +++ b/erpnext/selling/doctype/sales_common/sales_common.py @@ -197,17 +197,19 @@ class DocType(TransactionBase): #---------------------------------------- Get Tax Details -------------------------------# def get_tax_details(self, item_code, obj): + import json tax = webnotes.conn.sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , item_code) t = {} for x in tax: t[x[0]] = flt(x[1]) ret = { - 'item_tax_rate' : tax and str(t) or '' + 'item_tax_rate' : tax and json.dumps(t) or '' } return ret # Get Serial No Details # ========================================================================== def get_serial_details(self, serial_no, obj): + import json item = webnotes.conn.sql("select item_code, make, label,brand, description from `tabSerial No` where name = '%s' and docstatus != 2" %(serial_no), as_dict=1) tax = webnotes.conn.sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , item[0]['item_code']) t = {} @@ -218,7 +220,7 @@ class DocType(TransactionBase): 'label' : item and item[0]['label'] or '', 'brand' : item and item[0]['brand'] or '', 'description' : item and item[0]['description'] or '', - 'item_tax_rate' : str(t) + 'item_tax_rate' : json.dumps(t) } return ret diff --git a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py index c791e865ed..ea63d049a5 100644 --- a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py +++ b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py @@ -112,6 +112,7 @@ class DocType: def cal_charges_and_item_tax_amt(self): """ Re-calculates other charges values and itemwise tax amount for getting valuation rate""" + import json for pr in self.selected_pr: obj = get_obj('Purchase Receipt', pr, with_children = 1) total = 0 @@ -121,7 +122,11 @@ class DocType: prev_total, item_tax = flt(prd.amount), 0 total += flt(prd.qty) * flt(prd.purchase_rate) - item_tax_rate = prd.item_tax_rate and eval(prd.item_tax_rate) or {} + try: + item_tax_rate = prd.item_tax_rate and json.loads(prd.item_tax_rate) or {} + except ValueError: + item_tax_rate = prd.item_tax_rate and eval(prd.item_tax_rate) or {} + ocd = getlist(obj.doclist, 'purchase_tax_details') # calculate tax for other charges diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index 5d4310facc..db5215a6fe 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -241,7 +241,7 @@ cur_frm.cscript['Make Purchase Invoice'] = function() { 'from_docname': cur_frm.doc.name, 'from_to_list':"[['Purchase Receipt','Payable Voucher'],['Purchase Receipt Detail','PV Detail'],['Purchase Tax Detail','Purchase Tax Detail']]" }, function(r,rt) { - loaddoc('Payable Voucher', n); + loaddoc('Payable Voucher', n); } ); }