Odoo Code Audit · Checklist
Odoo Custom Module Health Checklist
28 risk patterns that make custom Odoo modules unsafe, slow or hard to upgrade. Each one is tagged for Odoo 17, 18 and 19, with why it matters, how to detect it, how to fix it, and the Odoo source file that proves the claim.
Mohamed Magdy, Founder & Senior Odoo Engineer · November 22, 2026
This checklist lists 28 patterns that make a custom Odoo module unsafe, slow, or expensive to upgrade. They show up most in modules written quickly, with or without AI tools: the code installs, the demo works, and the problem appears in production or at the next upgrade. Each item says which Odoo versions it applies to, why it matters, how to find it, and how to fix it.
Every version-specific claim was checked against the Odoo 17.0, 18.0 and 19.0 source code on 22 November 2026. Each item names the file and function, so you can check it yourself. Items marked Sample report are reproduced on a purpose-built demo module in the sample audit report, with a test that proves each one.
How to read the version tags
Versions lists the Odoo releases where the pattern is a problem. “17, 18, 19” means the risk is the same on all three. “Breaks on 18 and 19” means the code works on 17 and fails after an upgrade. Paths are relative to the Odoo source tree: odoo/models.py in 17 and 18 became odoo/orm/models.py in 19.
On this page:
- Security and access rules (items 1–8)
- Data integrity (items 9–14)
- Performance (items 15–17)
- Upgrade safety: 17 to 18 and 19 (items 18–26)
- Dead code and tests (items 27–28)
Security and access rules
1. Public routes that read with sudo()
Versions: 17, 18, 19 · Sample report: F01
A route with auth="public" runs for visitors who are not logged in, and sudo() skips access rights and record rules. Together they hand every record the query returns to anyone with the URL.
Detect: search the controllers for auth="public" and auth='none', then read each handler for .sudo().
Fix: require a login, and let access rights and record rules do their job. If a public page really needs data, sudo() with a domain that limits the result to what that visitor may see, and return only the fields you mean to publish.
# Before: any visitor gets every commission line
@http.route("/commission/stats", type="http", auth="public", csrf=False)
def stats(self):
lines = request.env["commission.line"].sudo().search([])
# After: logged-in users only; access rights and record rules apply
@http.route("/commission/stats", type="http", auth="user", methods=["GET"])
def stats(self):
lines = request.env["commission.line"].search([])
Source: odoo/http.py → route() (the auth parameter); record rules are skipped under superuser in odoo/models.py → BaseModel._apply_ir_rules() (17, 18) and odoo/orm/models.py → BaseModel._search() (19).
2. SQL built with string formatting
Versions: 17, 18, 19 · Sample report: F02
Formatting a request parameter into SQL text lets the caller rewrite the query. In the sample report, ?login=nobody' OR '1'='1 returns every salesperson’s total to an anonymous visitor.
Detect: search for cr.execute( and read each call for % formatting, .format( or f-strings that include a variable.
Fix: use the ORM. When you need SQL, pass values as parameters, or build the query with odoo.tools.SQL, which keeps the code and the values apart. It exists in 17, 18 and 19.
# Before
self.env.cr.execute("SELECT id FROM res_users WHERE login = '%s'" % login)
# After
from odoo.tools import SQL
self.env.cr.execute(SQL("SELECT id FROM res_users WHERE login = %s", login))
Source: odoo/tools/sql.py → class SQL; odoo/sql_db.py → Cursor.execute() accepts an SQL object.
3. Access rights that give every employee full control
Versions: 17, 18, 19 · Sample report: F03
A line like base.group_user,1,1,1,1 in ir.model.access.csv lets every internal user create, change and delete the model’s records, including users with no role in that app. In the sample report, any salesperson can raise their own commission rate.
Detect: grep -n "base.group_user,1,1,1,1" */security/ir.model.access.csv
Fix: grant read access to the app’s user group and full access to its manager group.
access_commission_rule_salesman,commission.rule salesman,model_commission_rule,sales_team.group_sale_salesman,1,0,0,0
access_commission_rule_manager,commission.rule manager,model_commission_rule,sales_team.group_sale_manager,1,1,1,1
Source: odoo/addons/base/models/ir_model.py → IrModelAccess.check().
4. Models with no access rights at all
Versions: 17, 18, 19
A model without access rights can only be used as superuser. The usual workaround is sudo() everywhere, which turns a missing rule into an open door. Odoo warns about it at install time.
Detect: install the module on a test database and look for this log line: The models [...] have no access rules in module <name>, consider adding some, like:
Fix: add an ir.model.access.csv row per model and group, as in item 3. Then remove the sudo() calls the missing rows made necessary.
Source: odoo/modules/loading.py → load_module_graph().
5. Per-user or per-company data without record rules
Versions: 17, 18, 19 · Sample report: F04
Access rights work per model; record rules decide which records a user sees. A model with a user_id or company_id and no record rule shows every salesperson every colleague’s records, and every company the other companies’ data.
Detect: for each model with user_id or company_id, look for an ir.rule on that model in the module’s security XML.
Fix: a rule per group, plus a global multi-company rule. company_ids is available in the rule’s evaluation context.
<record id="commission_line_rule_own" model="ir.rule">
<field name="name">Commission lines: own only</field>
<field name="model_id" ref="model_commission_line"/>
<field name="domain_force">[('user_id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
</record>
<record id="commission_line_rule_company" model="ir.rule">
<field name="name">Commission lines: multi-company</field>
<field name="model_id" ref="model_commission_line"/>
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
Source: odoo/addons/base/models/ir_rule.py → IrRule._eval_context() (user, company_ids).
6. Hiding a field in the view instead of restricting it
Versions: 17, 18, 19 · Sample report: F04, F11
invisible, column_invisible and leaving a field out of a view change what the screen shows. They don’t change what the server returns: the value still comes back through read, search_read, export and the JSON-RPC API.
Detect: look for fields hidden with a condition on the user’s groups, such as invisible="not is_manager", and for view rewrites that hide columns.
Fix: put groups= on the field definition. Odoo then removes the field from views for users outside the group and raises AccessError when they read it.
commission_total = fields.Float(
compute="_compute_commission_total", store=True,
groups="sales_team.group_sale_manager",
)
Source: odoo/models.py → BaseModel.check_field_access_rights() (17, 18), odoo/orm/models.py → BaseModel._check_field_access() (19); odoo/addons/base/models/ir_ui_view.py → _postprocess_access_rights().
7. csrf=False on routes that change data
Versions: 17, 18, 19
Odoo checks a CSRF token on every request that isn’t a safe method (GET, HEAD, OPTIONS, TRACE) unless the route sets csrf=False. On a POST route that changes data, csrf=False lets another website submit that request with your user’s session.
Detect: grep -rn "csrf=False" */controllers/ and check which of those routes accept POST and write data.
Fix: keep the default, and send the token from the form. For a webhook called by another system, check a shared secret or signature instead of a session.
<form method="post" action="/my/settings">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
</form>
Source: odoo/http.py → HttpDispatcher.dispatch() (routing.get('csrf', True)); Request.csrf_token().
8. t-raw and hand-built HTML in QWeb
Versions: 17, 18, 19
t-raw prints its value without escaping, so user-supplied text becomes HTML and script. Odoo 17, 18 and 19 log a warning for every t-raw they compile: Found deprecated directive @t-raw=... Replace by @t-out.
Detect: grep -rn "t-raw" */views/ */report/ */templates/, plus that warning in the install log.
Fix: use t-out, which escapes the value unless it is already a markupsafe.Markup object. Wrap a string in Markup only when you produced the HTML yourself.
Source: odoo/addons/base/models/ir_qweb.py → IrQWeb._compile_directive_raw().
Data integrity
9. Stored computed fields with missing dependencies
Versions: 17, 18, 19 · Sample report: F05
Odoo recomputes a stored field only when a field listed in @api.depends changes. Anything the method reads but doesn’t declare leaves the stored value stale, and reports, filters and exports read that stale value.
Detect: compare every field path the compute method reads with its @api.depends. Then test it: change an input and read the field.
Fix: declare every field path the method reads.
# Before: recomputed only when the state changes
@api.depends("state")
def _compute_commission_total(self): ...
# After
@api.depends("amount_untaxed", "user_id", "company_id")
def _compute_commission_total(self): ...
Source: odoo/api.py → depends() (17, 18), odoo/orm/decorators.py → depends() (19).
10. cr.commit() inside business methods
Versions: 17, 18, 19 · Sample report: F06
Odoo runs each request in one transaction and commits once, after the method returns. A cr.commit() in the middle makes the work done so far permanent, even if the rest of the method fails. You get half-confirmed orders, duplicate lines on retry, and tests that can’t roll back.
Detect: grep -rn "cr.commit()" */models/ */controllers/ */wizard/
Fix: remove it. Keep explicit commits for long scheduled jobs that process batches and are written to resume safely after a failure.
Source: odoo/service/model.py → retrying(), which runs the request and commits at the end.
11. except Exception: pass
Versions: 17, 18, 19 · Sample report: F08
A broad except with pass turns every error into silence. In the sample report, a salesperson without a commission rule gets no commission line and nobody is told. After an upgrade to 19 the same except hides a crash, and no order gets a commission line at all. In PostgreSQL, a failed statement also aborts the whole transaction, so later queries fail with “current transaction is aborted” far from the cause.
Detect: grep -rnE "except( Exception)?:" -A1 . | grep -B1 "pass"
Fix: catch the specific exception you expect, report it to the user or the record’s chatter, and wrap database work that may fail in a savepoint.
try:
with self.env.cr.savepoint():
self.env["commission.line"].create(vals)
except ValidationError as error:
order.message_post(body=str(error))
Source: odoo/sql_db.py → BaseCursor.savepoint().
12. Reading records across companies
Versions: 17, 18, 19 · Sample report: F07
search([]) on a model with a company_id returns every company’s records when the code runs with sudo(), when the model has no multi-company record rule, or when the user works in several companies at once. In the sample report, a company A order takes its commission rate from a company B rule.
Detect: look for searches on company-dependent models without a company_id term, especially in sudo() code and scheduled jobs.
Fix: filter by the document’s company, set _check_company_auto = True with check_company=True on the relational fields, and add the global rule from item 5.
rule = self.env["commission.rule"].search([
("user_id", "=", order.user_id.id),
("company_id", "=", order.company_id.id),
], limit=1)
Source: odoo/models.py → BaseModel._check_company() and the _check_company_auto attribute (17, 18); odoo/orm/models.py (19).
13. ondelete chosen without thinking about the data
Versions: 17, 18, 19
Without an explicit ondelete, a required many2one gets restrict and an optional one gets set null. ondelete="cascade" on a link to master data deletes the dependent documents along with it. ondelete="set null" on a required field fails when the registry loads, with a ValueError.
Detect: grep -rn "ondelete=" */models/ and check each cascade points from a child line to its parent document.
Fix: cascade for true child lines (order lines, commission lines). restrict for references to customers, products, journals and other master data.
order_id = fields.Many2one("sale.order", required=True, ondelete="cascade") # child line
partner_id = fields.Many2one("res.partner", required=True, ondelete="restrict") # master data
Source: odoo/fields.py → Many2one.setup_nonrelated() (17, 18), odoo/orm/fields_relational.py → Many2one.setup_nonrelated() (19).
14. Hard-coded database IDs
Versions: 17, 18, 19
browse(1), [(6, 0, [3])] and IDs inside domains point at whatever record has that ID in this database. On a copy, a new install or after a migration, it is a different record or none at all.
Detect: grep -rnE "browse\([0-9]+\)|\(6, *0, *\[[0-9]" */models/ */data/
Fix: use XML IDs.
team = self.env.ref("sales_team.team_sales_department")
optional = self.env.ref("my_module.my_record", raise_if_not_found=False)
Source: odoo/api.py → Environment.ref() (17, 18), odoo/orm/environments.py → Environment.ref() (19).
Performance
15. Queries inside loops (N+1)
Versions: 17, 18, 19 · Sample report: F09
A search, search_count or browse(...).read() per record turns one list view into hundreds of queries. In the sample report, computing a count on 20 orders runs at least 10 more queries than on 10 orders.
Detect: read compute methods and loops for ORM calls on another model, and count queries in a test with self.env.cr.sql_log_count or assertQueryCount.
Fix: one grouped query for the whole recordset. _read_group(domain, groupby, aggregates) has this signature in 17, 18 and 19 and returns records as group keys.
counts = dict(self.env["commission.line"]._read_group(
[("order_id", "in", self.ids)], ["order_id"], ["__count"],
))
for order in self:
order.commission_count = counts.get(order, 0)
Source: odoo/models.py → BaseModel._read_group() (17, 18), odoo/orm/models.py → BaseModel._read_group() (19).
16. create() overridden one record at a time
Versions: 17, 18, 19 (breaks on 19) · Sample report: F10
@api.model def create(self, vals) handles one dict. On 17, Odoo logs The model ... is not overriding the create method in batch and calls the method once per record. On 18 it is a DeprecationWarning. On 19, @api.model on create is treated as @api.model_create_multi, so vals is a list and vals.get(...) raises AttributeError.
Detect: grep -rn -A1 "@api.model$" */models/ | grep "def create"
Fix:
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
vals.setdefault("state", "draft")
return super().create(vals_list)
Source: odoo/api.py → model() and model_create_single() (17, 18); odoo/orm/decorators.py → model() (19).
17. Searched fields without an index
Versions: 17, 18, 19
A field has no database index unless it declares one (index=None is the default). On a large table, a field used in domains, _order or record rules can then force a full table scan on every search.
Detect: list the fields your domains, rules and _order use on tables with many rows, then check \d table_name in psql or EXPLAIN the slow query.
Fix: index=True (B-tree), index="btree_not_null" when most values are empty, or index="trigram" for ilike searches on text.
reference = fields.Char(index="trigram")
user_id = fields.Many2one("res.users", index=True)
Source: odoo/fields.py → Field docstring, index parameter (17, 18); odoo/orm/fields.py (19).
Upgrade safety: 17 to 18 and 19
18. <tree> views and tree view modes
Versions: breaks on 18 and 19 · Sample report: F13, F15
18 renamed the list view type from tree to list. A module with <tree> views doesn’t install: 18 stops with Wrong value for ir.ui.view.type: 'tree' and 19 with Invalid view type: 'tree'. Actions returned from Python with "view_mode": "tree,form" also break, because 17 translated tree to list before sending the action to the browser and 18 doesn’t.
Detect: grep -rnE "<tree|view_mode.*tree" .
Fix: <list> and list everywhere once the module targets 18 or 19 (17 still needs tree).
<list editable="bottom">
<field name="name"/>
</list>
Source: odoo/addons/base/models/ir_ui_view.py → View.type selection; addons/web/controllers/utils.py → fix_view_modes() (17 only).
19. attrs and states in views
Versions: breaks on 17, 18, 19
Since 17, views use Python expressions in invisible, readonly and required. A view that still has attrs or states fails validation with Since 17.0, the "attrs" and "states" attributes are no longer used.
Detect: grep -rnE "attrs=|states=" */views/
Fix:
<!-- 16 and earlier -->
<button name="action_mark_paid" type="object" attrs="{'invisible': [('state', '=', 'paid')]}"/>
<!-- 17, 18, 19 -->
<button name="action_mark_paid" type="object" invisible="state == 'paid'"/>
Source: odoo/addons/base/models/ir_ui_view.py → View._check_xml().
20. name_get() overrides
Versions: ignored on 17, removed in 18 and 19 · Sample report: F12
17 computes display_name from _rec_name and no longer calls name_get(); calling it directly emits DeprecationWarning: Since 17.0, deprecated method, read display_name instead. 18 removed it. A name_get() override therefore changes nothing on 17 and later, and records without a name field show as commission.line,7.
Detect: grep -rn "def name_get" .
Fix:
@api.depends("order_id.name", "user_id.name")
def _compute_display_name(self):
for line in self:
line.display_name = f"{line.order_id.name} / {line.user_id.name}"
Source: odoo/models.py → BaseModel.name_get() and BaseModel._compute_display_name() (17).
21. user_has_groups()
Versions: breaks on 18 and 19 · Sample report: F14
self.user_has_groups(...) exists on 17 and is gone from 18. Any compute or button that calls it raises AttributeError. In the sample report, that error comes from a field on the sale order form, so no one can open a sale order.
Detect: grep -rn "user_has_groups" .
Fix: self.env.user.has_group("sales_team.group_sale_manager"), which exists in 17, 18 and 19. Better still, use groups= on the field (item 6).
Source: odoo/models.py → BaseModel.user_has_groups() (17 only); odoo/addons/base/models/res_users.py → Users.has_group().
22. group_operator on fields
Versions: deprecated on 18 and 19 · Sample report: F17
18 renamed the field parameter to aggregator. group_operator still works on 18 and 19, converted with DeprecationWarning: Since Odoo 18, 'group_operator' is deprecated, use 'aggregator' instead.
Detect: grep -rn "group_operator" */models/
Fix: rate = fields.Float(aggregator="avg") on 18 and 19.
Source: odoo/fields.py → Field._get_attrs() (18), odoo/orm/fields.py → Field._get_attrs() (19).
23. check_access_rights() and check_access_rule()
Versions: deprecated on 18 and 19
18 added check_access(operation), which checks the model’s access rights and the record rules on the records in one call. Both old methods warn deprecated since 18.0; use check_access() instead, and 19 marks them with @api.deprecated.
Detect: grep -rnE "check_access_(rights|rule)\(" .
Fix:
# 17
record.check_access_rights("write")
record.check_access_rule("write")
# 18, 19
record.check_access("write")
Source: odoo/models.py → BaseModel.check_access() (18), odoo/orm/models.py → BaseModel.check_access() (19).
24. read_group() in Python code
Versions: deprecated on 19
19 deprecates the public read_group(): Since 19.0, read_group is deprecated. Please use _read_group in the backend code or formatted_read_group for a complete formatted result.
Detect: grep -rn "\.read_group(" */models/ */controllers/
Fix: _read_group(domain, groupby, aggregates) in server code (item 15). It returns records and values instead of formatted dictionaries, so the code that reads the result changes too.
Source: odoo/orm/models.py → BaseModel.read_group() (19); addons/web/models/models.py → formatted_read_group() (19).
25. _sql_constraints
Versions: ignored on 19 · Sample report: F16
19 no longer reads _sql_constraints. It logs Model attribute '_sql_constraints' is no longer supported, please define model.Constraint on the model. and doesn’t create the constraint. Duplicates the constraint used to block are then accepted. No error, only a warning in the log.
Detect: grep -rn "_sql_constraints" */models/
Fix (19):
_user_company_uniq = models.Constraint(
"UNIQUE(user_id, company_id)",
"A salesperson can only have one commission rule per company.",
)
Source: odoo/orm/model_classes.py (the warning) and odoo/orm/table_objects.py → class Constraint (19).
26. Field and API renames in 19
Versions: breaks on 19
Code and XML that use the old names fail on 19:
| 17 and 18 | 19 |
|---|---|
groups_id on res.users, ir.ui.view, ir.ui.menu, window and server actions | group_ids |
res.groups.users | res.groups.user_ids |
@http.route(type="json") | type="jsonrpc" (json warns) |
self._context, self._uid | self.env.context, self.env.uid |
_context and _uid still work on 19 with a deprecation warning; the renamed fields don’t exist under their old names.
Detect: grep -rnE "groups_id|\.users\b|type=.json.|self\._context|self\._uid" .
Source: field definitions in odoo/addons/base/models/res_users.py, res_groups.py, ir_ui_view.py, ir_ui_menu.py and ir_actions.py (19); odoo/http.py → route() (19); odoo/orm/models.py → BaseModel._context and BaseModel._uid (19).
Dead code and tests
27. Overrides of methods the framework no longer calls
Versions: 17, 18, 19 · Sample report: F11, F12
BaseModel has no fields_view_get() in 17, 18 or 19; the web client loads views through get_views(). An override of fields_view_get() never runs, so whatever it was meant to do, such as hiding a column from some users, doesn’t happen. The same is true of name_get() from 18 (item 20).
Detect: for every method a module overrides, check that the parent class still defines it in the target version: grep -rn "def fields_view_get" . is a quick start.
Fix: delete the override and move the intent to what the version supports: groups= on the field for visibility, _compute_display_name for names.
Source: odoo/addons/base/models/ir_ui_view.py → get_views() (17, 18, 19); no fields_view_get in odoo/models.py (17, 18) or odoo/orm/models.py (19).
28. No tests for access rules and computed values
Versions: 17, 18, 19
Without tests, nothing tells you that a record rule stopped working or a stored value went stale after a change. Access rules and computed money fields need tests most, because their failures are silent.
Detect: look for a tests/ folder with tests that use with_user(), assertRaises(AccessError) and changed inputs on computed fields.
Fix: a TransactionCase per model that creates users with new_test_user(), checks what each group can read and write, and changes the inputs of every stored compute.
from odoo.exceptions import AccessError
from odoo.tests import TransactionCase, new_test_user
class TestCommissionAccess(TransactionCase):
def test_salesperson_cannot_change_rates(self):
alice = new_test_user(self.env, login="alice", groups="sales_team.group_sale_salesman")
rule = self.env["commission.rule"].create({"name": "Alice", "user_id": alice.id, "rate": 10})
with self.assertRaises(AccessError):
rule.with_user(alice).write({"rate": 50})
Source: odoo/tests/common.py → new_test_user(), TransactionCase.
What to do with the results
If your modules show several of these patterns, start with the security items (1–8) and anything that silently changes money or stock (9–12). Plan the upgrade items (18–26) before you start an upgrade, not during it.
The Odoo Code Audit applies this checklist to your modules with a senior engineer reading every line, and the sample report shows what you get. Planning a version move? See Odoo upgrades.