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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
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 .
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
0
cze 23
|
2028 | ||
|
1
gru 22
|
3339 | ||
|
0
kwi 22
|
2554 | ||
|
1
kwi 19
|
6204 | ||
|
2
lip 25
|
3819 |
Its old code, but, see whether it helps: https://apps.odoo.com/apps/modules/9.0/merge_same_products/
Thank you.