Skip to Content
Menu
This question has been flagged
198 Views

So, the new fields is "x_studio_dias_ultima_compra" (res.partner model , float). It should be the difference between today() and field named "x_studio_fecha_ultima_compra_1" (res.partner model , datetime).

its calculation it works like this (and it is succesfully operative ):

for record in self:
    confirmed_client_orders = record.sale_order_ids.filtered(lambda o: o.state == 'sale')
    if confirmed_client_orders:
        record['x_studio_fecha_ultima_compra_1'] = max(confirmed_client_orders.mapped('date_order'))
    else:
        record['x_studio_fecha_ultima_compra_1'] = False

so the new calculation that I'll try without luck is:


    def _compute_dias_ultima_compra(self):
        today = date.today()
        for record in self:
            if record.x_studio_fecha_ultima_compra_1 is set:
               
                fecha_compra = record.x_studio_fecha_ultima_compra_1.date()
                diferencia = (today - fecha_compra).days
                record.x_studio_dias_ultima_compra = diferencia
            else:
                record.x_studio_dias_ultima_compra = 0

the results are... 0 in all "x_studio_dias_ultima_compra" customer's field and then when I updated some record in a customer I got an error window refered to this comand.

I dont see the mistake, please help me,

regards

Avatar
Discard

Actual error message would be beneficial