Reference Fields in Odoo
Odoo has different types of fields like Character, Integer, Boolean, etc. Also, have the relational fields which help to create relationships between different models. A reference field will help to create a dynamic relationship in a model. Which means we can select the model dynamically to create the relation. In Many2one, One2many and Many2many fields we can pre-define the target model in which the relationship needs to be created. For example, in a Sale Order, if we create a Many2one field to Customers, it will only create a relation between these two models, here we pre-define the target model that is customers.
In the case of the reference field first, we can select the target model and then select the record. For example, In Customer model I need to add a field ‘Document Source’, In this, for some customers, I need to add a Purchase Order as document source, for some other customers need to add Sale Order as source, and also sometimes I may need to add an Invoice as the source. In this case, I can define a reference field, so I can first choose the model (Purchase, Sale, or Invoice) and then select the record.
We can see a simple example of a reference field from Settings >> Technical >> Menu Items.
If we try to create a Menu Item from here, we have to choose an Action for this menu. This Action field is a Reference Field. Because first, we have to select the action model, ie have to select whether it is an ir.actions.the report, ir.actions.server, ir.actions.act_window, etc. After selecting that, we can select the particular action of the selected model.
After selecting the model it will show another field to choose the records in the selected model.
After saving, it will show as a single field (only the record) like a Many2one field.
Originally published at Reference Fields in Odoo