odoo 8 auto count days field

48 views Asked by At

I have this Interest Age (days) field which I want to be able to shown count of days between a specified date from other field and to day, so that everytime I open the page it will update the days

date_hpp_start = fields.Date('HPP Date start')
@api.multi
@api.depends('date_hpp_start')
def _compute_difference(self):
    for rec in self:
        if rec.date_hpp_start:
            converted_date = datetime.datetime.strptime(rec.date_hpp_start, '%Y-%m-%d').date()
            rec.days_difference = (datetime.date.today() - converted_date).days

days_difference = fields.Integer(string='Interest Age (days)', store=True, compute=_compute_difference)

This is not correct because with this code,the days only be changed everytime I choose the HPP Date start field. Thank you.

1

There are 1 answers

0
Nur Faiz On

I found that the problem is on the store=True, and after I removed it, it shown the days according to the counter.