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

问题描述 投票:0回答:1

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

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
python-3.x erpnext frappe
1个回答
0
投票

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

if price_list_name:
        name = price_list_name[0][0]
        price_doc = frappe.get_doc("Item Price",name)
© www.soinside.com 2019 - 2024. All rights reserved.