官术网_书友最值得收藏!

Extending views

Forms, lists, and search views are defined using the arch XML structures. To extend views, we need a way to modify this XML. This means locating XML elements and then introducing modifications at those points.

The XML record for view inheritance is just like the one for regular views, but also using the inherit_id attribute, with a reference to the view to be extended.

As an example of this, we will extend the Partner view to make the todo_ids field visible, showing all the Tasks that person is involved in.

The first thing to do is to find the XML ID for the view to be extended. We can find that by looking up the view in the Settings app and the Technical | User Interface | Views menu. The XML ID for the Partner form is base.view_partner_form. While there, we should also find the XML element where we want to insert our changes. We will be adding the list of collaborators at the end of the right columns, after the Language field. We usually identify the element to use by its name attribute. In this case, we have <field name="lang" />.

We will add an XML file for the extensions made to the Partner views, views/res_partner_view.xml, with this content:

<?xml version="1.0"?>
<odoo>
<record id="my_inherited_view" model="ir.ui.view">
<field name="name">Add To-Dos to Partner Form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="lang" position="after">
<field name="todo_ids" />
</field>
</field>
</record>
</odoo>

The inherit_id record field identifies the view to be extended by referring to its external identifier using the special ref attribute. External identifiers will be discussed in more detail in Chapter 5Import, Export, and Module Data.

Usually, XPath is used to locate XML elements. Odoo also uses XPath for this, but it also has the simpler form we just used available. View extension and XPath are discussed further in Chapter 9, Backend Views - Design the User Interface.

The other view types, such as list and search views, also have an arch field and can be extended the same way as form views can.

主站蜘蛛池模板: 鸡西市| 泰安市| 抚顺县| 绍兴县| 洪雅县| 屏南县| 安康市| 封丘县| 辽阳市| 株洲市| 二手房| 信阳市| 通州区| 高邑县| 高州市| 张北县| 宜丰县| 西城区| 迁安市| 通渭县| 香港 | 卢氏县| 通江县| 石河子市| 石阡县| 玉溪市| 富民县| 德保县| 合川市| 泌阳县| 六安市| 化德县| 南涧| 五峰| 莎车县| 大城县| 万山特区| 南安市| 景谷| 彭阳县| 丰原市|