just copy paste from Julia,
i had a similar problem, Odoo send me this fix:
ARM created a fix for this. In order to implement it you need to follow these steps:
1.debug mode
2.technical/server actions
3.create
4.action name: e.g. fix unreserved qty
5.model: ir.actions.server
6.action to do: "execute python code"
7.copy/paste the fix underneath the pre-existing code
8."save"
9."create contextual action"
10.refresh page
11.action/fix "fix unreserved qty"
12.wait for it to load
13."remove contextual action"
14.action/delete
here is the code
============
quants = env['stock.quant'].search([])
move_line_ids = []
warning = ''
for quant in quants:
move_lines = env["stock.move.line"].search([
('product_id', '=', quant.product_id.id),
('location_id', '=', quant.location_id.id),
('lot_id', '=', quant.lot_id.id),
('package_id', '=', quant.package_id.id),
('owner_id', '=', quant.owner_id.id),
('product_qty', '!=', 0)
])
move_line_ids += move_lines.ids
reserved_on_move_lines = sum(move_lines.mapped('product_qty'))
move_line_str = str.join(', ', [str(move_line_id) for move_line_id in move_lines.ids])
if quant.location_id.should_bypass_reservation():
# If a quant is in a location that should bypass the reservation, its `reserved_quantity` field
# should be 0.
if quant.reserved_quantity != 0:
quant.write({'reserved_quantity': 0})
else:
# If a quant is in a reservable location, its `reserved_quantity` should be exactly the sum
# of the `product_qty` of all the partially_available / assigned move lines with the same
# characteristics.
if quant.reserved_quantity == 0:
if move_lines:
move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
elif quant.reserved_quantity < 0:
quant.write({'reserved_quantity': 0})
if move_lines:
move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
else:
if reserved_on_move_lines != quant.reserved_quantity:
move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
quant.write({'reserved_quantity': 0})
else:
if any(move_line.product_qty < 0 for move_line in move_lines):
move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
quant.write({'reserved_quantity': 0})
move_lines = env['stock.move.line'].search([
('product_id.type', '=', 'product'),
('product_qty', '!=', 0),
('id', 'not in', move_line_ids),
])
move_lines_to_unreserve = []
for move_line in move_lines:
if not move_line.location_id.should_bypass_reservation():
move_lines_to_unreserve.append(move_line.id)
if len(move_lines_to_unreserve) > 1:
env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id in %s ;""" % (tuple(move_lines_to_unreserve), ))
elif len(move_lines_to_unreserve) == 1:
env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id = %s ;""" % (move_lines_to_unreserve[0]))
then on the logs you will see :
2019-07-05 15:32:54,032 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2144]
2019-07-05 15:32:54,388 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2145]
2019-07-05 15:32:54,600 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2146]
2019-07-05 15:32:54,814 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2147]
2019-07-05 15:32:55,026 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2148]
2019-07-05 15:32:55,242 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2149]
2019-07-05 15:32:55,458 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2150]
2019-07-05 15:32:55,674 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2151]
2019-07-05 15:32:55,886 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2152]
2019-07-05 15:32:56,095 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2153]
2019-07-05 15:32:56,306 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2154]
2019-07-05 15:32:56,517 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2155]
2019-07-05 15:32:56,736 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2156]
2019-07-05 15:32:56,952 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2157]
2019-07-05 15:32:57,164 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2158]
2019-07-05 15:32:57,378 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2159]
2019-07-05 15:32:57,595 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2160]
2019-07-05 15:32:57,808 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2161]
2019-07-05 15:32:58,023 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2162]
2019-07-05 15:32:58,234 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2163]
2019-07-05 15:32:58,447 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2164]
2019-07-05 15:32:58,654 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2165]
2019-07-05 15:32:58,868 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2166]
2019-07-05 15:32:59,081