diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index ea338cf7cd2551c2ee6ab5c661313f41fc5c4f56..cc5f607637866e08f3968b1899724a5239cefc4e 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -506,21 +506,31 @@ class Repair(models.Model): 'partner_id': repair.address_id.id, 'location_id': operation.location_id.id, 'location_dest_id': operation.location_dest_id.id, - 'move_line_ids': [(0, 0, {'product_id': operation.product_id.id, - 'lot_id': operation.lot_id.id, - 'product_uom_qty': 0, # bypass reservation here - 'product_uom_id': operation.product_uom.id, - 'qty_done': operation.product_uom_qty, - 'package_id': False, - 'result_package_id': False, - 'owner_id': owner_id, - 'location_id': operation.location_id.id, #TODO: owner stuff - 'company_id': repair.company_id.id, - 'location_dest_id': operation.location_dest_id.id,})], 'repair_id': repair.id, 'origin': repair.name, 'company_id': repair.company_id.id, }) + + # Best effort to reserve the product in a (sub)-location where it is available + product_qty = move.product_uom._compute_quantity( + operation.product_uom_qty, move.product_id.uom_id, rounding_method='HALF-UP') + available_quantity = self.env['stock.quant']._get_available_quantity( + move.product_id, + move.location_id, + lot_id=operation.lot_id.id, + strict=False, + ) + move._update_reserved_quantity( + product_qty, + available_quantity, + move.location_id, + lot_id=operation.lot_id.id, + strict=False, + ) + # Then, set the quantity done. If the required quantity was not reserved, negative + # quant is created in operation.location_id. + move._set_quantity_done(operation.product_uom_qty) + moves |= move operation.write({'move_id': move.id, 'state': 'done'}) move = Move.create({