From 58e89044f1b0a611eb5c0c4c5f0f4ddd22c693ca Mon Sep 17 00:00:00 2001 From: Guillaume MASSON Date: Wed, 16 Oct 2024 13:16:05 +0200 Subject: [PATCH 1/2] [ADD] sale_order_line_date : add test for commitment date removal on sale order line --- .../tests/test_sale_order_line_date.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sale_order_line_date/tests/test_sale_order_line_date.py b/sale_order_line_date/tests/test_sale_order_line_date.py index 55a36271f3e..d13bd1effd1 100644 --- a/sale_order_line_date/tests/test_sale_order_line_date.py +++ b/sale_order_line_date/tests/test_sale_order_line_date.py @@ -166,3 +166,14 @@ def test_03_line_commitment_date_picking_propagation(self): self._assert_equal_dates( self.sale_line1.commitment_date, self.sale_line1.move_ids.date_deadline ) + + def test_04_line_commitment_date_removal(self): + self.sale1.commitment_date = False + self.sale1.action_confirm() + self._assert_equal_dates( + self.sale_line1.commitment_date, self.sale_line1.move_ids.date_deadline + ) + self.sale_line1.commitment_date = False + self._assert_equal_dates( + self.sale_line1._expected_date(), self.sale_line1.move_ids.date_deadline + ) From 0b5dd65e13dd4fae1418f06b78854d1559844a1e Mon Sep 17 00:00:00 2001 From: Guillaume MASSON Date: Wed, 16 Oct 2024 13:25:25 +0200 Subject: [PATCH 2/2] [FIX] sale_order_line_date : use default date to propagate if commitment date is removed on the sale order line --- .../models/sale_order_line.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sale_order_line_date/models/sale_order_line.py b/sale_order_line_date/models/sale_order_line.py index 2f715effc13..b3432286b4c 100644 --- a/sale_order_line_date/models/sale_order_line.py +++ b/sale_order_line_date/models/sale_order_line.py @@ -31,13 +31,17 @@ def _prepare_procurement_values(self, group_id=False): def write(self, vals): res = super().write(vals) - moves_to_upd = set() if "commitment_date" in vals: - for move in self.move_ids: - if move.state not in ["cancel", "done"]: - moves_to_upd.add(move.id) - if moves_to_upd: - self.env["stock.move"].browse(moves_to_upd).write( - {"date_deadline": vals.get("commitment_date")} - ) + if vals.get("commitment_date"): + self.move_ids.filtered( + lambda sm: sm.state not in ["cancel", "done"] + ).write({"date_deadline": vals.get("commitment_date")}) + else: + for line in self: + date_deadline = ( + line.order_id.commitment_date or line._expected_date() + ) + line.move_ids.filtered( + lambda sm: sm.state not in ["cancel", "done"] + ).write({"date_deadline": date_deadline}) return res