Skip to content

Commit

Permalink
[FIX] repair,mrp_repair: add kit products to confirmed repair orders
Browse files Browse the repository at this point in the history
Problem
---
When adding a kit manufactured product to a confirmed repair order,
an error is thrown upon saving, because we're working with a move
that was already deleted/exploded

Steps
---
* install repair,mrp
* create a repair order and confirm it
* add a kit manufactured product to it
* the error is thrown (Record already deleted)

Fix
---
make sure we're working with the moves after they are exploded.

opw-3889564
  • Loading branch information
naja628 committed May 3, 2024
1 parent 637cae0 commit b6064b1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions addons/mrp_repair/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import test_tracability
from . import test_flows
50 changes: 50 additions & 0 deletions addons/mrp_repair/tests/test_flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.tests import Form, tagged
from odoo.addons.mrp.tests.common import TestMrpCommon
from odoo.exceptions import AccessError


@tagged('post_install', '-at_install')
class TestMrpRepairFlows(TestMrpCommon):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})

def test_possible_to_add_kit_after_confirm(self):
"""
Test that it is possible to add a kit manufactured product to an already confirmed Repair Order
"""
repaired = self.env['product.product'].create({'name': 'Repaired'})
part = self.env['product.product'].create({'name': 'Kit Component'})
kit = self.env['product.product'].create({
'name': 'Kit',
'type': 'product',
})
bom = self.env['mrp.bom'].create({
'product_id': kit.id,
'product_tmpl_id': kit.product_tmpl_id.id,
'type': 'phantom',
})
bom.write({
'bom_line_ids': [self.env['mrp.bom.line'].create({
'product_id': part.id,
'product_tmpl_id': part.product_tmpl_id.id,
'bom_id': bom.id,
}).id],
})
try:
# create repair order and confirm it
ro_form = Form(self.env['repair.order'])
ro_form.product_id = repaired
ro = ro_form.save()
ro.action_validate()
# add kit
with ro_form.move_ids.new() as ro_line:
ro_line.repair_line_type = 'add'
ro_line.product_id = kit
ro_form.save()
except AccessError:
self.fail("Cannot add kit manufactured product to existing repair order")
8 changes: 5 additions & 3 deletions addons/repair/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ def create(self, vals_list):
move.group_id = move.repair_id.procurement_group_id.id
move.origin = move.name
move.picking_type_id = move.repair_id.picking_type_id.id
repair_moves |= move

if move.state == 'draft' and move.repair_id.state in ('confirmed', 'under_repair'):
move._check_company()
move._adjust_procure_method()
move._action_confirm()
move._trigger_scheduler()
exploded = move._action_confirm()
exploded._trigger_scheduler()
repair_moves |= exploded
else:
repair_moves |= move
repair_moves._create_repair_sale_order_line()
return moves

Expand Down

0 comments on commit b6064b1

Please sign in to comment.