From b9edb91418de5a9d5855eea166d0149ec0d730bb Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 5 Jan 2018 11:14:36 +0100 Subject: [PATCH] [FIX] stock_account: change standard price Improve performance when 70k+ locations, only use locations where the product is instead of all locations. --- addons/stock_account/models/product.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 1e4ac7ffbe1..751d182d30d 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -97,7 +97,9 @@ class ProductProduct(models.Model): """ Changes the Standard Price of Product and creates an account move accordingly.""" AccountMove = self.env['account.move'] - locations = self.env['stock.location'].search([('usage', '=', 'internal'), ('company_id', '=', self.env.user.company_id.id)]) + quant_locs = self.env['stock.quant'].sudo().read_group([('product_id', 'in', self.ids)], ['location_id'], ['location_id']) + quant_loc_ids = [loc['location_id'][0] for loc in quant_locs] + locations = self.env['stock.location'].search([('usage', '=', 'internal'), ('company_id', '=', self.env.user.company_id.id), ('id', 'in', quant_loc_ids)]) product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in self}