I am trying to compute the days since of a book release date. while creating a new record, the code showing an error.
Something went wrong !
library.book(,).age_days
I would like to solve this problem using filtered(lambda function).
My code:
date_release = fields.Date('Release Date', copy=False)
age_days = fields.Float(string='Days Since Release', compute='_compute_age')
@api.depends('date_release')
def _compute_age(self): #self: library.book(,)
today = fields.Date.today() #today: 2021-06-16
for book in self.filtered(lambda x: x.date_release):
delta = today - book.date_release
book.age_days = delta.days