From ba812ddd992c2e8ee7060197e30f17b2bb8d062b Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Fri, 11 Jun 2021 08:36:35 +0000 Subject: [PATCH] [FIX] sale: improve compute expected date performance Without this patch, each time the compute reaches the line with `.filtered()`, it needs a new fetch from the database. With too many sale orders, this becomes a bottleneck. Now, before getting to that line, Odoo knows that it'll need all sale.order.line records, so it can fetch them all at once. In a production database, loading the sale.order list goes down from 7s to 500ms with this patch. @Tecnativa TT30390 closes odoo/odoo#72141 X-original-commit: 7969a052a19f3572e4819d163f969ae02bc8a80e Signed-off-by: Nicolas Lempereur (nle) --- addons/sale/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 6a8816fffb0..ef1a95d2f6e 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -316,6 +316,7 @@ class SaleOrder(models.Model): """ For service and consumable, we only take the min dates. This method is extended in sale_stock to take the picking_policy of SO into account. """ + self.mapped("order_line") # Prefetch indication for order in self: dates_list = [] for line in order.order_line.filtered(lambda x: x.state != 'cancel' and not x._is_delivery() and not x.display_type):