From 2761393b06bb396cf08799948e6fda3091ff1f35 Mon Sep 17 00:00:00 2001 From: jev-odoo Date: Tue, 27 Aug 2019 09:26:51 +0000 Subject: [PATCH] [FIX] stock,sale_stock: Speed up sale_order confirmation In case there is a lot of stock_moves and/or lot of stock_quants, the function _get_qty_procurement takes a lot of time because there is no index defined on most accessed fields. I.E. OPW-2027183 closes odoo/odoo#36113 Signed-off-by: Richard Mathot (rim) --- addons/sale_stock/models/stock.py | 2 +- addons/stock/models/stock_quant.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index a346b815d20..b28a3e4c2ef 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -11,7 +11,7 @@ class StockLocationRoute(models.Model): class StockMove(models.Model): _inherit = "stock.move" - sale_line_id = fields.Many2one('sale.order.line', 'Sale Line') + sale_line_id = fields.Many2one('sale.order.line', 'Sale Line', index=True) @api.model def _prepare_merge_moves_distinct_fields(self): diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 80bd07e9a80..20a4bd640c6 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -20,7 +20,7 @@ class StockQuant(models.Model): product_id = fields.Many2one( 'product.product', 'Product', - ondelete='restrict', readonly=True, required=True) + ondelete='restrict', readonly=True, required=True, index=True) # so user can filter on template in webclient product_tmpl_id = fields.Many2one( 'product.template', string='Product Template', @@ -32,7 +32,7 @@ class StockQuant(models.Model): string='Company', store=True, readonly=True) location_id = fields.Many2one( 'stock.location', 'Location', - auto_join=True, ondelete='restrict', readonly=True, required=True) + auto_join=True, ondelete='restrict', readonly=True, required=True, index=True) lot_id = fields.Many2one( 'stock.production.lot', 'Lot/Serial Number', ondelete='restrict', readonly=True)