From 705881328f2bc284003c3689b9460cf6cc65433c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Tue, 11 Mar 2025 22:23:29 +0100 Subject: [PATCH] [IMP] sale_order_batch: fix multi deletion issue --- sale_order_batch/models/sale_order.py | 1 - sale_order_batch/models/sale_order_line.py | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/sale_order_batch/models/sale_order.py b/sale_order_batch/models/sale_order.py index 51b6235..130ddfe 100644 --- a/sale_order_batch/models/sale_order.py +++ b/sale_order_batch/models/sale_order.py @@ -42,7 +42,6 @@ class SaleOrder(models.Model): raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}")) return super().action_confirm() - # TODO: Unlink batch_product when no so lines anymore def write(self, vals): res = super().write(vals) if "batch_id" in vals.keys(): diff --git a/sale_order_batch/models/sale_order_line.py b/sale_order_batch/models/sale_order_line.py index fdd0dae..bad34d6 100644 --- a/sale_order_batch/models/sale_order_line.py +++ b/sale_order_batch/models/sale_order_line.py @@ -22,15 +22,9 @@ class SaleOrderLine(models.Model): def _unlink_batch_product(self): lines_to_unlink = self.filtered(lambda l: l.batch_product_id) - batch_product_unlink = self.env["sale.order.batch.product"] - for line in lines_to_unlink: - if line.batch_product_id: - 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() + batch_products = lines_to_unlink.mapped("batch_product_id") + lines_to_unlink.update({"batch_product_id": False}) + batch_products.filtered(lambda p: len(p.sale_order_line_ids) == 0).unlink() def _update_batch_product(self): lines_with_batch = self.filtered(lambda l: l.batch_id)