Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

datetime now

By
badr elmar
on 4/6/16, 12:47 PM 476 views

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 ?

Yurdik Cervantes Mendoza
on 4/7/16, 9:57 AM

@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)

badr elmar
on 4/7/16, 11:43 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/6/16, 12:47 PM
Seen: 476 times
Last updated: 4/7/16, 11:51 AM