Skip to content

Commit

Permalink
[FIX] stock: _free_reservation
Browse files Browse the repository at this point in the history
to reproduce:
- have 4 units of product 1 in stock
- create a move for a dozen, reserve it
- try to scrap a single unit
- an exception "cannot reserve more than available" is raised

To reflect the change of reservation after scrapping the quantity, we
have to update the reserved quantity on the move line.
When updating the quantity on the move line, "quantity_split" is in the
quant uom, so it should be converted to the uom of the move line.
  • Loading branch information
sle-odoo committed Jan 4, 2018
1 parent cf32a23 commit 5f3255b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/stock/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def _free_reservation(self, product_id, location_id, quantity, lot_id=None, pack
candidate.product_qty - quantity,
precision_rounding=self.product_uom_id.rounding,
rounding_method='UP')
candidate.product_uom_qty = self.product_id.uom_id._compute_quantity(quantity_split, self.product_uom_id, rounding_method='HALF-UP')
candidate.product_uom_qty = self.product_id.uom_id._compute_quantity(quantity_split, candidate.product_uom_id, rounding_method='HALF-UP')
quantity -= quantity_split
move_to_recompute_state |= candidate.move_id
if quantity == 0.0:
Expand Down
41 changes: 41 additions & 0 deletions addons/stock/tests/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,47 @@ def test_scrap_4(self):
scrapped_move.quantity_done = 8
self.assertEqual(scrap.scrap_qty, 8, 'Scrap quantity is not updated.')

def test_scrap_5(self):
""" Scrap the product of a reserved move line where the product is reserved in another
unit of measure. Check that the move line is correctly updated after the scrap.
"""
# 4 units are available in stock
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 4)

# try to reserve a dozen
partner = self.env['res.partner'].create({'name': 'Kimberley'})
picking = self.env['stock.picking'].create({
'name': 'A single picking with one move to scrap',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'partner_id': partner.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
})
move1 = self.env['stock.move'].create({
'name': 'A move to confirm and scrap its product',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_dozen.id,
'product_uom_qty': 1.0,
'picking_id': picking.id,
})
move1._action_confirm()
move1._action_assign()
self.assertEqual(move1.reserved_availability, 0.33)

# scrap a unit
scrap = self.env['stock.scrap'].create({
'product_id': self.product1.id,
'product_uom_id': self.product1.uom_id.id,
'scrap_qty': 1,
'picking_id': picking.id,
})
scrap.action_validate()

self.assertEqual(scrap.state, 'done')
self.assertEqual(move1.reserved_availability, 0.25)

def test_in_date_1(self):
""" Check that moving a tracked quant keeps the incoming date.
"""
Expand Down

0 comments on commit 5f3255b

Please sign in to comment.