My question is how i can call a dynamic current datetime in a function (not the static datetime) ?
@api.depends('start_date', 'date_now')
def _get_duration(self):
for r in self:
if r.start_date and r.date_now:
dt = r.start_date
ft = r.date_now
d1 = datetime.strptime(dt, "%Y-%m-%d %H:%M:%S").date()
d2 = datetime.strptime(ft, "%Y-%m-%d %H:%M:%S").date()
rd = relativedelta(d2, d1)
date_now = fields.Datetime('Date', default=fields.Datetime.now) <-- it returns the date of creation .. then the result of the function is not synchronize with the actual date.
So i am looking for a way to get a date that change every moment
Hope that my question is clear
What do you mean by dynamic ?
@api.depends('start_date', 'date_now') def _get_duration(self): for r in self: if r.start_date and r.date_now: dt = r.start_date ft = r.date_now d1 = datetime.strptime(dt, "%Y-%m-%d %H:%M:%S").date() d2 = datetime.strptime(ft, "%Y-%m-%d %H:%M:%S").date() rd = relativedelta(d2, d1) date_now = fields.Datetime('Date', default=fields.Datetime.now)