From 21ee079741e435d4b06681c8bdd69af2d2e00318 Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Mon, 18 Sep 2023 13:03:12 +0200 Subject: [PATCH] [FIX] repair, sale_*: set cost in SO when creating SO from repair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1” - cost= $100 - Create a repair order: - select any product in the product to repair - add “P1” as component - create the quotation from the repair order Problem: The cost is not computed correctly and is set at 0 in the `sale.order.line` opw-3502317 closes odoo/odoo#135822 X-original-commit: b95ed3617f465a655c8f918bee8edc673c8f202b Signed-off-by: William Henrotin (whe) --- addons/repair/models/sale_order.py | 4 ++++ addons/repair/tests/test_repair.py | 20 +++++++++++++++++++ addons/sale/models/sale_order_line.py | 3 +++ .../models/sale_order_line.py | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/repair/models/sale_order.py b/addons/repair/models/sale_order.py index 5ac8d62c7ae..89324bbfa45 100644 --- a/addons/repair/models/sale_order.py +++ b/addons/repair/models/sale_order.py @@ -110,3 +110,7 @@ class SaleOrderLine(models.Model): for line in self: binded_ro_ids |= line.order_id.sudo().repair_order_ids.filtered(lambda ro: ro.sale_order_line_id.id == line.id and ro.state != 'done') binded_ro_ids.action_repair_cancel() + + def has_valued_move_ids(self): + res = super().has_valued_move_ids() + return res and not self.move_ids.repair_id diff --git a/addons/repair/tests/test_repair.py b/addons/repair/tests/test_repair.py index 6416dd943bc..130c71adb58 100644 --- a/addons/repair/tests/test_repair.py +++ b/addons/repair/tests/test_repair.py @@ -473,3 +473,23 @@ class TestRepair(common.TransactionCase): ], limit=1) self.assertEqual(repair.move_ids[0].location_dest_id, location_dest_id) + def test_purchase_price_so_create_from_repair(self): + """ + Test that the purchase price is correctly set on the SO line, + when creating a SO from a repair order. + """ + self.product_product_11.standard_price = 10 + repair = self.env['repair.order'].create({ + 'partner_id': self.res_partner_1.id, + 'product_id': self.product_product_3.id, + 'picking_type_id': self.stock_warehouse.repair_type_id.id, + 'move_ids': [ + (0, 0, { + 'repair_line_type': 'add', + 'product_id': self.product_product_11.id, + }) + ], + }) + repair.action_create_sale_order() + self.assertEqual(repair.sale_order_id.order_line.product_id, self.product_product_11) + self.assertEqual(repair.sale_order_id.order_line.purchase_price, 10) diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 7395c38e37f..85e8ac1003e 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -1274,3 +1274,6 @@ class SaleOrderLine(models.Model): round=False, ) return amount + + def has_valued_move_ids(self): + return self.move_ids diff --git a/addons/sale_stock_margin/models/sale_order_line.py b/addons/sale_stock_margin/models/sale_order_line.py index ac57411115a..f31f9ea209e 100644 --- a/addons/sale_stock_margin/models/sale_order_line.py +++ b/addons/sale_stock_margin/models/sale_order_line.py @@ -12,7 +12,7 @@ class SaleOrderLine(models.Model): lines_without_moves = self.browse() for line in self: product = line.product_id.with_company(line.company_id) - if not line.move_ids: + if not line.has_valued_move_ids(): lines_without_moves |= line elif product and product.categ_id.property_cost_method != 'standard': purch_price = product._compute_average_price(0, line.product_uom_qty, line.move_ids)