Skip to Content
Menu
This question has been flagged
2 Replies
127 Views

HELLO,

I need to calculate a field which shows the last order date from each customers.

The field I created in customer model its call "x_studio_fecha_ultima_compra"

Whereas the formula max was right aplied, the depedence field it did not work and its drive me crazy.

please, help me how to have to call the field date order from sale order model, and how to have to calculate the maximum value of date order field for each customer.


regards,






Avatar
Discard
Author

Someone? can help me??

Author Best Answer

this is what I wrote,


and the result, it doesnt calculate yet.

this is the field...




Avatar
Discard
Best Answer

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

Avatar
Discard
Author

Hi, Thanks.
I changed the code and It solved the windows error about dependences fields, but it doesnt show any date in the calculate fields yet.