[FIX] mrp: Unbuild multi serial number components
Use case to reproduce: - Create a product with a BOM that use at least twice the same component tracked by SN - Build this product with SN 'A' and SN 'B' - Unbuild it -> Constraint error on duplicate SN It happens because the unbuild order will create only one stock.move.lots for SN A with a quantity of 2. This commit create a stock.move.lots by quant used, for example if the MO used 2 quants with a qty of 1 and one with lot 'A' and the other with lot 'B'. It will create 2 stock.move.lots with lots 'A' and 'B'. Still a know issue: If the user try to unbuild twice the same MO it will reuse the same unbuilded componenets than the first unbuild order.
This commit is contained in:
@@ -121,14 +121,20 @@ class MrpUnbuild(models.Model):
|
||||
for produce_move in produce_moves:
|
||||
if produce_move.has_tracking != 'none':
|
||||
original = original_quants.filtered(lambda quant: quant.product_id == produce_move.product_id)
|
||||
if original and not original[0].lot_id:
|
||||
if not original:
|
||||
raise UserError(_("You don't have in the stock the required lot/serial number for %s .") % (produce_move.product_id.name,))
|
||||
self.env['stock.move.lots'].create({
|
||||
'move_id': produce_move.id,
|
||||
'lot_id': original[0].lot_id.id,
|
||||
'quantity_done': produce_move.product_uom_qty,
|
||||
'quantity': produce_move.product_uom_qty
|
||||
})
|
||||
quantity_todo = produce_move.product_qty
|
||||
for quant in original:
|
||||
if quantity_todo <= 0:
|
||||
break
|
||||
move_quantity = min(quantity_todo, quant.qty)
|
||||
self.env['stock.move.lots'].create({
|
||||
'move_id': produce_move.id,
|
||||
'lot_id': quant.lot_id.id,
|
||||
'quantity_done': produce_move.product_id.uom_id._compute_quantity(move_quantity, produce_move.product_uom),
|
||||
'quantity': produce_move.product_id.uom_id._compute_quantity(move_quantity, produce_move.product_uom),
|
||||
})
|
||||
quantity_todo -= move_quantity
|
||||
else:
|
||||
produce_move.quantity_done = produce_move.product_uom_qty
|
||||
produce_moves.move_validate()
|
||||
|
||||
Reference in New Issue
Block a user