[FIX] stock: recompute move state for reservation

Creating a move line with some reserved quantity should make its stock
move recompute its state as this noew reservation quantity could make it
assigned.

closes odoo/odoo#126069

Task: 3371590
X-original-commit: ca4cf35b3450ad3246e57a34aa8f3fe7c4f187af
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
William Henrotin
2023-06-23 16:35:22 +02:00
parent 955a5fecc8
commit 4ae28ba747
3 changed files with 31 additions and 3 deletions
+4 -2
View File
@@ -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):
+21
View File
@@ -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)
+6 -1
View File
@@ -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)