跳至内容
菜单
此问题已终结
2 回复
5454 查看

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 .

相关帖文 回复 查看 活动
0
6月 23
2052
1
12月 22
3373
0
4月 22
2596
1
4月 19
6226
2
7月 25
3852