[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
This commit is contained in:
Victor Feyens
2022-02-07 17:16:02 +00:00
parent 4d04ac2056
commit cf0d1eb80a
+7 -5
View File
@@ -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: