Trợ giúp

3

Time Zone Problem in odoo

Avatar
Hilar Andikkadavath

I can see so many topics regarding timezone, still, it's not clear about its manipulations on odoo. And also need clarifications for the system behavior for portal users.
NB: - Psql stores DateTime in UTC

1 Bình luận
Ảnh đại diện
Huỷ bỏ
Avatar
Hilar Andikkadavath
-
Yes, you are right. We disscussed the same in the above. Datetime data in db is stored in and according to the users timezone it will get automatically converted and by this way we can handle users from different timezones. While loading the view odoo is actually adding tz context with the stored data. No need of any extra configurations to manage account and reports. 

On Fri, 30 Aug 2019, 11:02 pm Dmitry Somov, <dmitry.somov@gmail.com> wrote:

A new answer on Time Zone Problem in odoo has been posted. Click here to access the post :

See post

Sent by Odoo S.A. using Odoo.

8 Câu trả lời
7
Best Answer

Hilar,

Yes, system (database) captures time in UTC format just because odoo allows users to login from anywhere in the world and every person belongs to different country have different timezone.

So, odoo evaluates the time based on the logged in user's timezone. If you don't know about how to set the timezone in users, you can go user's form either from preferences or from setting open the particular user from which you are trying to logged in. system (odoo) will display time according to your (user's) set timezone.

Hope this answer may help you to more clear about timezone.

Regards,

Anil.

4 Bình luận
Ảnh đại diện
Huỷ bỏ
Avatar
Hilar Andikkadavath
-

I know This and I mentioned that in question, thats only applicable on which user is using the orm methods, what is the case of public, and if you are fetching datas through query? Next case is for portal users, some times you have to fetch data as SUPERUSER and you can display data as in format of SUPERUSER TZ

If you want to display the datetime info on website, you need to convert the manually in localise format. you can pytz lib to customise this.

This e.g. may help you.

from datetime import datetime

import pytz

user_tz = self.env.user.tz or pytz.utc

local = pytz.timezone(user_tz)

display_date_result = datetime.strftime(pytz.utc.localize(datetime.strptime(your_date_or_datetime_info, DEFAULT_SERVER_DATETIME_FORMAT)).astimezone(local),"%d/%m/%Y %H:%M%S")

try this.

Avatar
Hilar Andikkadavath
-

orm methods returns datetime data according to the users zone. Other cases I used momentJs. above method is also good

@hilar, that's great if you can use momentJs.

0
Avatar
Ali mughal
Best Answer

In my scenario, I want to subtract two dates but when I fetch the date it gives me UTC time and date.  

#first import this library
from pytz import timezone
#convert the date string into object
now_utc_date=datetime.strptime(now_utc,"%Y-%m-%d %H:%M:%S")
print('utc date and time', now_utc_date)
# now i am changing timezone
now_dubai = now_utc_date.astimezone(timezone('Asia/Dubai'))
print('converted time',now_pacific.strftime("%Y-%m-%d %H:%M:%S")) I hope this code resolve the error
Ảnh đại diện
Huỷ bỏ
0
Avatar
Dmitry Somov
Best Answer

It has been discussed in the community for a while:
https://www.odoo.com/forum/help-1/question/time-zone-problem-in-odoo-118905
https://www.odoo.com/forum/help-1/question/user-timezone-not-applied-to-report-filters-9478
In my opinion there is a logic behind the default treatment of timezones in Odoo:
1) Transactions are recorded with UTC timestamp for all users (server time is UTC)
2) Transactions are displayed to users in their timezone (UTC +TZ delta)

Impacts:
1) For two users working in various timezones to have identical reports requires setting their time to UTC
2) Some transactions recorded same day (late hours) in Western timezones will be timestamped next day on server and will be shown in the reports for next day
3) Some transactions recorded same day (early hours) in Eastern timezones will be timestamped previous day on server and will be shown in the reports for previous day
4) Reports which do not take time as a parameter (only day) will be shown identical to all users. Some transactions from Western timezones day ends (local time) and Eastern timezones day starts (local time) won’t be shown.

Conclusion:
Accountants should be aware of this behavior and should setup their policies respectively:
1) For the reports taking DAY AND TIME as parameters they should login under a UTC-USER
2) For the reports taking only DAY as a parameter they may login either under a LOCAL TIMEZONE USER or under a UTC-USER

Ảnh đại diện
Huỷ bỏ