IndexError:元组索引超出范围(Frappe / Erpnext)

时间:2019-04-16 17:41:41

标签: python-3.x erpnext frappe

我正在尝试修改下面的代码,但出现“元组索引超出范围”错误。

price_list_name = frappe.db.sql("""select name
                from `tabItem Price` a 
                where a.item_code = %s and a.selling = 1 
                and a.uom = %s
                and a.creation = (select max(b.creation) from `tabItem Price` b 
                where a.item_code = b.item_code and b.selling = 1)""",(d.item_code, d.uom))
        frappe.log(price_list_name)
        name = price_list_name[0][0]
        price_doc = frappe.get_doc("Item Price",name)

这是错误消息:

File "/home/frappe/erpnext/apps/xlevel_sales/xlevel_sales/custom_method.py", line 27, in update_item_price_list
name = price_list_name[0][0]
IndexError: tuple index out of range

1 个答案:

答案 0 :(得分:0)

由于price_list_name不返回任何值,因此出现此错误,请添加if条件以避免该错误。

if price_list_name:
        name = price_list_name[0][0]
        price_doc = frappe.get_doc("Item Price",name)