Some facts about odoo external IDs

Some facts about odoo external IDs

All data have been maintained in database tables and have IDs which are called internal IDs. So why Odoo decided to have another type of ID, External IDs?

By CSV and XML files, you can add records to the database. You are going to use that in code while they haven’t appended them yet in the database. That’s one reason to use External ID.

Let’s have an Example:

What does this code really do?

Whenever you see <record> in odoo source codes, it means a record will be saved in a database table. The table is the value of the model attribute and as you probably guess, in <field> you define the value of each field of the table. But the story isn’t finished now. Odd add another record in ir.model.data table to assign a name for this specific record. That’s the Interesting part. With this assignment, you can access the record without mentioning the internal ID.

Here’s an example of What a row in the ir.model.data table might look like:

The ir.model.data model is used to store mappings between external identifiers (External IDs) and internal record IDs (res_id) for various models in Odoo.

  - name: The name of the external identifier (the part after the module name).

  - model: The name of the Odoo model to which this record belongs.

- res_id: The internal ID of the record in the specified model.

  - module: The name of the module that defines the record.

Odoo believes by having and using External ID, We have cleaner code and less challenge in migration and upgrades.

Now, You can access the record in Python code by self.env.ref()

Additionally, when you want to have some common-used records like selected values, External ID can help you have cleaner and safer code.

 

 

Plus, Demo Data and Test Data are another usage of External ID in Odd.

In conclusion, Although the External ID concept is quite rare for general developers (at least for me), it plays an important role in Odoo framework. I hope to help you understand it better.

To view or add a comment, sign in

Others also viewed

Explore topics