Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
7805 Widoki

On our Windows Server Odoo instance I use date.today() to set the default of the date to, well, today. However, this morning we realized that the date was off, but the date of the server was correct. I restarted the server and the date in Windows did NOT change, however, the Odoo module default date did. What gives?

The line of code is as follow (no errors though)
'order_date': fields.date(string='Date', default=date.today())

Awatar
Odrzuć
Najlepsza odpowiedź

The solution is to not call the function:

my_field = fields.Date(default=fields.Date.today)
Awatar
Odrzuć
Najlepsza odpowiedź

date.today() returns a value, so the python interpreter thinks that you want set a constant to default value.
Use lambda function to avoid this:

default =  lambda self: fields.Date.today()

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Even on a linux machine this happens. Maybe it's the version I am using, but updating the custom app date.today() requires a restart everytime.

Awatar
Odrzuć
Najlepsza odpowiedź

Check your Timezone configuration on users

Awatar
Odrzuć
Autor

That wasn't it. Timezones via Odoo and Windows machine all match. Now the date is staying the same as my restart date. Maybe it has something to do with the module being instantiated on that date.

Powiązane posty Odpowiedzi Widoki Czynność
8
maj 23
61348
DateTime Python Rozwiązane
4
lut 23
71721
1
maj 16
3876
python in v9 Rozwiązane
1
lis 15
5955
2
kwi 23
23341