Odoo Advanced C: Master and Demo Data
7 November, 2022 by
Deviati Nur Istiqomah

Advanced C: Master and Demo Data


This tutorial assumes you followed the Core Training.

To do the exercise, fetch the branch 15.0-core from the technical training solutions repository. It contains a basic module we will use as a starting point

Data Types

Master Data

Master data is usually part of the technical or business requirements for the module. In other words, such data is often necessary for the module to work properly. This data will always be installed when installing the module.

We already met technical data previously since we have defined security rulesviews and actions. Those are one kind of master data.

On top of technical data, business data can be defined, e.g. countries, currencies, units of measure, as well as complete country localization (legal reports, tax definitions, chart of account), and much more…

Demo Data

In additional to master data, which are requirements for a module to work properly, we also like having data for demonstration purposes:

  • Help the sales representatives make their demos quickly.

  • Have a set of working data for developers to test new features and see how these new features look with data they might not have added themselves.

  • Test that the data is loaded correctly, without raising an error.

  • Setup most of the features to be used quickly when creating a new database.

Demo data is automatically loaded when you start the server if you don’t explicitly say you don’t want it. This can be done in the database manager or with the command line.

$ ./odoo-bin -h
Usage: odoo-bin [options]

--version             show program's version number and exit
-h, --help            show this help message and exit

Common options:
                      disable loading demo data for modules to be installed
                      (comma-separated, use "all" for all modules). Requires
                      -d and -i. Default is none

$ ./odoo-bin --addons-path=... -d db -i account --without-demo=all

Data Declaration


Reference: the documentation related to this topic can be found in Module Manifests.

Data is declared either in CSV or in XML. Each file containing data must be added in the manifest for them to be loaded.

The keys to use in the manifest to add new data are data for the master data and demo for the demo data. Both values should be a list of strings representing the relative paths to the files declaring the data.

Usually, demo data is in a demo folder, views and actions are in a views folder, security related data is in a security folder, and other data is in a data folder.

If your work tree looks like this:

├── data
│   └── master_data.xml
├── demo
│   └── demo_data.xml
├── models
│   ├── *.py
│   └── __init__.py
├── security
│   └── ir.model.access.csv
├── views
│   └── estate_property_offer_views.xml
├── __init__.py
└── __manifest__.py

Your manifest should look like this:

# -*- coding: utf-8 -*-

    "name": "Real Estate",
    "depends": [
    "data": [
        "security/ir.model.access.csv",  # CSV and XML files are loaded at the same place
        "views/estate_property_offer_views.xml",  # Views are data too
        "data/master_data.xml",  # Split the data in multiple files depending on the model
    "demo": [
    "application": True,


Reference: the documentation related to this topic can be found in CSV data files.

The easiest way to declare simple data is by using the CSV format. This is however limited in terms of features: use it for long lists of simple models, but prefer XML otherwise.



Your IDE has probably an extension to have a syntax highlighting of the CSV files



Add some standard Real Estate Property Types for the estate module: Residential, Commercial, Industrial and Land. These should always be installed.


Reference: the documentation related to this topic can be found in Data Files.

When the data to create is more complex it can be useful, or even necessary, to do it in XML.

  <record id="id1" model="tutorial.example">
    <field name="field_a">valueA1</field>
    <field name="field_b">valueB1</field>

  <record id="id2" model="tutorial.example">
    <field name="field_a">valueA2</field>
    <field name="field_b">valueB2</field>


Create some demo data for the estate module.





Big Villa

Trailer home





A nice and big villa

Home in a trailer park






























Data Extension

During the Core Training, we saw in the Chapter 13: Inheritance chapter we could inherit (extend) an existing view. This was a special case of data extension: any data can be extended in a module.

When you are adding new fields to an existing model in a new module, you might want to populate those fields on the records created in the modules you are depending on. This is done by giving the xml_id of the record you want to extend. It won’t replace it, in this case we will set the field_c to the given value for both records.

  <record id="id1" model="tutorial.example">
    <field name="field_c">valueC1</field>

  <record id="id2" model="tutorial.example">
    <field name="field_c">valueC2</field>


Related fields can be set using the ref key. The value of that key is the xml_id of the record you want to link. Remember the xml_id is composed of the name of the module where the data is first declared, followed by a dot, followed by the id of the record (just the id works too if you are in the module declaring it).

  <record id="id1" model="tutorial.example">
    <field name="related_id" ref="module.relatedid"/>


Create some demo data offers for the properties you created.

Create offers using the partners defined in base





Azure Interior

Big Villa



Azure Interior

Big Villa



Deco Addict

Big Villa





Ensure both of your demo properties are created with their Property Type set to Residential.


The value to assign to a field is not always a simple string and you might need to compute it. It can also be used to optimize the insertion of related values, or because a constraint forces you to add the related values in batch. See :Add X2many fields.

  <record id="id1" model="tutorial.example">
    <field name="year" eval="datetime.now().year+1"/>


The offers you added should always be in a date relative to the installation of the module.


You might also need to execute python code when loading data.

<function model="tutorial.example" name="action_validate">
    <value eval="[ref('demo_invoice_1')]"/>


Validate one of the demo data offers by using the “Accept Offer” button. Refuse the others.

Add X2many fields

Reference: the documentation related to this topic can be found in Command.

If you need to add related data in a One2many or a Many2many field, you can do so by using the Command methods.

  <record id="id1" model="tutorial.example">
    <field name="related_ids" eval="[
            'name': 'My name',
            'name': 'Your name',


Create one new Property, but this time with some offers created directly inside the One2many field linked to the Offers.

Accessing the data


You should never access demo data outside of the demo data declaration, not even in tests.

There are multiple ways to access the master/demo data.

In python code, you can use the env.ref(self, xml_id, raise_if_not_found=True) method. It returns the recordset linked to the xml_id you specify.

In XML, you can use the ref key like this

  <record id="id1" model="tutorial.example">
    <field name="related_id" ref="module.relatedid"/>

It will call the ref method, and store the id of the record returned on the field related_id of the record of type tutorial.example with id id1.

In CSV, the title of the column must be suffixed with :id or /id.


In SQL, it is more complicated, see the advanced section.


Data can always be deleted by the user. Always code defensively, taking this into account.


What is the XML id?

Because we don’t want a column xml_id in every single SQL table of the database, we need a mechanism to store it. This is done with the ir.model.data model.

It contains the name of the record (the xml_id) along with the module in which it is defined, the model defining it, and the id of it.

No update

The records created with the noupdate flag won’t be updated when upgrading the module that created them, but it will be created if it didn’t exist yet.


odoo-bin -i module will bypass this setting and always load the data. But normally one shouldn’t do this on a production database.

<odoo noupdate="1">
  <record id="id1" model="model">
    <field name="fieldA" eval="True"/>

Import as SQL

In some cases, it makes sense to do the import directly in SQL. This is however discouraged as it bypasses all the features of the ORM, computed fields (including metadata) and python constraints.


Generally using raw SQL also bypasses ACLs and increases the risks of injections.

ReferenceSecurity in Odoo

Deviati Nur Istiqomah
7 November, 2022
Share this post