Skip to content
Snippets Groups Projects
Commit e5041ee1 authored by Arnold Moyaux's avatar Arnold Moyaux
Browse files

[FIX] stock: prevent to copy reservation on stock.move.line


Usecase:
- Product A 10 units in stock
- Do a planned transfer of 7 units to customer
- Reserve
- Do an rpc or execute code to call copy on the stock.move.line

It will result with 2 sml that have 14 units reserve and 7 units
reserved on stock.quant

It's the same result if you create twice the stock.move.line without
updating the stock.quant at the same time. However in stable we
try to only use _update_reserved_quantity on stock.move or some
override in create/write method for 'done' stock.move.line in unlock
cases.

So we never use the copy in stable and define the basic behavior as
'we don't copy the reservation' could prevent some usecase where
the update on the stock.quant is forgotten after.

closes odoo/odoo#74275

X-original-commit: 0c293ce4
Signed-off-by: default avatarArnold Moyaux <amoyaux@users.noreply.github.com>
parent 0cd0bec8
No related branches found
No related tags found
No related merge requests found
......@@ -28,9 +28,10 @@ class StockMoveLine(models.Model):
product_id = fields.Many2one('product.product', 'Product', ondelete="cascade", check_company=True, domain="[('type', '!=', 'service'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True)
product_qty = fields.Float(
'Real Reserved Quantity', digits=0,
'Real Reserved Quantity', digits=0, copy=False,
compute='_compute_product_qty', inverse='_set_product_qty', store=True)
product_uom_qty = fields.Float('Reserved', default=0.0, digits='Product Unit of Measure', required=True)
product_uom_qty = fields.Float(
'Reserved', default=0.0, digits='Product Unit of Measure', required=True, copy=False)
qty_done = fields.Float('Done', default=0.0, digits='Product Unit of Measure', copy=False)
package_id = fields.Many2one(
'stock.quant.package', 'Source Package', ondelete='restrict',
......
......@@ -145,8 +145,7 @@ class TestWiseOperator(TransactionCase):
# put the move lines from delivery_order_wise2 into delivery_order_wise1
for pack_id2 in pack_ids2:
new_pack_id1 = pack_id2.copy(default={'picking_id': delivery_order_wise1.id, 'move_id': move1.id})
new_pack_id1.qty_done = new_pack_id1.product_qty
new_pack_id1.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_pack_id1.qty_done = pack_id2.product_qty
new_move_lines = delivery_order_wise1.move_line_ids.filtered(lambda p: p.qty_done)
self.assertEqual(sum(new_move_lines.mapped('product_qty')), 0)
......@@ -157,8 +156,7 @@ class TestWiseOperator(TransactionCase):
# put the move line from delivery_order_wise1 into delivery_order_wise2
new_pack_id2 = pack_ids1.copy(default={'picking_id': delivery_order_wise2.id, 'move_id': move2.id})
new_pack_id2.qty_done = new_pack_id2.product_qty
new_pack_id2.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_pack_id2.qty_done = pack_ids1.product_qty
new_move_lines = delivery_order_wise2.move_line_ids.filtered(lambda p: p.qty_done)
self.assertEqual(len(new_move_lines), 1)
......
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