Odoo Time Showing in Form View does not match Time in Qweb Report – Timezone Mismatch

Synopsis

You are seeing a time in the Odoo form view, which is using the correct timezone, but when you try to download the report of the same form view data, you see, the timezone is changed to UTC or something else. How to fix this?

Solution

The issue appears when the user has configured a different timezone or has not, while the Odoo system uses a central timezone. Make sure to set the timezone for the user to same as the one Odoo uses. You may do so, from

Odoo >> Settings >> Users >> Select User >> Edit >> Preference >> Set Timezone

If this does not solve the problem, then the problem probably appears because Odoobot is set to use a different timezone, and your report is generated using ‘sudo()’ function. To set the timezone for Odoobot

Odoo >> Settings >> Users >> From the Filters, select ‘Inactive Users’ >> Click on Odoobot >> Edit >> Preference >> Set the Timezone

Hope this helps.

How to Set Timezone in Postgres Databases

Question: How to Set Timezone in Postgres Databases

Answer

Postgres allows you to set a timezone per database. To view the list of available timezones, you may use the following query from psql:

select * from pg_timezone_names;

To set a timezone for say a database called ‘inventory_report’, you may use the following query:

alter database inventory_report set timezone to 'Asia/Dhaka';

Tips:

To List Postgres Databases, you may use the following command from psql:

\l

To List Postgres Tables in a Database:

Connect to the database first:

\c my_prod

Now, list:

\dt

How to Set Timezone in LXC/LXD container CentOS 7

LXC should take the UTC as the default timezone for the guest. To set a custom timezone, you need to manually run this:

ln -sf /usr/share/zoneinfo/Asia/Dhaka /etc/localtime

In our case, we set the Asia/Dhaka as the default timezone. For Ubuntu based systems, you may use ‘tzdata’ package.

How to: Change Timezone in CentOS / RHEL 6 & CentOS / RHEL 7

How to change Timezone in CentOS 6 / RHEL 6

In CentOS 6, timezone files are located under /usr/share/zoneinfo. So, if your zone is for example, America/Chicago (UTC -6), it would be /usr/share/zoneinfo/America/Chicago and so on.

CentOS 6, uses a file called ‘localtime’ located under /etc to determine it’s currently set timezone.

# ls -la /etc/localtime

This file, is either the actual time zone file moved to this location or a symlink to the timezone under zoneinfo directory. So if you want to change the timezone, first you need to determine which timezone to use and then symlink it to localtime. You can do that using the following:

# rm -f /etc/localtime
# ln -s /usr/share/zoneinfo/Asia/Dhaka /etc/localtime
# date

This would set the current timezone to GMT +6 BDT or Asia/Dhaka timezone, zone I belong to.

How to change timezone in CentOS 7 or RHEL 7

CentOS 7, comes with a tool called ‘timedatectl’. This can be used to find and set the symlink for you instead of doing the work that were required in CentOS 6.

To list available time zones, run:

# timedatectl list-timezones

You can find your desired timezone, as following:

# timedatectl list-timezones | grep Chicago

Now, to set a time zone, use the command set-timezone with timedatectl command. For example, if I want to set the time zone to America/Chicago, I would run the following:

# timedatectl set-timezone America/Chicago
# date

This also should create the symlink of locatime file to the zoneinfo directory. You can see that with the following:

# ls -l /etc/localtime