Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
15614 Vizualizări
# -*- coding: utf-8 -*-
from odoo import models, fields, api
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
and getting Error is
Traceback (most recent call last): File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 638, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 675, in dispatch result = self._call_function(**self.params) File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 331, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/odoo10/odoo-dev/odoo/odoo/service/model.py", line 119, in wrapper return f(dbname, *args, **kwargs) File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 324, in checked_call result = self.endpoint(*a, **kw) File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 933, in __call__ return self.method(*args, **kw) File "/home/odoo10/odoo-dev/odoo/odoo/http.py", line 504, in response_wrap response = f(*args, **kw) File "/home/odoo10/odoo-dev/odoo/addons/web/controllers/main.py", line 882, in call_button action = self._call_kw(model, method, args, {}) File "/home/odoo10/odoo-dev/odoo/addons/web/controllers/main.py", line 870, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/odoo10/odoo-dev/odoo/odoo/api.py", line 679, in call_kw return call_kw_model(method, model, args, kwargs) File "/home/odoo10/odoo-dev/odoo/odoo/api.py", line 662, in call_kw_model recs = self.with_context(context or {}) File "/home/odoo10/odoo-dev/odoo/odoo/models.py", line 4865, in with_context context = dict(args[0] if args else self._context, **kwargs) TypeError: cannot convert dictionary update sequence element #0 to a sequence
Imagine profil
Abandonează

when is this function called ? 'do_clear_done'

Autor

yes @Hilar this happen when i call 'do_clear_done'

Cel mai bun răspuns

If that function is new you should use api.multi

Imagine profil
Abandonează
Autor

Thanks Esther Martin it's working...

but can you explain why it's not working with @api.model

why @api.model not working for this action even in code there is no loop.

why new function require @api.multi ??

You can found everything about api here: https://www.odoo.com/documentation/8.0/reference/orm.html

Anyways, for new functions, is always used multi.

Related Posts Răspunsuri Vizualizări Activitate
2
apr. 24
2051
0
mar. 19
3530
1
oct. 18
3018
0
mar. 17
3480
2
iul. 24
2173