Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Error in new API name_get function?

By
Jeff Beidler
on 11/7/14, 12:33 PM 1,575 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?

1
Marvin Taboada
On 11/7/14, 5:01 PM

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

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

Jeff Beidler
on 11/7/14, 5:49 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/7/14, 12:33 PM
Seen: 1575 times
Last updated: 8/12/15, 10:48 AM