Hi,
- dependancies : sale_order_ids.date_order,sale_order_ids.state
- sale_order_ids.date_order : when this date change, we want update our field
- sale_order_ids.state : when the state change too. Because if a client change his mind and cancel an order/sale, we must change the date.
- calculate :
for record in self:
confirmed_client_orders = record.sale_order_ids.filtered(lambda o: o.state == 'sale')
if confirmed_client_orders:
# Obtenir la date de la dernière commande
record['x_studio_fecha_ultima_compra'] = max(confirmed_client_orders.mapped('date_order'))
else:
# Pas de commandes confirmées
record['x_studio_fecha_ultima_compra'] = False
Someone? can help me??