0

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

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
4

1 回答 1

1

您收到此错误是因为price_list_name不返回任何值,请添加if条件以避免错误。

if price_list_name:
        name = price_list_name[0][0]
        price_doc = frappe.get_doc("Item Price",name)
于 2020-01-01T05:29:30.870 回答