Skip to content

Commit 4870606

Browse files
committed
[FIX] mrp: find child/source MO
When a MO is generated in order to supply another one, the smart buttons "Source MO"/"Child MO" are still invisible. To reproduce the issue: 1. In Settings, enable "Multi-Step Routes" 2. Enable MTO route 3. Edit the warehouse: 3-steps manufacturing 4. Create 3 stored products Super, Sub and Compo: - Sub has two routes: MTO and Manufacture 5. Create two BoMs: - For 1 x Super: - 1 x Sub - For 1 x Sub: - 1 x Compo 6. Create and confirm a MO with 1 x Super Error: On confirmation, a second MO is created to produce one Sub, which is correct. However, neither the first MO nor the generated one has a link with the other one (through the smart button "Source MO"/"Child MO") When confirming the MO, a SM is created to bring one Sub to the pre-production location. Thanks to MTO route, this will generate another SM that brings one Sub from post-production to stock location (this will lead to the creation of the second MO). However, the other SM (1 x Sub from Post to Stock) doesn't have the same procurement group. This is the reason why it is not found by the `_compute` methods. OPW-2730830 closes odoo#85083 Signed-off-by: Arnold Moyaux (arm) <[email protected]>
1 parent a33b7ee commit 4870606

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

addons/mrp/models/mrp_production.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,17 @@ def _compute_allowed_product_ids(self):
282282
product_domain += [('id', 'in', production.bom_id.product_tmpl_id.product_variant_ids.ids)]
283283
production.allowed_product_ids = self.env['product.product'].search(product_domain)
284284

285-
@api.depends('procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids')
285+
@api.depends('procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids',
286+
'procurement_group_id.stock_move_ids.move_orig_ids.created_production_id.procurement_group_id.mrp_production_ids')
286287
def _compute_mrp_production_child_count(self):
287288
for production in self:
288-
production.mrp_production_child_count = len(production.procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids - production)
289+
production.mrp_production_child_count = len(production._get_children())
289290

290-
@api.depends('move_dest_ids.group_id.mrp_production_ids')
291+
@api.depends('procurement_group_id.mrp_production_ids.move_dest_ids.group_id.mrp_production_ids',
292+
'procurement_group_id.stock_move_ids.move_dest_ids.group_id.mrp_production_ids')
291293
def _compute_mrp_production_source_count(self):
292294
for production in self:
293-
production.mrp_production_source_count = len(production.procurement_group_id.mrp_production_ids.move_dest_ids.group_id.mrp_production_ids - production)
295+
production.mrp_production_source_count = len(production._get_sources())
294296

295297
@api.depends('procurement_group_id.mrp_production_ids')
296298
def _compute_mrp_production_backorder(self):
@@ -1051,9 +1053,21 @@ def _autoconfirm_production(self):
10511053

10521054
self.workorder_ids.filtered(lambda w: w.state not in ['done', 'cancel'])._action_confirm()
10531055

1056+
def _get_children(self):
1057+
self.ensure_one()
1058+
procurement_moves = self.procurement_group_id.stock_move_ids
1059+
child_moves = procurement_moves.move_orig_ids
1060+
return (procurement_moves | child_moves).created_production_id.procurement_group_id.mrp_production_ids - self
1061+
1062+
def _get_sources(self):
1063+
self.ensure_one()
1064+
dest_moves = self.procurement_group_id.mrp_production_ids.move_dest_ids
1065+
parent_moves = self.procurement_group_id.stock_move_ids.move_dest_ids
1066+
return (dest_moves | parent_moves).group_id.mrp_production_ids - self
1067+
10541068
def action_view_mrp_production_childs(self):
10551069
self.ensure_one()
1056-
mrp_production_ids = self.procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids.ids
1070+
mrp_production_ids = self._get_children()
10571071
action = {
10581072
'res_model': 'mrp.production',
10591073
'type': 'ir.actions.act_window',
@@ -1073,7 +1087,7 @@ def action_view_mrp_production_childs(self):
10731087

10741088
def action_view_mrp_production_sources(self):
10751089
self.ensure_one()
1076-
mrp_production_ids = self.procurement_group_id.mrp_production_ids.move_dest_ids.group_id.mrp_production_ids.ids
1090+
mrp_production_ids = self._get_sources()
10771091
action = {
10781092
'res_model': 'mrp.production',
10791093
'type': 'ir.actions.act_window',

addons/mrp/tests/test_warehouse_multistep_manufacturing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ def test_manufacturing_complex_product_3_steps(self):
421421
self.assertEqual(len(picking.move_lines), 1)
422422
picking.product_id = self.complex_product
423423

424+
# MOs are correctly linked to each other
425+
self.assertEqual(production.mrp_production_child_count, 1)
426+
self.assertEqual(production.mrp_production_source_count, 0)
427+
self.assertEqual(subproduction.mrp_production_child_count, 0)
428+
self.assertEqual(subproduction.mrp_production_source_count, 1)
429+
child_action = production.action_view_mrp_production_childs()
430+
source_action = subproduction.action_view_mrp_production_sources()
431+
self.assertEqual(child_action.get('res_id'), subproduction)
432+
self.assertEqual(source_action.get('res_id'), production)
433+
424434
def test_3_steps_and_byproduct(self):
425435
""" Suppose a warehouse with Manufacture option set to '3 setps' and a product P01 with a reordering rule.
426436
Suppose P01 has a BoM and this BoM mentions that when some P01 are produced, some P02 are produced too.

0 commit comments

Comments
 (0)