Search code examples
pythonxmlodooodoo-10odoo-12

How to add "decoration-danger" for different fields ? e.g.I want to change my field to red if it doesn't belong to 50-100. for other it might be 85-95


I am making an app in odoo and i need to highlight the different fields to red if they do not belong to a range, which is specific to their field. For e.g bow_speed should lie between 100 and 150, if not it should turn to red. for bat_speed the range should be between 40-60. if not then the field should turn red. I saw the solutions but they all highlight the whole tree for the value of single field. Means if any single field is not in the range then the whole tree will turn red. I want that field specific. Below is the code related to what I described above:

<tree decoration-danger="bow_speed&lt;=150 and bow_speed&gt;=100">
    <field name="bow_speed"/>
    <field name="bat_speed"/>
</tree>

I did use "decoration-danger" for the whole tree after-taking the value of single field. Means if any single field is not in the range then the whole tree will turn red. I want that field specific.I tried putting "decoration-danger="bow_speed<=150 and bow_speed>=100" this line in every field. Although I didn't get the error but there was no output. I tried the following:

<tree>
    <field name="bow_speed" decoration-danger="bow_speed&lt;=150 and bow_speed&gt;=100"/>
    <field name="bat_speed" decoration-danger="bat_speed&lt;=40 and bat_speed&gt;=60"/>
</tree>

the expected result should be that each field turns red based in its own specifice range.Also, Can I use your solution in the form tag?


Solution

  • For FORM you can use the way I used in tree:

    <form>
        <field name="bow_speed" decoration-danger="bow_speed&lt;=150 and bow_speed&gt;=100"/>
        <field name="bat_speed" decoration-danger="bat_speed&lt;=40 and bat_speed&gt;=60"/>
    </form>
    

    For TREE view you can add the fields in the attribute of tree tag:

    <tree decoration-danger="(bow_speed&lt;=150 and bow_speed&gt;=100) or
                             (bat_speed&lt;=40 and bat_speed&gt;=60")
    >
        <field name="bow_speed"/>
        <field name="bat_speed"/>
    </tree>