Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
4 Respostas
7820 Visualizações

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())

Avatar
Cancelar
Melhor resposta

The solution is to not call the function:

my_field = fields.Date(default=fields.Date.today)
Avatar
Cancelar
Melhor resposta

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()

Avatar
Cancelar
Autor Melhor resposta

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.

Avatar
Cancelar
Melhor resposta

Check your Timezone configuration on users

Avatar
Cancelar
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.

Publicações relacionadas Respostas Visualizações Atividade
8
mai. 23
61379
4
fev. 23
71748
1
mai. 16
3888
python in v9 Resolvido
1
nov. 15
5974
2
abr. 23
23359