Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
9472 มุมมอง

Hello,

I am using Odoo 15 and would like to know if it is possible to set the background color of record in a tree view based on condition.

Example :

I need to color sale order in yellow color if the field state ='draft' and in blue if state='sale', ... 


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,


You can set the background color of each record in the tree view


based on a condition by following these steps:


1. Define the condition in the XML file: In the XML file, within the


<tree>


element, you can set the decoration-attributes to define the condition for each background color.

<record id="sale_order_view_tree" model="ir.ui.view">

<field name="name">product.template.view.tree.inherit.sale_order</field>

<field name="model">sale.order</field>

    <field name="inherit_id" ref="sale.view_order_tree"/>

    <field name="arch" type="xml">

        <tree position="attributes">

            <attribute name="decoration-danger">state == draft</attribute>

<attribute name="decoration-success">state== sent</attribute>

<attribute name="decoration-warning">state== sale</attribute>

        </tree>

    </field>

</record>


2. Add CSS styles in the CSS file:


.o_sale_order .text-success { background-color: #a7f2af7d !important;

}


 .o_sale_order

.text-danger { background-color: #fb88847d !important; }


.o_sale_order

.text-warning { background-color: #fdf57d8f !important; }


Hope it helps



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Checkout this module:
https://apps.odoo.com/apps/modules/15.0/web_tree_dynamic_colored_field/

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Thanks for sharing this link. I was also looking for the same. 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 22
6281
1
มิ.ย. 22
6077
6
ก.ย. 17
8157
1
มี.ค. 15
4412
2
มี.ค. 15
9923