扩展视图

阅读(18) 最后更新: 2019年2月16日 17:41

上一页 修改视图和数据 | 用XPath选择扩展点 下一页

翻译进度 100%

自助翻译

替换:替换选定的节点。如果与空内容一起使用,它将删除元素。从Odoo 10开始,它还允许您通过在内容中使用$0来表示要替换的元素,从而将一个元素与其他标记包装在一起。
replace: Replaces the selected node.If used with empty content, it deletes the element.Since Odoo 10, it also allows you to wrap an element with other markup by using $0 in the content to represent the element being replaced.

属性:修改匹配元素的属性值。内容应该有一个或多个值元素,例如name=“无形”>True>。
attributes: Modifies attribute values for the matched element.The content should have one or more value elements, such as name="invisible">True> .If used with no body, as in , the attribute is removed from the selected element.

虽然PORTION=“替换”允许我们删除XML元素,但应该避免这种情况:它可以中断可能依赖于已删除节点作为占位符的依赖模块来添加其他元素,作为另一种选择,请考虑使元素不可见。
While position="replace" allows us to delete XML elements, this should be avoided: it can break depending modules that may be depending on the deleted node as a placeholder to add other elements.As an alternative, consider making the element invisible.

表单、列表和搜索视图是使用ARCH XML结构定义的。为了扩展视图,我们需要一种修改XML的方法-这意味着定位XML元素,然后在这些点引入修改。
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.

视图继承的XML记录就像用于常规视图的记录一样,但也使用INTENECTION_id属性,并引用要扩展的View。
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.

我们将使用它来扩展图书视图以添加is_Available字段。
We will use this to extend the Book View to add the is_available field.

我们需要做的第一件事是找到要扩展的视图的XML ID,我们可以通过在Settings应用程序中查找View和TechnologyUser Interface ViewViewmenu查找视图。BookForm的XML ID是Library_app.view_form_book。我们还应该找到要插入更改的XML元素。我们将在ISBN字段之后添加is Available?字段。我们通常用它的名称属性来标识要使用的元素。
The first thing we need to do is 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 Book form is library_app.view_form_book.While there, we should also find the XML element where we want to insert our changes.We will be adding the Is Available?field after the ISBN field.We usually identify the element to use by its name attribute.In this case, we have .

我们将为合作伙伴视图的扩展名添加一个XML文件,Views/book_view.xml,内容如下:book:Add is Available?field Library.book,在前面的代码中,我们高亮显示了特定于继承的元素。Inherence_id Record字段通过使用特殊的ref属性引用其外部标识符来标识要扩展的视图。外部标识符将在第5章“导入、导出和模块数据”中详细讨论。
We will add an XML file for the extensions made to the Partner Views, views/book_view.xml, with the following content: Book: add Is Available?field library.book In the preceding code, we highlighted the inheritance-specific element.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 5, Import, Export, and Module Data.

视图使用XML定义,并存储在体系结构字段arch.ExtensionaView中,我们定位扩展将发生的节点,然后执行预期的更改,例如添加XML元素。
Views are defined using XML, and are stored in the architecture field, arch.To extend a View, we locate the node where the extension will take place, and then perform the intended change, such as adding XML elements.

找到节点的最简单的方法是使用一个元素,通常具有一个独特的属性,我们然后添加位置属性,声明要做的更改的类型。
The simplest way to locate a node is to use an element with a distinctive attribute, usually, name.We then add the position attribute, declaring the type of change to make.

在上一节中的示例中,扩展节点是具有name=“isBN”的元素,所做的更改是在所选元素之后追加额外的XML内容:任何XML元素和属性都可以用于选择要用作扩展点的节点,但字符串属性的值被转换为用户的活动语言,因此它不能用作节点选择器。
In the example in the previous section, the extension node was the element with name="isbn", and the change made was to append additional XML content after the selected element: Any XML element and attribute can be used to select the node to use as the extension point, except for string attributes.The value of string attributes is translated to the user's active language, so it can't be used as a node selector.

在版本9.0之前,字符串属性(对于显示的标签文本)也可以用作扩展定位器。自9.0以来,不再允许这样做,这一限制与在这些字符串上操作的语言转换机制有关。
Before version 9.0, the string attribute (for the displayed label text) could also be used as an extension locator.Since 9.0, this is not allowed anymore.This limitation is related to the language translation mechanism operating on those strings.

一旦选择了XML节点作为扩展点,我们需要指示要执行的扩展操作,这是使用Position属性:Inside(默认值):追加所选节点内的内容来完成的,该容器应该是一个容器,例如或。
Once an XML node has been selected as an extension point, we need to indicate the extension operation to perform.This is done using the position attribute: inside (the default): Appends the content inside the selected node, which should be a container, such as or .

后:将内容添加到所选节点之后的父元素中。
after: Adds the content to the parent element, after the selected node.

前面:将内容添加到所选节点之前的父元素。
before: Adds the content to the parent element, before the selected node.

除了属性位置之外,前面的定位器可以与带有Position=“Move”的子元素组合,其效果是将子定位器目标节点移动到父定位器的目标位置。
Except for the attributes position, the preceding locators can be combined with a child element with position="move".The effect is to move the child locator target node to the parent locator's target position.

Odoo 12中的更改:Place=“Move”子定位器在Odoo 12中是新的,在以前的版本中不可用。
Changes in Odoo 12: The position="move" child locator is new in Odoo 12, and is not available in previous versions.

例如:其他视图类型(如List和Search视图)也有一个ARCH字段,并且可以像Form视图一样进行扩展。
For example: The other View types, such as list and search Views, also have an arch field, and can be extended in the same way as form Views can.

odoo技术交流2 群号 625337975

http://www.odoogo.com/post/58/Odoo开发视频教程

文档不断更新中,添加微信odoogo,获取最新视频课程和模块

留言提问