Most Odoo module definitions, such as user interfaces and security rules, are actually data records stored in specific database tables. The XML and CSV files found in modules are not used by Odoo applications at runtime. They are instead a means to load those definitions into the database tables.

Because of this, an important part of Odoo modules is about representing (serializing) that data using files so that can be later loaded into a database.

Modules can also have default and demonstration data. Data representation allows adding that to our modules. Additionally, understanding Odoo data representation formats is important in order to export and import business data in the context of a project implementation.

Before we go into practical cases, we will first explore the external identifier concept, which is the key to Odoo data representation.

An external identifier (also called XML ID) is a human-readable string identifier that uniquely identifies a particular record in Odoo. They are important when loading data into Odoo.

One reason for that is when upgrading a module, its data files will be loaded again into the database, and we need to detect the already existing records, in order to update them instead of creating new duplicate records.

Another reason supporting interrelated data: data records must be able to reference other data records. The actual database identifier is a sequential number automatically assigned by the database, during module installation. The external identifiers provides a way to reference a related record without the need to know beforehand what database ID it will be assigned, allowing us to define data relations in Odoo data files.

Odoo takes care of translating the external identifier names into actual database IDs assigned to them. The mechanism behind this is quite simple: Odoo keeps a table with the mapping between the named external identifiers and their corresponding numeric database IDs: the ir.model.data model.

To inspect the existing mappings, go to the Technical section of the Settings top menu and select the External Identifiers menu item under Sequences & Identifiers.

For example, if we visit the External Identifiers list and filter it by the todo_app module, we will see the external identifiers generated by the module created previously:

Understanding external identifiers

We can see that the external identifiers have a Complete ID label. Notice how it is composed of the module name and the identifier name joined by a dot, for example, todo_app.action_todo_task.

External identifiers need to be unique only inside an Odoo module, so that there is no risk of two modules conflicting because they accidentally chose the same identifier name. To build a global unique identifier Odoo joins together the modules name with the actual external identifier name. This is what you can see in the Complete ID field.

When using an external identifier in a data file, you can choose to use either the complete identifier or just the external identifier name. Usually it's simpler to just use the external identifier name, but the complete identifier enables us to reference data records from other modules. When doing so, make sure that those modules are included in the module dependencies, to ensure that those records are loaded before ours.

At the top of the list, we have the todo_app.action_todo_task complete identifier. This is the menu action we created for the module, which is also referenced in the corresponding menu item. By clicking on it, we go to the form view with its details; the action_todo_task external identifier in the todo_app module maps to a specific record ID in the ir.actions.act_window model, 72 in this case:

Understanding external identifiers

Besides providing a way for records to easily reference other records, external identifiers also allow you to avoid data duplication on repeated imports. If the external identifier is already present, the existing record will be updated; you'd not need to create a new record. This is why on subsequent module upgrades, previously loaded records are updated instead of being duplicated.

When preparing definition and demonstration data files for the modules, we frequently need to look up existing external identifiers that are needed for references.

We can use the External Identifiers menu shown earlier, but the Developer menu can provide a more convenient method for this. As you may recall from Chapter 1 , Getting Started with Odoo Development, the Developer menu is activated in the Settings dashboard, in an option at the bottom-right.  

To find the external identifier for a data record, on the corresponding form view, select the View Metadata option from the Developer menu. This will display a dialog with the record's database ID and external identifier (also known as XML ID).

As an example, to look up the Demo user ID, we can navigate to form view, at Settings | Users and select the View Metadata option, and this will be shown:

Finding external identifiers

To find the external identifier for view elements, such as form, tree, search, or action, the Developer menu is also a good source of help. For this, we can either use its Manage Views option or open the information for the desired view using the Edit <view type> option. Then, select their View Metadata option.