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
base: saas-16.4
Are you sure you want to change the base?
[FIX] repair,mrp_repair: add kit products to confirmed repair orders #163847
Conversation
5b69180
to
d76f084
Compare
Note: odoo/addons/repair/models/repair.py Lines 542 to 554 in a9d2771
and I'm not sure I fully understand why we don't have the "same" problem |
d76f084
to
b6064b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the idea of the fix
Just few improvements :)
Note: PR's target is ok, the issue starts from 16.4, since the refactoring (eaa6e1a)
addons/repair/models/stock_move.py
Outdated
|
||
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nitpicking)
In a lot of cases, the method will return the same move. So let's make the name simpler
exploded = move._action_confirm() | |
moves = move._action_confirm() |
addons/repair/models/stock_move.py
Outdated
repair_moves |= exploded | ||
else: | ||
repair_moves |= move |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not something like ?
repair_moves |= exploded | |
else: | |
repair_moves |= move | |
repair_moves |= moves |
Where moves
is initiated before the if-block ?
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', | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always better to work in batch
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', | |
}) | |
repaired, part, kit = self.env['product.product'].create([ | |
{...}, | |
... | |
]) |
}) | ||
bom.write({ | ||
'bom_line_ids': [self.env['mrp.bom.line'].create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not directly add the line while creating the BoM ?
We could then avoid a useless call to write
Also, be careful when dealing with 2many
fields, you need to use some commands
}) | |
bom.write({ | |
'bom_line_ids': [self.env['mrp.bom.line'].create({ | |
'bom_line_ids': [(0, 0, { |
}).id], | ||
}) | ||
try: | ||
# create repair order and confirm it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# create repair order and confirm it |
The code is clear enough :)
ro_form.product_id = repaired | ||
ro = ro_form.save() | ||
ro.action_validate() | ||
# add kit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# add kit |
Same
except AccessError: | ||
self.fail("Cannot add kit manufactured product to existing repair order") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use try-except
to test such use cases
Just do your calls directly in the test body, and if one call raises an error, the test will fail
Else, if there isn't any raised error, the test will pass
That being said, it's then a bit weird to have a test without any assert
So it's always worth adding at least one
Here for instance, you could check that the line has been replaced with a new line for the component
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not using any lot here, so I don't get the reason why it would be useful ?
@classmethod | |
def setUpClass(cls): | |
super().setUpClass() | |
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]}) |
When we |
Also, for the commit redaction, it's always better to explain why the issue occurs, instead of what the commit does as we can see that directly in the diff See the guidelines and the section "Write a commit" in our documentation :) So here, instead of
You can rather explain that, when confirming the SM and since it's a kit, we will explode it: odoo/addons/mrp/models/stock_move.py Lines 375 to 376 in 46931a3
And therefore, keeping a reference to the initial move is incorrect as it has been deleted during its confirmation |
23ef92a
to
d4ee07b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few small things, then it should be ok
I think there is an error in the commit description "When confirming moves, we explode them, so when we're adding directly to the repair order, we need to make we take the new moves."
{'name': 'Kit Component2'}, | ||
{'name': 'Kit', 'type': 'product'}, | ||
]) | ||
CREATE = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from odoo.fields import Command
'bom_line_ids': [ | ||
(CREATE, 0, { | ||
'product_id': part1.id, | ||
'product_tmpl_id': part1.product_tmpl_id.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the template is useless, and imo setting the quantity would make it clearer
'product_tmpl_id': part1.product_tmpl_id.id, | |
'product_qty': 1.0, |
ro_line.product_id = kit | ||
ro_form.save() | ||
|
||
self.assertEqual(len(ro_form.move_ids), 2, "Repair order moves should correspond to the kit components") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the form is a bit weird, it's better to use the record
Also, it could be nice to also ensure that move_ids
are based on the components: either by using assertRecordValues
(and getting rid of the assertEqual
), or by using another assertEqual
on ro.move_ids.product_id
.
That way, you can also remove the error message as the assert will be clear enough
d4ee07b
to
af7c0ff
Compare
}) | ||
|
||
self.assertEqual(len(ro.move_ids), 2, "Repair order moves should correspond to the kit components") | ||
self.assertEqual(ro.move_ids.mapped('product_id'), part1 | part2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertEqual(ro.move_ids.mapped('product_id'), part1 | part2) | |
self.assertEqual(ro.move_ids.product_id, part1 | part2) |
self.env['stock.move'].create({ | ||
'repair_id': ro.id, | ||
'product_id': kit.id, | ||
'repair_line_type': 'add', | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking 🙈
self.env['stock.move'].create({ | |
'repair_id': ro.id, | |
'product_id': kit.id, | |
'repair_line_type': 'add', | |
}) | |
self.env['stock.move'].create({ | |
'repair_id': ro.id, | |
'product_id': kit.id, | |
'repair_line_type': 'add', | |
}) |
af7c0ff
to
9d8ee69
Compare
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 --- When confirming moves, we explode them, so when we're adding directly to the repair order, we need to make sure we take the new moves. opw-3889564
9d8ee69
to
e4bba88
Compare
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
Fix
When confirming moves, we explode them, so when we're adding directly to
the repair order, we need to make sure we take the new moves.
opw-3889564
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr