An enterprise package's language: models, fields and queries

What you write when you program inside an enterprise package, using Odoo in Python as the example: models and fields (relations included), the four operations on records, recordsets and the prefix-notation filter.

  • 24 cards
  • 5 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. Understand

A few cards from the deck

  • ORM (object-relational mapping): what is it?

    Show the answer

    The layer that maps the program's classes and objects to the database's tables and rows, and turns the code's calls into SQL queries.

    In Odoo you call search, create, write or unlink on a model rather than hand-writing SQL: the ORM takes care of the query, the access rights and the cache.

  • What does the variable orders hold after this line?

    ```python
    orders = self.env['sale.order'].search([('state', '=', 'sale')])
    `

    • A recordset: the orders in the sale state, possibly none
    • A Python list of dictionaries, one dictionary per order found in the database
    • A single order: the first one found by the search
    • The integer number of orders found by the search
    Show the answer

    A recordset: the orders in the sale state, possibly none

    search always returns a set, even an empty one or one with a single element. The count comes from search_count or len(orders).

  • The ORM's four basic operations on records are … to find, … to add, … to modify and … to delete.

    Show the answer

    The ORM's four basic operations on records are search to find, create to add, write to modify and unlink to delete.

    They make up CRUD (create, read, update, delete): reading goes through search, then through access to the fields of the resulting set.

  • Model (in an enterprise package): what is it?

    Show the answer

    A class that describes a type of business object, such as the order, the customer or the product: its data and its methods. Each one matches a table in the database.

    In Odoo, class Loan(models.Model) with _name = 'library.loan' creates the library.loan model and its library_loan table.

  • An order contains several lines, and each line belongs to one order only. Which fields do you declare?

    • A Many2one from the line to the order, and on the order a One2many that is its inverse
    • A One2many on the line that designates its order, and on the order a Many2one to its first line only
    • A Many2many on the order and a Many2many on the line, linked together through a relation table
    • A Many2one on the order and a Many2one on the line, pointing at each other with no inverse
    Show the answer

    A Many2one from the line to the order, and on the order a One2many that is its inverse

    The foreign key lives on the "many" side: the line. The order's One2many stores nothing, it reads the lines back through inverse_name, the name of the line's Many2one.