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

get product category id in product_id_change

By
mohamed abdelwahed
on 5/23/13, 12:06 PM 2,160 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
1

Keyur

--Keyur--
1165
| 4 4 8
Ahmedabad, India
--Keyur--

Odoo Expert

Keyur
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)

or

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

Then

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.

Keyur
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

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

2 follower(s)

Stats

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