Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
137 Näkymät

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
Hylkää
Tekijä

Someone? can help me??

Tekijä Paras vastaus

this is what I wrote,


and the result, it doesnt calculate yet.

this is the field...




Avatar
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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.