Skip to content

no-write-in-compute (ODOO040)

Preview (since 0.16.2.2) · Related issues · View source

Derived from the odoo linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for self.write(...) calls inside compute methods.

Why is this bad?

Writing from a compute method triggers the full write path (constraints, recomputes, audit fields) and can recurse; assigning via update (or plain field assignment) is the supported way to set values from a compute.

Example

def _compute_total(self):
    self.write({"total": 10})

Use instead:

def _compute_total(self):
    for record in self:
        record.update({"total": 10})