From 57ce14265380365033cf9cd3f5e38b2bbf228fc4 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Mon, 17 Feb 2020 15:15:45 +0000 Subject: [PATCH] [FIX] mrp: adjust procure method for additional moves Commit c883ed108759dfff7f0373da535c557a09c0f30d let the possibility to add additional stock moves in a confirmed production. The issue is those move don't get the production group and their procure method is set (and never changed) to make_to_stock. This commit call adjust_procure_method before confirming additional moves. closes odoo/odoo#45660 X-original-commit: 96cc10fa79a120172b3cde88d50ba2fda5e75ab5 Signed-off-by: William Henrotin --- addons/mrp/models/mrp_production.py | 11 ++++++- .../test_warehouse_multistep_manufacturing.py | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 73942bc46ca..da6106f5529 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -739,7 +739,16 @@ class MrpProduction(models.Model): for production in self: if production.state in ('done', 'cancel'): continue - moves_to_confirm |= (production.move_raw_ids | production.move_finished_ids).filtered( + additional_moves = production.move_raw_ids.filtered( + lambda move: move.state == 'draft' and move.additional + ) + additional_moves.write({ + 'group_id': production.procurement_group_id.id, + 'reference': production.name, # set reference when MO name is different than 'New' + }) + additional_moves._adjust_procure_method() + moves_to_confirm |= additional_moves + moves_to_confirm |= production.move_finished_ids.filtered( lambda move: move.state == 'draft' and move.additional ) if moves_to_confirm: diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 6d503549db7..a04f9078acc 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -273,3 +273,36 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): self.assertFalse(production.move_raw_ids.move_orig_ids) self.assertEqual(production.state, 'confirmed') self.assertEqual(production.reservation_state, 'assigned') + + def test_manufacturing_3_steps_flexible(self): + """ Test MO/picking before manufacturing/picking after manufacturing + components and move_orig/move_dest. Ensure that additional moves are put + in picking before manufacturing too. + """ + with Form(self.warehouse) as warehouse: + warehouse.manufacture_steps = 'pbm_sam' + bom = self.env['mrp.bom'].search([ + ('product_id', '=', self.finished_product.id) + ]) + new_product = self.env['product.product'].create({ + 'name': 'New product', + 'type': 'product', + }) + bom.consumption = 'flexible' + production_form = Form(self.env['mrp.production']) + production_form.product_id = self.finished_product + production_form.picking_type_id = self.warehouse.manu_type_id + production = production_form.save() + + production.action_confirm() + + production_form = Form(production) + with production_form.move_raw_ids.new() as move: + move.product_id = new_product + move.product_uom_qty = 2 + production = production_form.save() + move_raw_ids = production.move_raw_ids + self.assertEqual(len(move_raw_ids), 2) + pbm_move = move_raw_ids.move_orig_ids + self.assertEqual(len(pbm_move), 2) + self.assertTrue(new_product in pbm_move.product_id)