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.
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.
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.
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.
We will use this to extend the Book View to add the is_available field.
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 .
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.
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.
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.
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.
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.
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.
Changes in Odoo 12: The position="move" child locator is new in Odoo 12, and is not available in previous versions.
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.