From 2281aace5ce8f0a6e05263c137f6fe2a26ac782a Mon Sep 17 00:00:00 2001 From: Tran Anh Tuan Date: Fri, 19 Apr 2024 11:10:42 +0700 Subject: [PATCH] [IMP] sale_auto_remove_zero_quantity_lines: Remove empty note in sale order --- .../models/sale_order.py | 13 +++++++------ ...est_sale_auto_remove_zero_quantity_lines.py | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sale_auto_remove_zero_quantity_lines/models/sale_order.py b/sale_auto_remove_zero_quantity_lines/models/sale_order.py index 1a6ea484e47..b48d31362c5 100644 --- a/sale_auto_remove_zero_quantity_lines/models/sale_order.py +++ b/sale_auto_remove_zero_quantity_lines/models/sale_order.py @@ -14,14 +14,15 @@ def _should_auto_remove_zero_quantity_lines(self): def action_confirm(self): for order in self: if order._should_auto_remove_zero_quantity_lines(): - zero_lines = order.order_line.filtered( - lambda line: line.product_id and line.product_uom_qty == 0 + zero_or_empty_lines = order.order_line.filtered( + lambda line: (line.product_id and line.product_uom_qty == 0) + or (line.display_type == "line_note" and not line.name.strip()) ) - if zero_lines: + if zero_or_empty_lines: body = _( - "Some sale order lines with zero quantities were removed upon " - "confirmation." + "Some lines with zero quantities or empty notes were " + "removed upon confirmation." ) order.message_post(body=body) - zero_lines.unlink() + zero_or_empty_lines.unlink() return super().action_confirm() diff --git a/sale_auto_remove_zero_quantity_lines/tests/test_sale_auto_remove_zero_quantity_lines.py b/sale_auto_remove_zero_quantity_lines/tests/test_sale_auto_remove_zero_quantity_lines.py index 1908272e011..3f6c29935be 100644 --- a/sale_auto_remove_zero_quantity_lines/tests/test_sale_auto_remove_zero_quantity_lines.py +++ b/sale_auto_remove_zero_quantity_lines/tests/test_sale_auto_remove_zero_quantity_lines.py @@ -50,9 +50,25 @@ def test_sale_auto_remove_zero_quantity_lines(self): "display_type": "line_note", }, ), + ( + 0, + 0, + { + "name": " ", + "display_type": "line_note", + }, + ), + ( + 0, + 0, + { + "name": " ", + "display_type": "line_section", + }, + ), ], "pricelist_id": self.env.ref("product.list0").id, } ) so.action_confirm() - self.assertEqual(len(so.order_line), 2) + self.assertEqual(len(so.order_line), 3)