Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
753 Vistas

Environment: I'm looking at 'check_in' and 'check_out' fields in 'hr.attendance' which are just basic fields.Datetime fields.

In its form view, they are also listed in <field> tags with no special widgets or anything.

I'm cloning odoo community edition and running odoo-bin on my local server.


Expectation: Every fields.Datetime is stored in UTC, and rendered in views depending on user's timezone settings. Thus when I export 'hr.attendance' records, the exported data should have UTC records for 'check_in' and 'check_out' regardless of my user timezone settings. However, when I change my user timezone settings, what I see in views should change.


Actual: Exported values change when I change user timezone settings. Views don't change Datetime values no matter how I change user timezone settings.


For example, when creating a new record for 'hr.attendance', the field 'check_in' will pick up a default Datetime value with 'default=fields.Datetime.now'. This displays the same time that I see on my local device. So I'd believe 'it displays the check-in time in views according to my timezone settings, and will store a different value matching UTC in the database.'


Am I just misunderstanding how Odoo treats Datetime?

Avatar
Descartar
Autor

Thanks DataInteger and Hybrosys for the answers and confirmation!

It indeed seemed like a cache/cookie/JS related issue. I tried log out, opened a new browser tab in incognito mode, accessed Odoo local server, logged in again, and the timezone settings for views and exports seem to work fine as expected now.

Mejor respuesta

Hi,


All Datetime fields in Odoo are stored in UTC in the database.


fields.Datetime.now() gives the current UTC time.


In form and list views, datetime fields are shown in the user's timezone.


When you change your user timezone, the displayed datetime values should also change.


A hard refresh is required after changing timezone for the change to take effect in views.


Exported datetime values (CSV/Excel) are converted to the user’s timezone, not exported in UTC.


If you change your timezone and export again, the exported datetime will be different — this is expected.


If datetime values in views do not change with timezone, it may be due to missing refresh or caching.


To get exported datetime values in UTC, you need to use a backend script or Odoo shell.



Hope it helps.   

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 25
2110
1
jul 25
1605
3
jun 25
826
1
abr 25
1400
0
ene 25
1307