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

When I try to add same product multiple time in sale order line, how can I merge all of them in a same sale order line by increasing the quantity only?

อวตาร
ละทิ้ง
ผู้เขียน

Thank you.

คำตอบที่ดีที่สุด

Try with this code.

---------------------------------------------------------

def merge_duplicate_product_lines(self, res):
for line in res.order_line:
if line.id in res.order_line.ids:
line_ids = res.order_line.filtered(lambda m: m.product_id.id == line.product_id.id)
quantity = 0
for qty in line_ids:
quantity += qty.product_uom_qty
line_ids[0].write({'product_uom_qty': quantity,
'order_id': line_ids[0].order_id.id})
line_ids[1:].unlink()

@api.model
def create(self, vals):
res = super(SaleOrder, self).create(vals)
res.merge_duplicate_product_lines(res)

return res

def write(self, vals):
res = super(SaleOrder, self).write(vals)
self.merge_duplicate_product_lines(self)
return res

อวตาร
ละทิ้ง
ผู้เขียน

Thank you brother . it's working .

คำตอบที่ดีที่สุด

You can use this module https://apps.odoo.com/apps/modules/17.0/merge_so_line/

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มิ.ย. 23
2260
1
ธ.ค. 22
3618
0
เม.ย. 22
2790
1
เม.ย. 19
6410
2
ก.ค. 25
4172