[FIX] mrp: adjust procure method for additional moves
Commit c883ed1087 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 <Whenrow@users.noreply.github.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user