[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) <nle@odoo.com>
This commit is contained in:
Jairo Llopis
2021-06-14 15:50:17 +00:00
committed by Nicolas Lempereur
parent f27b186a63
commit ba812ddd99
+1
View File
@@ -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):