Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] repair,mrp_repair: add kit products to confirmed repair orders #163847

Draft
wants to merge 1 commit into
base: saas-16.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions addons/mrp_repair/tests/test_flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.fields import Command


@tagged('post_install', '-at_install')
class TestMrpRepairFlows(TestMrpCommon):
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, part1, part2, kit = self.env['product.product'].create([
{'name': 'Repaired'},
{'name': 'Kit Component1'},
{'name': 'Kit Component2'},
{'name': 'Kit', 'type': 'product'},
])
self.env['mrp.bom'].create({
'product_id': kit.id,
'product_tmpl_id': kit.product_tmpl_id.id,
'type': 'phantom',
'bom_line_ids': [
Command.create({
'product_id': part1.id,
'product_qty': 1.0,
}),
Command.create({
'product_id': part2.id,
'product_qty': 1.0,
}),
],
})

ro_form = Form(self.env['repair.order'])
ro_form.product_id = repaired
ro = ro_form.save()
ro.action_validate()

self.env['stock.move'].create({
'repair_id': ro.id,
'product_id': kit.id,
'repair_line_type': 'add',
})

self.assertEqual(ro.move_ids.product_id, part1 | part2, "Repair order moves should correspond to the kit components")
16 changes: 9 additions & 7 deletions addons/repair/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,37 @@ def create(self, vals_list):
vals['location_id'] = src_location.id
if not vals.get('location_dest_id'):
vals['location_dest_id'] = dest_location.id
moves = super().create(vals_list)
repair_moves = self.env['stock.move']
moves = super().create(vals_list).with_context(no_create_sol=True)
repair_moves = moves.env['stock.move']
for move in moves:
if not move.repair_id:
continue
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

confirmed_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()
confirmed_moves = move._action_confirm()
confirmed_moves._trigger_scheduler()
repair_moves |= confirmed_moves
repair_moves._create_repair_sale_order_line()
return moves
return moves.with_context(self.env.context)

def write(self, vals):
res = super().write(vals)
repair_moves = self.env['stock.move']
moves_to_create_so_line = self.env['stock.move']
create = not self.env.context.get('no_create_sol', False)
for move in self:
if not move.repair_id:
continue
# checks vals update
if 'repair_line_type' in vals or 'picking_type_id' in vals and move.product_id != move.repair_id.product_id:
move.location_id, move.location_dest_id = move._get_repair_locations(move.repair_line_type)
if not move.sale_line_id and 'sale_line_id' not in vals and move.repair_line_type == 'add':
if create and not move.sale_line_id and 'sale_line_id' not in vals and move.repair_line_type == 'add':
moves_to_create_so_line |= move
if move.sale_line_id and ('repair_line_type' in vals or 'product_uom_qty' in vals):
repair_moves |= move
Expand Down