Embedded views

When you show a one2many or a many2many field on a form, you don't have much control over how it is rendered up to now if you haven't used one of the specialized widgets. Also, in the case of many2one fields, it is desirable sometimes to be able to influence the way the linked record is opened. In this recipe, we'll look into how to define private views for those fields.

How to do it...

  1. Define your field as usual, but don't close the tag:
    <field name="child_ids">
  2. Simply write the view definition(s) into the tag:
        <tree>
            <field name="name" />
            <field name="email" />
            <field name="phone" />
        </tree>
        <form>
            <group>
                <field name="name" />
                <field name="function" />
            </group>
        </form>
  3. Close the tag:
    </field>

How it works...

When Odoo loads a form, it first checks for reference fields if there are views embedded as outlined previously. Those embedded views can have the exact same elements as views we defined before. Only if Odoo doesn't find an embedded view of some type, does it use the model's default view of this type.

There's more...

While embedded views seem like a great feature in the first place, they complicate view inheritance a lot. For example, as soon as embedded views are involved, the field names are not guaranteed to be unique and you'll usually have to use some quite elaborate XPaths to select elements within an embedded view.

So, in general, you should better served defining the standalone views and use the keys form_view_ref and tree_view_ref described earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.197.164