diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 4ebbccecb2d..b44f89fea14 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -3,7 +3,7 @@ from collections import Counter -from odoo import _, api, fields, models +from odoo import _, api, fields, tools, models from odoo.exceptions import UserError, ValidationError from odoo.tools import OrderedSet from odoo.tools.float_utils import float_compare, float_is_zero, float_round @@ -175,6 +175,15 @@ class StockMoveLine(models.Model): res['warning'] = {'title': _('Warning'), 'message': message} return res + def init(self): + if not tools.index_exists(self._cr, 'stock_move_line_free_reservation_index'): + self._cr.execute(""" + CREATE INDEX stock_move_line_free_reservation_index + ON + stock_move_line (id, company_id, product_id, lot_id, location_id, owner_id, package_id) + WHERE + (state IS NULL OR state NOT IN ('cancel', 'done')) AND product_qty > 0""") + @api.model_create_multi def create(self, vals_list): for vals in vals_list: