NeoVe
NeoVe

Reputation: 3897

TypeError: _get_loc_req() takes at least 3 arguments (1 given) - Odoo v8 to Odoo v10 community

I have this method:

@api.multi
def _get_loc_req(self, cr, uid, context=None):
    """Get if a field is required or not by a Localization
    @param uid: Integer value of the user
    """
    context = context or {}
    res = True
    ru_brw = self.pool.get('res.users').browse(
        cr, uid, uid, context=context)
    rc_obj = self.pool.get('res.company')
    rc_brw = rc_obj.browse(cr, uid, ru_brw.company_id.id, context=context)

    if rc_brw.country_id and rc_brw.country_id.code == 'VE' and \
            rc_brw.printer_fiscal:
        res = False
    return res

Every time I click on the button which calls for this function, it throws me this:

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 862, in call_kw
return self._call_kw(model, method, args, kwargs)
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 679, in call_kw
return call_kw_model(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 664, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/account/models/account_invoice.py", line 342, in create
invoice = super(AccountInvoice, self.with_context(mail_create_nolog=True)).create(vals)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/mail/models/mail_thread.py", line 227, in create
thread = super(MailThread, self).create(values)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3778, in create
vals = self._add_missing_default_values(vals)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 1618, in _add_missing_default_values
defaults = self.default_get(list(missing_defaults))
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 1101, in default_get
defaults[name] = field.default(self)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/invoice.py", line 61, in <lambda>
default=lambda s: s._get_loc_req(),
TypeError: _get_loc_req() takes at least 3 arguments (1 given)

As I've said, I'm migrating some modules from v8 to v10 community, should I also change the arguments? Besides adding the correct decorator?

The decorator @api.multi was added by me, since this method operates on records, but maybe it is incorrect?

Upvotes: 1

Views: 320

Answers (1)

CZoellner
CZoellner

Reputation: 14778

Button methods should look like:

@api.multi
def my_method(self):
    # my logic
    return True

There is no need to handle database cursor, record ids, user id and context "manually" anymore with the new API.


With old API your method should have failed too or the context was filled with ids. It should've looked like:

def _get_loc_req(self, cr, uid, ids, context=None):

You have just missed the ids.

Upvotes: 1

Related Questions