Skip to Content
Menu
This question has been flagged
1 Reply
5773 Views

I am working in V8, and thus following the V8 API guide (https://media.readthedocs.org/pdf/odoo-new-api-guide-line/latest/odoo-new-api-guide-line.pdf) while trying to write a name_get function for my class.  The PDF says that you only need "self" as a parameter, like this:

def do_something(self):

When I try to run it, though, I get this error:

 Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 500, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 517, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 283, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 280, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 733, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/http.py", line 376, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/api.py", line 237, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/api.py", line 332, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/models.py", line 1754, in name_search
    return self._name_search(name, args, operator, limit=limit)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/api.py", line 235, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/api.py", line 464, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openerp-8.0_8a9027e-py2.7.egg/openerp/models.py", line 1767, in _name_search
    res = self.name_get(cr, access_rights_uid, ids, context)
TypeError: name_get() takes exactly 1 argument (5 given)


Does that mean that Odoo is still trying to pass in 5 arguments, when it calls the name_get method?

Avatar
Discard
Best Answer

Hello Jeff, effectively 'name_get' is a function that is originally defined to be invoked with either the old and the new API styles. In order to achieve this, the function definition is decorated with @api.multi.

Probably you're overriding 'name_get' in your new class without any decorator, please add the @api.multi decorator (as in the original definition) as there are a couple of places in the ORM where 'name_get' is still invoked with the old API style.

I hope this helps,

Marvin

Avatar
Discard
Author

Excellent, that did the trick! For others who may have the same issue, you will also need to add "from openerp import api" in order to use @api.multi

Related Posts Replies Views Activity
3
Feb 23
20640
1
Sep 23
835
3
Apr 19
2461
0
Mar 15
2755
0
Dec 24
30