From cf0d1eb80a366e7bbd18b2a655a322f7853a29c7 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 3 Feb 2022 14:40:23 +0000 Subject: [PATCH] [FIX] sale: compute the expected date based on the order state The state of sale order lines is strictly related to the order state, it's unnecessary to read the information line by line (and fetch/compute it) when we already have it on the current order record. X-original-commit: 660eaccbb417938bff0ffd8bd6a03aa1c42ce877 Part-of: odoo/odoo#84105 --- addons/sale/models/sale_order.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 4349aaddcf1..1159bebbd10 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -367,17 +367,19 @@ class SaleOrder(models.Model): for order in self: order.is_expired = order.state == 'sent' and order.validity_date and order.validity_date < today - @api.depends('order_line.customer_lead', 'date_order', 'order_line.state') + @api.depends('order_line.customer_lead', 'date_order', 'state') def _compute_expected_date(self): """ 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): - dt = line._expected_date() - dates_list.append(dt) + if order.state == 'cancel': + order.expected_date = False + continue + dates_list = order.order_line.filtered( + lambda line: not line.display_type and not line._is_delivery() + ).mapped(lambda line: line and line._expected_date()) if dates_list: order.expected_date = min(dates_list) else: