Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ

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?
อวตาร
ละทิ้ง

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 ตอบกลับ มุมมอง กิจกรรม
0
ธ.ค. 21
2556
2
ธ.ค. 19
25306
2
ต.ค. 24
2972
Merge Same Item in Sale Order Line แก้ไขแล้ว
2
ม.ค. 24
5518
0
มิ.ย. 23
2094