Skip to content
Snippets Groups Projects
Commit 0ff08112 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] repair: reserve parts


- Create some stock in WH/Stock for product A
- Create some stock in WH/Stock/Shelf 1 for product B
- Create a Repair Order for Product A in WH/Stock
- Add a line in Parts with B, leave the location to WH/Stock
- Process the order until the end

Negative quant is created in WH/Stock for B instead of using the
quantity in WH/Stock/Shelf 1.

We do a best effort in order to reserve the quantity in the
sub-locations.

opw-2177352

closes odoo/odoo#43631

Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent d679c75b
No related branches found
No related tags found
No related merge requests found
......@@ -493,19 +493,30 @@ 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
'location_dest_id': operation.location_dest_id.id,})],
'repair_id': repair.id,
'origin': repair.name,
})
# 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({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment