[FIX] mrp: unbuild the qty produced
Steps to reproduce the bug:
- Create a storable product “P1” with BoM:
- Component: C1, Qty: 1
- Create a Mo to produce 5 units of P1
- Confirm and mark as done the MO
- Unlock the MO
- Change the qty produced to 20
- Try to unbuild the MO
Problem:
Bug 1: The wizard triggered is set with the product_qty(5) instead
of the qty_produced (20)
Bug 2: Set the product_qty to 5 and validate the unbuild, in result
the stock moves in the unbuild order are 20 units instead of 5 units
opw-3630001
closes odoo/odoo#149494
X-original-commit: e4bac3ea028c529e6f47583e7c1af02158f23c2e
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -107,7 +107,7 @@ class MrpUnbuild(models.Model):
|
||||
if self.has_tracking == 'serial':
|
||||
self.product_qty = 1
|
||||
else:
|
||||
self.product_qty = self.mo_id.product_qty
|
||||
self.product_qty = self.mo_id.qty_produced
|
||||
|
||||
|
||||
@api.onchange('product_id')
|
||||
@@ -158,7 +158,7 @@ class MrpUnbuild(models.Model):
|
||||
self.env['stock.move.line'].create({
|
||||
'move_id': finished_move.id,
|
||||
'lot_id': self.lot_id.id,
|
||||
'quantity': finished_move.product_uom_qty,
|
||||
'quantity': self.product_qty,
|
||||
'product_id': finished_move.product_id.id,
|
||||
'product_uom_id': finished_move.product_uom.id,
|
||||
'location_id': finished_move.location_id.id,
|
||||
@@ -234,7 +234,7 @@ class MrpUnbuild(models.Model):
|
||||
for unbuild in self:
|
||||
if unbuild.mo_id:
|
||||
raw_moves = unbuild.mo_id.move_raw_ids.filtered(lambda move: move.state == 'done')
|
||||
factor = unbuild.product_qty / unbuild.mo_id.product_uom_id._compute_quantity(unbuild.mo_id.product_qty, unbuild.product_uom_id)
|
||||
factor = unbuild.product_qty / unbuild.mo_id.product_uom_id._compute_quantity(unbuild.mo_id.qty_produced, unbuild.product_uom_id)
|
||||
for raw_move in raw_moves:
|
||||
moves += unbuild._generate_move_from_existing_move(raw_move, factor, raw_move.location_dest_id, self.location_dest_id)
|
||||
else:
|
||||
|
||||
@@ -896,3 +896,49 @@ class TestUnbuild(TestMrpCommon):
|
||||
self.assertEqual(mo_2.unbuild_ids.produce_line_ids[0].lot_ids, finished_product_sn)
|
||||
self.assertEqual(mo_2.unbuild_ids.produce_line_ids[1].product_id, component)
|
||||
self.assertEqual(mo_2.unbuild_ids.produce_line_ids[1].lot_ids, component_sn)
|
||||
|
||||
def test_unbuild_different_qty(self):
|
||||
"""
|
||||
Test that the quantity to unbuild is the qty produced in the MO
|
||||
|
||||
BoM:
|
||||
- 4x final product
|
||||
components:
|
||||
- 2 x (storable)
|
||||
- 4 x (consumable)
|
||||
- Create a MO with 4 final products to produce.
|
||||
- Confirm and validate, then unlock the mo and update the qty produced to 10
|
||||
- open the wizard to unbuild > the quantity proposed should be 10
|
||||
- unbuild 4 units
|
||||
- the move lines should be created with the correct quantity
|
||||
"""
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.bom_id = self.bom_1
|
||||
mo = mo_form.save()
|
||||
|
||||
mo.action_confirm()
|
||||
mo.move_finished_ids._do_unreserve()
|
||||
mo_form = Form(mo)
|
||||
mo_form.qty_producing = 4
|
||||
mo = mo_form.save()
|
||||
mo.button_mark_done()
|
||||
self.assertEqual(mo.state, 'done', "Production order should be in done state.")
|
||||
# unlock and update the qty produced
|
||||
mo.action_toggle_is_locked()
|
||||
with Form(mo) as mo_form:
|
||||
mo_form.qty_producing = 10
|
||||
self.assertEqual(mo.qty_producing, 10)
|
||||
#unbuild order
|
||||
unbuild_form = Form(self.env['mrp.unbuild'])
|
||||
unbuild_form.mo_id = mo
|
||||
# check that the quantity to unbuild is the qty produced in the MO
|
||||
self.assertEqual(unbuild_form.product_qty, 10)
|
||||
unbuild_form.product_qty = 3
|
||||
unbuild_order = unbuild_form.save()
|
||||
unbuild_order.action_unbuild()
|
||||
self.assertRecordValues(unbuild_order.produce_line_ids.move_line_ids, [
|
||||
# pylint: disable=bad-whitespace
|
||||
{'product_id': self.bom_1.product_id.id, 'quantity': 3},
|
||||
{'product_id': self.bom_1.bom_line_ids[0].product_id.id, 'quantity': 0.6},
|
||||
{'product_id': self.bom_1.bom_line_ids[1].product_id.id, 'quantity': 1.2},
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user