تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
7817 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

The solution is to not call the function:

my_field = fields.Date(default=fields.Date.today)
الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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.

الصورة الرمزية
إهمال
أفضل إجابة

Check your Timezone configuration on users

الصورة الرمزية
إهمال
الكاتب

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.

المنشورات ذات الصلة الردود أدوات العرض النشاط
8
مايو 23
61377
DateTime Python تم الحل
4
فبراير 23
71745
1
مايو 16
3887
python in v9 تم الحل
1
نوفمبر 15
5969
2
أبريل 23
23357