目标:“月份”字段将显示当前月份和上个月,直到第10个 当前月份,第11天只会显示当前月份的选项。
我一直在寻找类似问题的问题,并尝试了所有可能的方法,所以这是到目前为止我已经尝试过的方法-
.py
MONTH_LIST = [
('january','JANUARY'),
('february','FEBRUARY'),
('march','MARCH'),
('april','APRIL'),
('may','MAY'),
('june','JUNE'),
('july','JULY'),
('august','AUGUST'),
('september','SEPTEMBER'),
('october','OCTOBER'),
('november','NOVEMBER'),
('december','DECEMBER')
]
def _get_month(self, cr, uid, ids, field_name, arg, context=None):
val = {}
date_now = datetime.datetime.now()
day = date_now.day
month = date_now.month
if day<10:
val['month_val'] = MONTH_LIST[month-1][1] + MONTH_LIST[month-2][1]
else:
val['month_val'] = MONTH_LIST[month-1][1]
return val
'month_val': fields.function(_get_month, string='Month', type='selection', selection=MONTH_LIST, required=True),
追踪-
2019-06-07 12:51:43,029 20396 INFO expensetest werkzeug: 127.0.0.1 - - [07/Jun/2019 12:51:43] "GET /web/binary/image?model=hr.employee&field=image_medium&id=283 HTTP/1.1" 200 -
2019-06-07 12:51:43,109 20396 INFO expensetest werkzeug: 127.0.0.1 - - [07/Jun/2019 12:51:43] "POST /web/dataset/call_kw/hr.expense.expense/fields_view_get HTTP/1.1" 200 -
2019-06-07 12:51:43,121 20396 INFO expensetest werkzeug: 127.0.0.1 - - [07/Jun/2019 12:51:43] "GET /web/binary/image?model=hr.employee&field=image_medium&id=257 HTTP/1.1" 200 -
2019-06-07 12:51:43,128 20396 INFO expensetest werkzeug: 127.0.0.1 - - [07/Jun/2019 12:51:43] "GET /web/binary/image?model=hr.employee&field=image_medium&id=265 HTTP/1.1" 200 -
2019-06-07 12:51:43,187 20396 INFO expensetest werkzeug: 127.0.0.1 - - [07/Jun/2019 12:51:43] "GET /web/binary/image?model=hr.employee&field=image_medium&id=217 HTTP/1.1" 200 -
2019-06-07 12:51:43,404 20396 ERROR expensetest openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 530, in _handle_exception
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 567, in dispatch
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 303, in _call_function
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\service\model.py", line 113, in wrapper
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 300, in checked_call
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 796, in __call__
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 396, in response_wrap
File "C:\Program Files\Odoo 8.0-20150515\server\openerp\addons\web\controllers\main.py", line 876, in search_read
File "C:\Program Files\Odoo 8.0-20150515\server\openerp\addons\web\controllers\main.py", line 897, in do_search_read
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\http.py", line 901, in proxy
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\api.py", line 241, in wrapper
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\models.py", line 5144, in search_read
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\api.py", line 241, in wrapper
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\models.py", line 3139, in read
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\api.py", line 239, in wrapper
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\models.py", line 3174, in read
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\api.py", line 239, in wrapper
File "C:\Program Files\Odoo 8.0-20150515\server\.\openerp\models.py", line 3355, in _read_from_database
KeyError: 1479
谢谢您的支持。
答案 0 :(得分:1)
不幸的是,您无法在Odoo中执行此操作,所选内容的值是在Odoo启动时创建的,因此无法对其进行修改。
选择填满选择之后,就无法更改。
尝试使用many2one
可以动态更改域,即使使用many2one
,也可以使用widget="selection"
更改域时会遇到问题两次访问该字段以查看列表已更改。