0

I am trying to modify code below but I am getting a "tuple index out of range" error.

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)

This is the error message:

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
BoltKey
  • 1,994
  • 1
  • 14
  • 26
EnSeal
  • 11
  • First check what is the value you are getting in `price_list_name`. The error is due to `price_list_name[0][0]`. So, you are probably not getting any value in it for that condition. – Sumit S Chawla Apr 16 '19 at 17:58

1 Answers1

1

You are getting this error because price_list_name does not return any value, add if condition to avoid the error.

if price_list_name:
        name = price_list_name[0][0]
        price_doc = frappe.get_doc("Item Price",name)
Nabin Hait
  • 21
  • 2