Skip to content

OD107 api-multi-one-removed

@api.multi and @api.one no longer exist.

Category Severity Series Needs the index
Deprecation Error 13.0 and later no

What it reports

A method of a model class decorated with @api.multi or @api.one, in a module of series 13.0 or later.

Why it matters

Odoo 13.0 removed both decorators from odoo.api. Python applies a decorator when it reads the class, so the module raises AttributeError as soon as Odoo imports it: the module cannot be installed, and a database that already has it fails to start. Since 13.0 every method receives a recordset, which is what @api.multi declared, so dropping the decorator is enough. @api.one called the method once per record and collected the results in a list; replace it with a loop over self and return what the callers expect.

Modules of earlier series are not checked. Only the decorators written as api.multi and api.one are reported, not one imported under another name.

Example

models/project_task.py
class ProjectTask(models.Model):
    _inherit = "project.task"

    @api.multi
    def action_set_high_priority(self):
        self.write({"priority": "1"})

odoo.api has no multi from 13.0, so importing the file fails.

models/project_task.py
class ProjectTask(models.Model):
    _inherit = "project.task"

    def action_set_high_priority(self):
        self.write({"priority": "1"})

Fixing

oscn check --fix removes @api.multi with its line when nothing else is on the line, not even a comment. @api.one is left to rewrite by hand, since callers get a list from it.

See fixing findings.

Suppressing

@api.multi  # odooscan: ignore[OD107]

See suppressing a finding.