[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#74489 X-original-commit: e5041ee1d9b5036cab55f4332977aeb818a3b1e1 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
@@ -30,9 +30,10 @@ class StockMoveLine(models.Model):
|
||||
product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True, domain="[('category_id', '=', product_uom_category_id)]")
|
||||
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user