Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Postgres Datetime field into Odoo Datetime field

I am trying to display set time of Postgres database time to datetime field into Odoo.

I am creating field is that to set the time.

last_modify_article = fields.Datetime("Last Modify Date")

But my DateTime :~ 2017-08-28T08:43:56+0200 is perfectly stored in Postgres database but in Odoo saw in different.

So, my question is that how can I manage the database date-time in the field.

Here is the Postgres Time

And

Here is Odoo field to set datetime in UTC

like image 664
Harshit Trivedi Avatar asked Aug 28 '17 09:08

Harshit Trivedi


2 Answers

Actually the database stores the Datetime field according to the system timezone. In Odoo, views which will be automatically converted according to the user's timezone if it is set.

On your images, I can see the time difference id +5:30 ie, Asia/Kolakata timezone. So your custom operations on Datetime field need the proper conversion of Timezone according to the user.

Odoo views and ORM methods are treated the tz with moment.js and the pytz conversions. This is actually a good feature to manage different timezones in Odoo.

You can use astimezone on Datetime objects:

def astimezone(self, tz): # known case of datetime.datetime.astimezone
    """ tz -> convert to local time in new timezone tz """
    return datetime(1, 1, 1)

or

fields.Datetime.context_timestamp(self, datetime.strptime(value, DEFAULT_SERVER_DATETIME_FORMAT))
like image 135
Hilar AK Avatar answered Oct 18 '22 09:10

Hilar AK


Odoo is designed to have the date and time stored as UTC in the database and convert it to the user's timezone on the front-end.

What time zone is set for your user? You can click your name in the top right, then Preferences. Time zone should be shown on the popup form.

like image 45
travisw Avatar answered Oct 18 '22 09:10

travisw