Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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?
Awatar
Odrzuć

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

Powiązane posty Odpowiedzi Widoki Czynność
0
gru 21
2433
2
gru 19
25157
2
paź 24
2655
2
sty 24
5368
0
cze 23
1982