Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
7855 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The solution is to not call the function:

my_field = fields.Date(default=fields.Date.today)
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Check your Timezone configuration on users

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
8
thg 5 23
61513
DateTime Python Đã xử lý
4
thg 2 23
71846
1
thg 5 16
3906
python in v9 Đã xử lý
1
thg 11 15
5995
2
thg 4 23
23406