Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
5792 Zobrazení

Hi dears odoo community,

please, is there a way to change the timezone infos to a specific datetime field on odoo, not to apply to all the context of current user, but to a specific one.

Because whene i try to change it via .replace(tzinfo) i got this error:

ValueError: Datetime field expects a naive datetime: 2020-12-18 14:36:06+00:00

and if i try to assign it using tostring method , i dont see any changes , value on database still on db and there is a difference between two value on the client and on the db,

rec.my_dt = fields.Datetime.to_string(rec.my_dt.astimezone(timezone('UTC')))

i want them two on utc.

thanks in advance.

Avatar
Zrušit

Have you found any solution?

Nejlepší odpověď

You can't do that on an Odoo Datetime field as they are stored based on UTC.

What you can do is to add another field to the model and store into this your expected Datetime, adding to it the hours of your timezone, knowing that for the system will still be an UTC value.

It should be something like this:

from datetime import timedelta
Class InheditedClass(models.Model):
   _inherited = 'inherited.class'
    my_datetime = fields.Datetime(string="My datetime")
    def my_logic(self):
       self.my_datetime = original_datetime + timedelta(hours=1) # change 1 with your hours
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
srp 21
6311
0
čvc 21
2645
3
kvě 18
7844
2
srp 25
2358
1
čvc 25
876