OD222 check-company-without-company¶
A field sets check_company to a comodel without company_id.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Warning, Error from saas~16.4 | saas~12.5 and later | yes |
What it reports¶
A Many2one, One2many or Many2many with check_company=True whose comodel has no
company_id field and gives no _check_company_domain of its own, by a method or by assigning a
function. From 18.0, only a field Odoo builds a company domain for is reported: on a model with
a company_id or company_ids field, on res.company, or a company-dependent field. A field is
reported once per module, at the check_company of its last definition in the module that gives
it.
Why it matters¶
check_company limits the records a field may point to to those of its record's companies. Odoo
writes that limit with the comodel's _check_company_domain, which unless the comodel overrides it
filters on the comodel's company_id. From saas~16.4, Odoo adds this domain to the field's
domain on every model, whatever _check_company_auto says, so the domain names a field the comodel
does not have: the client sends it with every search the field makes, such as the suggestions of a
Many2one input, and the server refuses it as an invalid field. From 18.0, Odoo adds it only to a
field on res.company, on a model with a company_id or company_ids field, or that is
company-dependent. The rule reports an error from saas~16.4.
From saas~12.5 to saas~16.3 it reports a warning: there the option asks that the comodel's records
belong to the record's companies, and a comodel without company_id has no company to compare, so
the option checks nothing. The company check Odoo runs on create and write of a model with
_check_company_auto skips such a field, so it never fails on it (13.0 odoo/models.py:3209). Odoo
also builds a company_id domain there for a field with no domain of its own, which the server
refuses the same way, but the rule does not tell those fields apart and warns on every one. Remove
check_company, or give the comodel a company_id.
From 18.0, a model with neither company_id nor company_ids, that is not res.company, gets no
company domain: Odoo logs that it cannot build one, and this rule does not report that. Neither
does it report a related field, or a comodel whose company_id is defined by a module outside the
dependencies.
The rule does not run for a module when the module or one of its dependencies depends on a module
that is not indexed. A model or comodel is skipped when the class that introduces it, with _name
or as a class Odoo names, is in a module outside the dependencies, or when a class of it, or of a
model it inherits or delegates to, has a plain Python base class or an _inherit element that is
not a literal, a parent whose fields and methods the scan cannot see. A module that Odoo always
installs with base, such as web, counts as in depends.
Example¶
class ParcelDepot(models.Model):
_name = "parcel.depot"
_description = "Parcel depot"
company_id = fields.Many2one("res.company")
industry_id = fields.Many2one("res.partner.industry", check_company=True)
class ParcelDepot(models.Model):
_name = "parcel.depot"
_description = "Parcel depot"
company_id = fields.Many2one("res.company")
industry_id = fields.Many2one("res.partner.industry")