Odoo Help


get product category id in product_id_change

mohamed abdelwahed
on 5/23/13, 12:06 PM 3,197 views

hello everybody i want to get the product category_id from the product_id_change() from sale.order.line :)

Hi, I have done it, but it gave some strange results, well the first thing I did was: In a re-defintion of product_id_change I wrote these lines ...sale_line_id = self.search(cr,uid,[],context=context) and then: for line in self.browse(cr, uid, sale_line_id, context=context): category_id = line.product_id and line.product_id.categ_id.id and then it returns a product_id and categ_id which is not in the quatation I'm working on....it's supossed that product_id_change works on the product im choosing to add in my saleorderso,so ...

MEXYTUL, Diego Calzadilla
on 8/13/13, 10:40 PM

why does it go and brings the category of the last product of my firts confirmed quatotion?? does any of you guys have any idea?. Thanks!

MEXYTUL, Diego Calzadilla
on 8/13/13, 10:42 PM


| 4 4 8
Ahmedabad, India

Odoo Expert

On 5/23/13, 12:29 PM

You can simply get category_id in sale.order.line by using browse method of sale_order_line in product_id_change method. Just need to pass sale_order_line id in it.

order_line_brw = self.pool.get('sale.order.line').browse(cr, uid, ids, context=context)


order_line_brw = self.browse(cr, uid, ids, context=context)


category_id = order_line_brw.product_id and order_line_brw.product_id.categ_id

This will give you browse record of category if you want category_id then just need to add .id at the end

Like this

category_id = order_line_brw.product_id and order_line_brw.product_id.categ_id.id

sorry but i get this error category_id = order_line_brw.product_id and order_line_brw.product_id.categ_id.id AttributeError: 'browse_record_list' object has no attribute 'product_id'

mohamed abdelwahed
on 5/23/13, 1:26 PM

It is because of ids is in list. Try to write it in for loop for example, for order_line_brw in self.browse(cr, uid, ids, context=context): or you can write ids[0] instead of ids. That will solve your problem.

on 5/26/13, 2:33 AM

Hi, I'm having the same problem, has any of you been able to solve it?. When I try the for loop, nothing happens, The debugger says: Nameerror: name order_line_brw is not defined. And if I write ids[0] wheter in order_line_brw = self.browse(cr, uid, ids, context=context or in the for loop instead of ids, I get the following error: for order_line_brw in self.browse(cr, uid, ids[0], context=context): IndexError: list index out of range

MEXYTUL, Diego Calzadilla
on 8/13/13, 5:52 PM

Thanks in advance for suggestions!!

MEXYTUL, Diego Calzadilla
on 8/13/13, 5:52 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 5/23/13, 12:06 PM
Seen: 3197 times
Last updated: 3/16/15, 8:10 AM