我有这个功能,我将从v8迁移到v10
def search_partner_seniat(self, cr, uid, ids, context=None):
""" Check vat of the partner and update iva rate
"""
if context is None:
context = {}
this = self.browse(cr, uid, ids)[0]
su_obj = self.env('seniat.url')
rp_obj = self.env('res.partner')
vat = this.vat.upper()
res = {'name': _('The requested contributor does not exist'),
'vat_subjected': False, 'vat': vat, 'wh_iva_agent': False,
'wh_iva_rate': 0.0}
if 'VE' in vat:
vat = vat[2:]
if rp_obj.check_vat_ve(vat, context=context):
res = su_obj._dom_giver(cr, uid, vat, context)
self.write(cr, uid, ids, res)
return {
'type': 'ir.actions.act_window',
'res_model': 'search.info.partner.seniat',
'view_mode': 'form',
'view_type': 'form',
'res_id': this.id,
'views': [(False, 'form')],
'target': 'new',
}
如何以新的API方式返回此内容?
这是追溯:
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/server.py", line 246, in app
return self.app(e, s)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/wsgi_server.py", line 184, in application
return application_unproxied(environ, start_response)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/wsgi_server.py", line 170, in application_unproxied
result = handler(environ, start_response)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 1306, in __call__
return self.dispatch(environ, start_response)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 1280, in __call__
return self.app(environ, start_wrapped)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/werkzeug/wsgi.py", line 588, in __call__
return self.app(environ, start_response)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 1454, in dispatch
odoo.registry(db).check_signaling()
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/__init__.py", line 55, in registry
return modules.registry.Registry(database_name)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/registry.py", line 55, in __new__
return cls.new(db_name)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/registry.py", line 78, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/loading.py", line 333, in load_modules
force, status, report, loaded_modules, update_module)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/loading.py", line 235, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/loading.py", line 135, in load_module_graph
registry.setup_models(cr, partial=True)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/registry.py", line 296, in setup_models
model._setup_complete()
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 2860, in _setup_complete
cls._init_constraints_onchanges()
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 652, in _init_constraints_onchanges
cls.pool._sql_error[cls._table + '_' + key] = msg
TypeError: cannot concatenate 'str' and 'function' objects
有什么想法吗?
答案 0 :(得分:1)
如果您确实想使用新API,请完整迁移代码。对于你的方法,它应该是:
@api.multi
def search_partner_seniat(self):
""" Check vat of the partner and update iva rate
"""
self.ensure_one()
vat = self.vat.upper()
res = {
'name': _('The requested contributor does not exist'),
'vat_subjected': False,
'vat': vat,
'wh_iva_agent': False,
'wh_iva_rate': 0.0
}
if 'VE' in vat:
vat = vat[2:]
# assumption: both methods in new api style
if self.env['res.partner'].check_vat_ve(vat): # check_vat_ve() should be @api.model
res = self.env['seniat.url']._dom_giver(vat) # _dom_giver() should be @api.model
self.write(res)
return {
'type': 'ir.actions.act_window',
'res_model': 'search.info.partner.seniat',
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'views': [(False, 'form')],
'target': 'new',
}