Přejít na obsah
Menu
You need to be registered to interact with the community.
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
Zrušit

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 Odpovědi Zobrazení Aktivita
0
pro 21
2447
2
pro 19
25171
2
říj 24
2682
2
led 24
5378
0
čvn 23
2002