This question has been flagged
1 Reply
6556 Views

Odoo Version: 10 community

Model:

class TodoTask(models.Model):
    _name  = "todo.task"
    _description = "To-do Task"

    name = fields.Char('Description', required=True)
    is_done = fields.Boolean('Done?')
    active = fields.Boolean('Active?', default=True)
     
     @api.multi
     def do_toggle_done(self):
        for task in self:
            task.is_done = not task.is_done
            return True

@api.model
def do_clear_done(self):
      dones = self.search([('is_done', '=', True)])
         dones.write({'active': False})
    return True

do_toggle_done method working perfectly.

But the problem is with do_clear_done method. It shows the following error

2017-10-08 01:48:00,011 8694 ERROR todo odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 640, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 677, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-10.0/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 935, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-10.0/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 889, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo-10.0/addons/web/controllers/main.py", line 877, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo-10.0/odoo/api.py", line 687, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/opt/odoo/odoo-10.0/odoo/api.py", line 670, in call_kw_model
    recs = self.with_context(context or {})
  File "/opt/odoo/odoo-10.0/odoo/models.py", line 4889, in with_context
    context = dict(args[0] if args else self._context, **kwargs)
TypeError: cannot convert dictionary update sequence element #0 to a sequence
Avatar
Discard
Author

Problem solved!! Thanks @Hiar

Best Answer

Make the @api.model decorator to @api.multi or @api.one . and hope the second function is in outside. @api.model decorator is only applicable for the cases if we don't know the id, is to be created. Here in @api.model self is a recordset, but its contents is not relevant,

Avatar
Discard