# How to use Visual in XML (Tree, Form)

**URL:** <https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106>\
**Category:** Developer\
**Created:** [December 20, 2019, 7:51am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106 "2019-12-20T07:51:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)\
**Post date:** [December 20, 2019, 7:51am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106/1 "2019-12-20T07:51:27Z")

</div>

> **[Views — Tryton server](https://docs.tryton.org/latest/server/topics/views/)**

How to use visual in xml?  
I had tried to use visual as the code below for field to\_pallet or to\_cartons, still do not see the effect

Below is my sample code:

```xml
<tree editable="bottom">
    <field name="stock" readonly="1"/>
    <field name="bin_loc" string="Current Bin"/>
    <field name="quantity" />
    <field name="cartons" />
    <field name="to_location"/>
    <field name="to_bin_loc"/>
    <field name="to_quantity" string="Transfer Qty" visual="warning"/>
    <field name="to_cartons" string="Transfer Carton"/>
    <field name="to_pallet" visual="If(Eval('draft'), 'warning', '') pyson='1'/>
    <field name="to_stock" readonly="1" string="To Stock"/>
    <field name="state"/>
</tree>

```

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [December 20, 2019, 8:06am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106/2 "2019-12-20T08:06:16Z")

</div>

As visual is pyson attribute it should be encodded using the [view\_attributes function](https://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.ModelView.view_attributes).

There is an example on the [account\_invoice](https://hg.tryton.org/modules/account_invoice/file/ba1b3bfda9bb/invoice.py#l1134) module

---

<div class="post-metadata">

**Author:** ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)\
**Post date:** [December 20, 2019, 8:47am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106/4 "2019-12-20T08:47:58Z")

</div>

Hi Pokoli, thank you for your fast response.

If let say, my tree is from parent.

If I want to select “child\_field2”, how to xpath?

I had tried this but it not work  
`/form/field[@name="lines"]/tree/field[@name='child_field2']`

Below is pseudo code:

child\_id: child\_tree

```auto
<tree>
    <field name="child_field1"/>
    <field name="child_field2"/>
</tree>

```

parent\_form:

```auto
<form>
    <field name="parent1"/>
     <field name="parent2"/>
     <field name="lines" view_ids="child_tree"/>
</form>

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [December 20, 2019, 8:58am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106/5 "2019-12-20T08:58:23Z")

</div>

If you want to modify the view of lines, you must add your `view_attributes` on the Model of the lines and use a xpath expression for the `child_tree` view.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [January 19, 2020, 8:58am UTC](https://discuss.tryton.org/t/how-to-use-visual-in-xml-tree-form/2106/6 "2020-01-19T08:58:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
