[IMP] sale_order_batch: fix multi deletion issue

This commit is contained in:
Niels Göttsch 2025-03-11 22:23:29 +01:00 committed by madmooose
parent cade3b897a
commit 705881328f
2 changed files with 3 additions and 10 deletions

View file

@ -42,7 +42,6 @@ class SaleOrder(models.Model):
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}")) raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
return super().action_confirm() return super().action_confirm()
# TODO: Unlink batch_product when no so lines anymore
def write(self, vals): def write(self, vals):
res = super().write(vals) res = super().write(vals)
if "batch_id" in vals.keys(): if "batch_id" in vals.keys():

View file

@ -22,15 +22,9 @@ class SaleOrderLine(models.Model):
def _unlink_batch_product(self): def _unlink_batch_product(self):
lines_to_unlink = self.filtered(lambda l: l.batch_product_id) lines_to_unlink = self.filtered(lambda l: l.batch_product_id)
batch_product_unlink = self.env["sale.order.batch.product"] batch_products = lines_to_unlink.mapped("batch_product_id")
for line in lines_to_unlink: lines_to_unlink.update({"batch_product_id": False})
if line.batch_product_id: batch_products.filtered(lambda p: len(p.sale_order_line_ids) == 0).unlink()
batch_product = line.batch_product_id
if len(batch_product.sale_order_line_ids) == 1:
batch_product_unlink += batch_product
else:
line.batch_product_id = False
batch_product_unlink.unlink()
def _update_batch_product(self): def _update_batch_product(self):
lines_with_batch = self.filtered(lambda l: l.batch_id) lines_with_batch = self.filtered(lambda l: l.batch_id)