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

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.

主站蜘蛛池模板: 中西区| 北辰区| 天台县| 灵武市| 卓尼县| 和政县| 深圳市| 靖安县| 阜南县| 乌拉特前旗| 张家口市| 永泰县| 汽车| 洮南市| 正宁县| 连平县| 盖州市| 北流市| 许昌县| 墨江| 星子县| 开阳县| 都兰县| 巴林左旗| 内江市| 柯坪县| 门头沟区| 贵溪市| 高尔夫| 霸州市| 徐水县| 乌审旗| 龙江县| 南召县| 铜鼓县| 莆田市| 九台市| 双鸭山市| 莒南县| 涟水县| 曲水县|