我有这个方法:
@api.multi
def update_url(self):
data = self.env['wizard.seniat.url'].read()
url_obj = self._get_url()
url_obj.write(
{'name': data['url1'],
'url_seniat': data['url2'],
'url_seniat2': data['url3']})
return {}
这是一个按钮,每当我点击它时,它就会抛出这个:
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 866, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 681, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_url_seniat.py", line 77, in update_url
{'name': data['url1'],
TypeError: list indices must be integers, not str
这是我正在从v8迁移到v10社区的模块。
有什么想法吗?
修改
这是旧API的原始方法:
def update_url(self, cr, uid, ids, context=None):
data = self.pool.get('wizard.seniat.url').read(cr, uid, ids)[0]
url_obj = self._get_url(cr, uid, ids, context)
url_obj.write(
{'name': data['url1'],
'url_seniat': data['url2'],
'url_seniat2': data['url3']})
return {}
答案 0 :(得分:1)
使用read()是一种不好的做法。 read()用于Web服务调用 但在你自己的方法调用中你应该总是使用browse()。不只, 它允许更好的代码质量,但它也更好 性能
- read()为生成额外SQL查询的many2one字段调用name_get() 你可能不需要。 - browse()针对字段的预取和自动加载进行了优化。
在这里你应该尝试:
"&2&lThis is the &6&lString&f&l."
您可以参考odoo 10 basic ORM here