[FIX] mrp: do not confirm empty production with MTO rule

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) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-07-29 17:13:02 +02:00
parent d16ff3aa7c
commit 2ab878aecb
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -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
+2 -2
View File
@@ -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',