Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
10333 Vistas

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

Avatar
Descartar

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

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!

Mejor respuesta

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
Avatar
Descartar
Autor

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'

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.

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

Thanks in advance for suggestions!!

Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 24
22031
0
sept 24
1466
3
ago 24
2846
0
feb 24
1973
0
feb 24
1472