diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index c9dbb991a34..fa8f724beec 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -327,6 +327,7 @@ class StockMoveLine(models.Model): else: create_move(move_line) + move_to_recompute_state = self.env['stock.move'] for move_line in mls: reserved_uom_qty = move_line.reserved_uom_qty location = move_line.location_id @@ -346,6 +347,9 @@ class StockMoveLine(models.Model): if not reserved_quants or float_compare(reserved_qty, sum(map(lambda q: q[1], reserved_quants)), product.uom_id.rounding) != 0: reserved_uom_qty = product.uom_id._compute_quantity(reserved_qty, ml_uom, rounding_method='HALF-UP') move_line.with_context(bypass_reservation=True).reserved_uom_qty = reserved_uom_qty + if move: + move_to_recompute_state |= move + move_to_recompute_state._recompute_state() moves_to_update = mls.filtered( lambda ml: @@ -910,8 +914,6 @@ class StockMoveLine(models.Model): 'location_id': quant.location_id.id, 'owner_id': quant.owner_id.id, } - if not (self.qty_done or vals.get('qty_done')): - line_data['qty_done'] = uom._compute_quantity(quant.available_quantity, quant.product_uom_id, rounding_method='HALF_UP') return line_data def action_open_reference(self): diff --git a/addons/stock/tests/test_immediate.py b/addons/stock/tests/test_immediate.py index 7d24a1d12ed..849e6d11651 100644 --- a/addons/stock/tests/test_immediate.py +++ b/addons/stock/tests/test_immediate.py @@ -15,6 +15,7 @@ class StockMove(TransactionCase): 'type': 'product', 'categ_id': cls.env.ref('product.product_category_all').id, }) + cls.env['stock.quant']._update_available_quantity(cls.product, cls.stock_location, 10.0) cls.product_consu = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'consu', @@ -40,3 +41,23 @@ class StockMove(TransactionCase): self.assertEqual(action['context']['show_quant'], True) action = picking.move_ids[1].action_show_details() self.assertEqual(action['context']['show_quant'], False) + + def test_create_move_line_reserved(self): + """ Create a delivery immediate transfer with a storable product. + The move line should be reserved. + """ + # create a delivery order + picking = Form(self.env['stock.picking'].with_context(default_picking_type_id=self.ref('stock.picking_type_out'))) + with picking.move_ids_without_package.new() as move: + move.product_id = self.product + move.product_uom_qty = 1.0 + picking = picking.save() + self.env['stock.move.line'].create({ + 'move_id': picking.move_ids_without_package.id, + 'product_id': self.product.id, + 'reserved_uom_qty': 1.0, + 'qty_done': 0, + }) + self.assertEqual(picking.move_ids.reserved_availability, 1.0) + self.assertEqual(picking.move_ids.state, 'assigned') + self.assertEqual(picking.move_ids.quantity_done, 0) diff --git a/addons/stock/tests/test_move_lines.py b/addons/stock/tests/test_move_lines.py index d5c54dd590b..7a618ed872b 100644 --- a/addons/stock/tests/test_move_lines.py +++ b/addons/stock/tests/test_move_lines.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.stock.tests.common import TestStockCommon +from odoo.tests import Form class StockMoveLine(TestStockCommon): @@ -57,8 +58,12 @@ class StockMoveLine(TestStockCommon): 'product_uom': self.product.uom_id.id, 'location_id': self.stock_location, 'location_dest_id': self.stock_location, - 'move_line_ids': [(0, 0, {'quant_id': self.quant.id})] }) + move_form = Form(move, view='stock.view_stock_move_operations') + with move_form.move_line_ids.new() as ml: + ml.quant_id = self.quant + + move = move_form.save() self.assertEqual(move.move_line_ids.lot_id, self.lot) self.assertEqual(move.move_line_ids.package_id, self.pack)