Using external IDs and namespaces

There was a lot of talk about XML IDs already, without specifying what an XML ID is. This recipe will give a deeper understanding of this.

How to do it...

We write into already existing records to demonstrate how to use cross module references:

  1. Add a data file to your module manifest:
        'data': [
            'data/res_partner.xml',
        ],
  2. Change the name of our main company:
    <record id="base.main_company" model="res.company">
        <field name="name">Packt publishing</field>
    </record>
  3. Set our main company's partner as publisher:
    <record id="book_cookbook" model="library.book">
        <field name="publisher_id" ref="base.main_partner" />
    </record>

On installation of this module, the company will be renamed and the book from the next recipe will be assigned ...

Get Odoo Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.