From 9ee9be3f4d9eee847658d16571f4299ed93ed96f Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Thu, 24 Nov 2022 14:37:00 +0000 Subject: [PATCH] [PERF] mrp,stock,purchase: sql improvement First correction: replace call to `read_group` to `_read_group` in order to avoid useless joints on table product_template and ir_translation when the grouping key is a Many2One. Second correction: add an index on workorder's `state` field. The get_conflicted_workorder_ids() method search for ready workorders that are in conflict relate to their planning. The state value is searched to many times to not index it closes odoo/odoo#106582 Task: 2852423 X-original-commit: b5019eec76845316e554f2dd11a6d8bbf6fea433 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_workorder.py | 2 +- addons/purchase_stock/models/product.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 4900076f3a3..8f8945213d9 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -63,7 +63,7 @@ class MrpWorkorder(models.Model): ('done', 'Finished'), ('cancel', 'Cancelled')], string='Status', compute='_compute_state', store=True, - default='pending', copy=False, readonly=True, recursive=True) + default='pending', copy=False, readonly=True, recursive=True, index=True) leave_id = fields.Many2one( 'resource.calendar.leaves', help='Slot into workcenter calendar once planned', diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index 55b055333eb..f93667c834d 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -33,7 +33,7 @@ class ProductProduct(models.Model): qty_by_product_location, qty_by_product_wh = super()._get_quantity_in_progress(location_ids, warehouse_ids) domain = self._get_lines_domain(location_ids, warehouse_ids) - groups = self.env['purchase.order.line'].read_group(domain, + groups = self.env['purchase.order.line']._read_group(domain, ['product_id', 'product_qty', 'order_id', 'product_uom', 'orderpoint_id'], ['order_id', 'product_id', 'product_uom', 'orderpoint_id'], lazy=False) for group in groups: