[FIX] mrp: backorder reservation correct UoM

Steps to reproduce:
-Create a product in kg as storable.
-Add it into the BOM of another as grams.
-Create an MO with the BOM with more than 1 quantity to be produced.
-Set the quantity to be produced to 1, validate and create backorder.

Bug:
Error message: "It is not possible to reserve more products of test kg
than you have in stock."

Fix:
correct conversion of units during backorder reservation of component

closes odoo/odoo#129152

X-original-commit: 8f26839998f21e521ecaeba38a2bcc6c72894f41
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid HANNICHE (waha)
2023-07-20 15:45:08 +02:00
parent 2c188a6c02
commit d49f1a05e6
2 changed files with 52 additions and 4 deletions
+4 -4
View File
@@ -1793,13 +1793,13 @@ class MrpProduction(models.Model):
move_qty_to_reserve = move.product_qty
for index, (quantity, move_line, ml_vals) in enumerate(ml_by_move):
taken_qty = min(quantity, move_qty_to_reserve)
taken_qty_uom = min(product_uom._compute_quantity(taken_qty, move_line.product_uom_id), move_line.qty_done)
taken_qty = min(quantity, move_qty_to_reserve, move_line.product_uom_id._compute_quantity(move_line.qty_done, product_uom))
taken_qty_uom = product_uom._compute_quantity(taken_qty, move_line.product_uom_id)
if float_is_zero(taken_qty_uom, precision_rounding=move_line.product_uom_id.rounding):
continue
move_line.with_context(bypass_reservation_update=True).reserved_uom_qty = taken_qty_uom
move_qty_to_reserve -= taken_qty_uom
ml_by_move[index] = (quantity - taken_qty_uom, move_line, ml_vals)
move_qty_to_reserve -= taken_qty
ml_by_move[index] = (quantity - taken_qty, move_line, ml_vals)
if float_compare(move_qty_to_reserve, 0, precision_rounding=move.product_uom.rounding) <= 0:
assigned_moves.add(move.id)
+48
View File
@@ -274,6 +274,54 @@ class TestMrpProductionBackorder(TestMrpCommon):
self.assertEqual(p2_bo_mls.lot_id, lot1)
self.assertEqual(p2_bo_mls.reserved_qty, 2)
def test_uom_backorder(self):
"""
test backorder component UoM different from the bom's UoM
"""
product_finished = self.env['product.product'].create({
'name': 'Young Tom',
'type': 'product',
})
product_component = self.env['product.product'].create({
'name': 'Botox',
'type': 'product',
'uom_id': self.env.ref('uom.product_uom_kgm').id,
'uom_po_id': self.env.ref('uom.product_uom_kgm').id,
})
mo_form = Form(self.env['mrp.production'])
mo_form.product_id = product_finished
mo_form.bom_id = self.env['mrp.bom'].create({
'product_id': product_finished.id,
'product_tmpl_id': product_finished.product_tmpl_id.id,
'product_uom_id': self.uom_unit.id,
'product_qty': 1.0,
'type': 'normal',
'consumption': 'flexible',
'bom_line_ids': [(0, 0, {
'product_id': product_component.id,
'product_qty': 1,
'product_uom_id':self.env.ref('uom.product_uom_gram').id,
}),]
})
mo_form.product_qty = 1000
mo = mo_form.save()
mo.action_confirm()
self.env['stock.quant']._update_available_quantity(product_component, self.stock_location, 1000)
mo.action_assign()
production_form = Form(mo)
production_form.qty_producing = 300
mo = production_form.save()
action = mo.button_mark_done()
backorder_form = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
backorder_form.save().action_backorder()
# 300 Grams consumed and 700 reserved
self.assertAlmostEqual(self.env['stock.quant']._gather(product_component, self.stock_location).reserved_quantity, 0.7)
def test_tracking_backorder_series_serial_1(self):
""" Create a MO of 4 tracked products (serial) with pbm_sam.
all component is tracked by serial