Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

IndexError: tuple index out of range in an Onchange Function

By
Odoo
on 4/30/15, 12:15 AM 1,504 views

when I try to run below code i got this error 


==================================================

File "/home/user/odoo/addons/sale_validation/sale.py", line 708, in on_change_line_product

first_line_rec = self.browse(cr, uid, ids, context=context)[0]

File "/home/user/odoo/openerp/models.py", line 5476, in __getitem__

return self._browse(self.env, (self._ids[key],))

IndexError: tuple index out of range

=================================

class purchase_order_line(osv.osv):

_inherit = 'purchase.order.line'

def on_change_line_product(self, cr, uid, ids,product_qty,context=None):

if context is None: context = {}

res = {}

line_num = 1

first_line_rec = self.browse(cr, uid, ids, context=context)[0]

for line_rec in first_line_rec.order_id.order_line:

res[line_rec.id] = line_num

line_num += 1

return res

_columns={

'line_no': fields.integer(string='Line Number'),

}


xml tag---------------

<field name="line_no" on_change="on_change_line_product(product_qty,context)"/>

0

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 4/30/15, 2:53 AM

Hi,

surround your code with this if statement. Use like this:-

if ids:
first_line_rec = self.browse(cr, uid, ids, context=context)[0]

You are getting this error when ids is empty and you are indexing that empty ids with [0].

Try with above code...

Hope this helps...........


0
Bipin rathod
On 4/30/15, 2:46 AM

Hello Dep,

Please remove the [0] index from this line.

first_line_rec = self.browse(cr, uid, ids, context=context)[0]

This will not giving you an error, but I didn't get you,what are you trying to do. because of there is no logic to write on change method on line number.

Hope you clear first what you want to do. 

Above line will resolve you issue. 


0
vadivel
On 4/30/15, 12:57 AM

Hi Dep, You can below code: first_line_rec = self.browse(cr, uid, ids[0], context=context) for line_rec in first_line_rec.order_id.order_line: res[line_rec.id] = line_num line_num += 1 return res

Hi vadivel , I got same Error....

Odoo
on 4/30/15, 1:22 AM

/sale.py", line 708, in on_change_line_product first_line_rec = self.browse(cr, uid, ids[0], context=context) IndexError: list index out of range

Odoo
on 4/30/15, 1:23 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/30/15, 12:15 AM
Seen: 1504 times
Last updated: 4/30/15, 2:53 AM