From 2ab878aecb67930a9a7cd35901cb6c4b98c7e442 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Tue, 12 Jul 2022 12:32:16 +0000 Subject: [PATCH] [FIX] mrp: do not confirm empty production with MTO rule 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”: - routes: - MTO - Manufacturing - Create a SO: - Select the product “P1” - Confirm the SO Problem: The created MO is in confirmed state instead of draft. This blocks the user, for example imagine that he has configured the product with a first BOM without components and 2 others with components. when the MO is created, the first bom will be selected, and as the MO will be confirmed, the user will not be able to select another BOM Solution: Since the MTO rule is not linked to an order point, we could be more flexible, so the production created via `_run_manufacture()` without bom or with a bom without component and operation via the MTO mechanism will not be confirmed opw-2897267 closes odoo/odoo#97099 X-original-commit: c623478aba040c0493e6da8a67c9742880572199 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/stock_rule.py | 3 ++- addons/mrp/tests/test_procurement.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index c488ebe54d2..4fb810809cc 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -51,7 +51,8 @@ class StockRule(models.Model): for company_id, productions_values in productions_values_by_company.items(): # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(productions_values) - productions.filtered(lambda p: not p.orderpoint_id or not p.move_raw_ids).action_confirm() + productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or\ + (p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm() for production in productions: origin_production = production.move_dest_ids and production.move_dest_ids[0].raw_material_production_id or False diff --git a/addons/mrp/tests/test_procurement.py b/addons/mrp/tests/test_procurement.py index e37580d67d9..98449ac845a 100644 --- a/addons/mrp/tests/test_procurement.py +++ b/addons/mrp/tests/test_procurement.py @@ -298,7 +298,7 @@ class TestProcurement(TestMrpCommon): def test_procurement_with_empty_bom(self): """Ensure that a procurement request using a product with an empty BoM - will create an empty MO in confirmed state that can be completed afterwards. + will create an empty MO in draft state that can be completed afterwards. """ self.warehouse = self.env.ref('stock.warehouse0') route_manufacture = self.warehouse.manufacture_pull_id.route_id.id @@ -328,7 +328,7 @@ class TestProcurement(TestMrpCommon): production = self.env['mrp.production'].search([('product_id', '=', product.id)]) self.assertTrue(production) self.assertFalse(production.move_raw_ids) - self.assertEqual(production.state, 'confirmed') + self.assertEqual(production.state, 'draft') comp1 = self.env['product.product'].create({ 'name': 'egg',