Skip to Content
Menú
This question has been flagged

I have a class "pack.products" that contains products linked to another product.

In the sale order, I need to write to order lines the list of pack products when I select that product.

So what I did:

class SaleOrderLine(models.Model):

_inherit = 'sale.order.line'

@api.onchange('product_id')
def _onchange_product_id(self):
product = self.product_id
if product.is_pack:
pack_products = self.env['pack.product'].search([('pack_product_id','=',product.id)])
line_ids = []
for line in pack_products:
line_ids.append((0, 0, {
'name': line.product_id.name,
'price_unit':1,
'customer_lead':1,
'state':'draft',
'qty_delivered':1,
'product_id': line.product_id.id,
'product_uom_qty': line.quantity,
}))
print(line_ids)
self.order_id.update({'order_line': line_ids})


When I print line_ids, I can see the pack products, but nothing shows on the sale order.
Is it because it's not saved yet?
Avatar
Descartar

Did you solve this ? I have something similar with linked sale order lines actually, and as soon as I change some value for one line I need to add more connected to it and I have problems as that line it's not saved yet ...

I need to figure it out how to first save the edited line before, in order to get the real ID that I connect the new added line from code

Related Posts Respostes Vistes Activitat
0
de des. 21
2438
2
de des. 19
25166
2
d’oct. 24
2665
2
de gen. 24
5372
0
de juny 23
1989