Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 39 ยท Projects and Practice

Odoo Practice Exercises and Interview Questions

Test your Odoo knowledge with views, security, reports, API and deployment exercises, plus common interview questions with short answers and runnable Python practice tasks.

You have now met views, QWeb, security, reports, integration, deployment and inheritance. This final lesson turns that knowledge into practice: hands-on exercises you can run in your browser, a set of frequent interview questions with short answers, and a checklist for reviewing Odoo code.

The Odoo features themselves cannot run on this site. The exercises therefore train the logic (domains, access, inheritance, routing) in plain Python, and you should then repeat each idea in a real Odoo instance. Starting from the Community edition on your computer or a free trial database is enough.

Exercise 1: write a domain filter

Given these records, write the list of books that are available and cheap, or lost. Use the same operators as in List, Search and Kanban Views. Try to solve it before running the answer; the evaluator below is compact so you can change the domain and see the result.

Python Exercise: domains

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the | takes the next two terms, and the first term is itself an &. Reading prefix notation is a skill you gain by practice.

Exercise 2: access resolution

Four groups, one user. Decide whether the user can write on library.loan, then check with the code. Remember that rights add up across groups, and implied groups count (Access Rights with ir.model.access).

Python Exercise: effective rights

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 3: predict the inheritance result

An extension view runs <xpath expr="//field[@name='isbn']" position="before"> with <field name="shelf"/>, and another module then runs position="replace" on isbn with <field name="barcode"/>. In what order do the fields end up in the form, name, isbn? Work it out on paper, then check using the idea from Customising with View and Model Inheritance: the first patch inserts shelf before isbn, the second replaces isbn in place. Result: name, shelf, barcode.

Exercise 4: harden a route

This controller has three problems: a public route reading a record by ID with sudo(), csrf=False and a raw SQL string. Rewrite it using the safety rules from Controllers and HTTP Routes and Field Security, sudo and Safe Coding.

Python
@http.route("/library/loan/<int:loan_id>", type="http", auth="public", csrf=False)
def loan_page(self, loan_id, q=None, **kw):
    request.env.cr.execute("SELECT id FROM library_loan WHERE note = '%s'" % q)
    loan = request.env["library.loan"].sudo().browse(loan_id)
    return request.render("library.loan_page", {"loan": loan})

A good answer: use auth="user" (or an access token for public links), remove csrf=False for a read-only GET (it only matters for POST anyway), check the loan belongs to the user's partner, drop the raw SQL in favour of search([("note", "=", q)]), or pass q as a parameter, and avoid sudo() for the read.

Exercise 5: model the XML-RPC call

Write the argument list for execute_kw that searches loans where the state is open, returns only book_id and date_due, sorted by due date, with at most 20 rows. Check the idea with the standard library:

Python Exercise: build the execute_kw arguments

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Frequently asked interview questions

What is the difference between _name and _inherit? _name defines a model's technical name. With _inherit alone you extend the existing model in place; with both, you create a new model copying the parent's fields.

What are sudo(), with_user() and with_context()? They change the environment of a recordset: superuser mode (no access checks), another user's rights, and extra context values.

Explain @api.depends, @api.onchange and @api.constrains. depends declares what a computed field depends on so Odoo recomputes it; onchange updates form values interactively in the browser only (not for imports or API calls); constrains validates data on create and write on the server.

How do access rights differ from record rules? Access rights (ir.model.access) are per model and per operation; record rules (ir.rule) filter which records. A user needs both. Global rules are ANDed; group rules are ORed.

How is a view modified by another module? Through an inheriting ir.ui.view with inherit_id and an xpath or shorthand node with a position.

What is QWeb? Odoo's XML template engine, used for reports, emails, website pages and kanban cards. t-out escapes; t-call composes templates.

How do you make a scheduled job? An ir.cron record that calls a model method with an interval; the method runs with superuser rights and under time limits.

How do you connect another system? XML-RPC or JSON-RPC with an API key on a dedicated user, or custom controllers for special endpoints.

What is the filestore? The folder where Odoo keeps attachments and images; it must be backed up with the database.

Why do -u module and a restart differ? A restart reloads Python code; -u also reloads XML and CSV data and updates the database schema.

What changed around Odoo 17 and 18? attrs was replaced by direct invisible, readonly and required expressions (17), the <tree> tag became <list> and some method names such as check_access_rights were consolidated (18). Always check the release notes for your version.

Code review checklist

  1. Does every new model have access rows and, if needed, record rules?
  2. Are sudo() calls minimal, with checks before them?
  3. Are values in raw SQL parameterised?
  4. Are views inherited with named xpath expressions rather than positions?
  5. Are depends and the manifest order correct?
  6. Is business logic in the model rather than only in invisible and required view attributes?
  7. Are reports, emails and cron jobs tested on a staging copy?
  8. Is there a restore-tested backup before the deployment?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A user in group A has an access row allowing read, and a user in group B has one allowing write. A user in both groups can...

    Model access rights are additive across groups; there are no deny rows.
  2. 2. Which tool validates data for imports and API writes, not just interactive forms?

    constrains runs on the server for create and write, whatever the source; onchange only runs in forms.
  3. 3. What is the safest way to inject a user-supplied value into raw SQL in Odoo?

    Parameters are quoted by the driver, preventing injection.
  4. 4. After you change only an XML view file of an installed module, what must you do?

    XML data is loaded at install or update time; --dev=xml reloads it automatically in development only.

Summary

  • Practise domains, group-based access, inheritance results and safe routes until you can do them without notes.
  • Know the difference between _name/_inherit, access rights/record rules, onchange/constrains and restart/-u.
  • Use the review checklist before releasing a module.
  • Keep building: extend the Library and Helpdesk projects with your own features.

Next: back to the Odoo track page