OD114 depends-on-id¶
@api.depends names the field id, which Odoo refuses.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Error | all | no |
What it reports¶
A string given to @api.depends that is id, or a dotted path with an id segment such as
partner_id.id.
Why it matters¶
api.depends raises NotImplementedError when one of its paths has an id segment, and a
decorator runs when Python reads the class. Importing the file fails, so the module cannot be
installed and a database that has it does not start. A record's id never changes once it exists,
so there is nothing to depend on: depend on the relational field itself, partner_id, which
covers a change of the record it points to.
Only literal strings are read; a function given to @api.depends is not. @api.onchange and
@api.constrains are not reported.
Example¶
models/sale_order.py
class SaleOrder(models.Model):
_inherit = "sale.order"
partner_ref = fields.Char(compute="_compute_partner_ref")
@api.depends("partner_id.id")
def _compute_partner_ref(self):
for order in self:
order.partner_ref = str(order.partner_id.id)
models/sale_order.py
class SaleOrder(models.Model):
_inherit = "sale.order"
partner_ref = fields.Char(compute="_compute_partner_ref")
@api.depends("partner_id")
def _compute_partner_ref(self):
for order in self:
order.partner_ref = str(order.partner_id.id)