[FIX] mrp: incorrect quantity_done

Step:
* Create Bom A: product A - qty 1, bom line: product = Component X, qty
= 20
* Create MO with Bom A and 1 produced_qty = 1:
	+ on components: To Consume = 20, Consumed = 15
+ Unbuild MO, check Unbuild, check Product Moves of Unbuild, check line
product Component X has Quantity = 20, in fact quantity must = 15

closes odoo/odoo#156952

X-original-commit: 18c45260f50663e042da3bbec13d02ef269e26b2
Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
This commit is contained in:
Dang Van Loc
2024-03-11 10:17:49 +00:00
committed by clesgow
parent 3242a8e513
commit b7e4e5b2aa
2 changed files with 35 additions and 1 deletions
+1 -1
View File
@@ -257,7 +257,7 @@ class MrpUnbuild(models.Model):
'name': self.name,
'date': self.create_date,
'product_id': move.product_id.id,
'product_uom_qty': move.product_uom_qty * factor,
'product_uom_qty': move.quantity * factor,
'product_uom': move.product_uom.id,
'procure_method': 'make_to_stock',
'location_dest_id': location_dest_id.id,
+34
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import Command
from odoo.tests import Form
from odoo.addons.mrp.tests.common import TestMrpCommon
from odoo.exceptions import UserError
@@ -942,3 +943,36 @@ class TestUnbuild(TestMrpCommon):
{'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},
])
def test_unbuild_less_quantity_consumed(self):
"""
Tests that you don't unbuild more than you consumed during production.
BoM uses component x20, but only 15 are consumed during the production order.
Unbuilding the MO should only put 15 components back in stock.
"""
bom = self.env['mrp.bom'].create({
'product_id': self.product_2.id,
'product_tmpl_id': self.product_2.product_tmpl_id.id,
'consumption': 'flexible',
'product_qty': 1.0,
'type': 'normal',
'bom_line_ids': [
Command.create({'product_id': self.product_3.id, 'product_qty': 20}),
]
})
with Form(self.env['mrp.production']) as mo_form:
mo_form.product_id = self.product_2
mo_form.bom_id = bom
mo_form.product_qty = 1
mo = mo_form.save()
mo.action_confirm()
mo.qty_producing = 1.0
mo.move_raw_ids.write({'quantity': 15, 'picked': True})
mo.button_mark_done()
unbuild_action = mo.button_unbuild()
unbuild_wizard = Form(self.env[unbuild_action['res_model']].with_context(**unbuild_action['context'])).save()
unbuild_wizard.action_validate()
self.assertEqual(mo.unbuild_ids.produce_line_ids.filtered(lambda m: m.product_id == self.product_3).product_uom_qty, 15)