From 66b4e080e29551d1c74cdc4b3d9ccba92ce81dd1 Mon Sep 17 00:00:00 2001 From: OmarAbosamaha Date: Fri, 29 Dec 2023 16:34:04 +0200 Subject: [PATCH] [FIX] repair: prevent uom comparison for non products Issue: When updating section line or note in a confirmed SO, the system tried to compare uom of them causing an error Steps to reproduce: 1- Install sale and repair apps 2- Create a sale order with adding a product and a section line 3- Confirm sale order 4- Modify section line 5- Save Solution: We need to check if the order line is a product before performing the uom comparison opw-3644939 closes odoo/odoo#148900 X-original-commit: e3cd490ab0e62865b5ad7516643a22c6ba3a3371 Signed-off-by: Adrien Widart (awt) Signed-off-by: Omar Abosamaha (abom) --- addons/repair/models/sale_order.py | 2 +- addons/repair/tests/test_repair.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/repair/models/sale_order.py b/addons/repair/models/sale_order.py index 4bf88693c73..274b2d934ab 100644 --- a/addons/repair/models/sale_order.py +++ b/addons/repair/models/sale_order.py @@ -70,7 +70,7 @@ class SaleOrderLine(models.Model): old_product_uom_qty = {line.id: line.product_uom_qty for line in self} res = super().write(vals_list) for line in self: - if line.state in ('sale', 'done'): + if line.state in ('sale', 'done') and line.product_id: if float_compare(old_product_uom_qty[line.id], 0, precision_rounding=line.product_uom.rounding) <= 0 and float_compare(line.product_uom_qty, 0, precision_rounding=line.product_uom.rounding) > 0: self._create_repair_order() if float_compare(old_product_uom_qty[line.id], 0, precision_rounding=line.product_uom.rounding) > 0 and float_compare(line.product_uom_qty, 0, precision_rounding=line.product_uom.rounding) <= 0: diff --git a/addons/repair/tests/test_repair.py b/addons/repair/tests/test_repair.py index 9001fa3d417..0699b5825b6 100644 --- a/addons/repair/tests/test_repair.py +++ b/addons/repair/tests/test_repair.py @@ -336,8 +336,12 @@ class TestRepair(common.TransactionCase): with so_form.order_line.new() as line: line.product_id = self.product_consu_order_repair line.product_uom_qty = 2.0 + with so_form.order_line.new() as line: + line.display_type = 'line_section' + line.name = 'Dummy Section' sale_order = so_form.save() order_line = sale_order.order_line[0] + line_section = sale_order.order_line[1] self.assertEqual(len(sale_order.repair_order_ids), 0) sale_order.action_confirm() # Quantity set on the "create repair" product doesn't affect the number of RO created @@ -348,6 +352,7 @@ class TestRepair(common.TransactionCase): order_line.product_uom_qty = 0 self.assertEqual(repair_order.state, 'cancel') order_line.product_uom_qty = 1 + line_section.name = 'updated section' self.assertEqual(repair_order.state, 'confirmed') repair_order.action_repair_cancel() self.assertTrue(float_is_zero(order_line.product_uom_qty, 2))