gpt4 book ai didi

javascript - 如何根据 Odoo12 中的字段值更改列的颜色?

转载 作者:行者123 更新时间:2023-12-02 23:02:25 24 4
gpt4 key购买 nike

我继承了一个 TreeView 并向该 View 添加了一个选择字段。我需要根据字段的值有不同的颜色。我想知道,Odoo 12 中是否可以有不同颜色的列值。我已经尝试过错误的代码,但它在我的情况下不起作用。

Python 代码:

availability = fields.Selection(string="Availability", compute='_compute_physician_availability', selection=[('available', "Available"), ('not_available', "Not Available")])

def _compute_physician_availability(self):
for physician in self:
employees = self.env['hr.employee'].search([('user_id', '=', physician.user_id.id)])
for employee in employees:
if employee.attendance_state == 'checked_in':
physician.availability = 'available'
else:
physician.availability = 'not_available'

XML 代码:

<record id="physician_tree_view_inherited" model="ir.ui.view">
<field name="name">Physician Tree View Inherited</field>
<field name="model">hms.physician</field>
<field name="inherit_id" ref="acs_hms.view_physician_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='email']" position="after">
<field name="availability" options="{'color': 'red: availability == Not Available'}"/>
</xpath>
</field>
</record>

我也尝试过下面的代码,但它在我的情况下也不起作用。

 <field name="availability" colors=="red:availability=='not_available'; green:availability=='available'"/>

我需要为我的医生的每个状态使用不同的颜色,以使我的 TreeView 更加用户友好,这是客户的要求。

最佳答案

Odoo 9 和 odoo 10 版本支持 TreeView 中的自定义颜色,但 Odoo 11 和 odoo 12 版本仅支持装饰器。

可能的装饰器是:

decoration-bf - shows the line in BOLD 
decoration-it - shows the line in ITALICS
decoration-danger - shows the line in LIGHT RED
decoration-info - shows the line in LIGHT BLUE
decoration-muted - shows the line in LIGHT GRAY
decoration-primary - shows the line in LIGHT PURPLE
decoration-success - shows the line in LIGHT GREEN
decoration-warning - shows the line in LIGHT BROWN

示例

<record id="physician_tree_view_inherited" model="ir.ui.view">
<field name="name">Physician Tree View Inherited</field>
<field name="model">hms.physician</field>
<field name="inherit_id" ref="acs_hms.view_physician_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name='decoration-danger'>availability='not_available'</attribute>
<attribute name='decoration-success'>availability='available'</attribute>
</xpath>
</field>
</record>

关于javascript - 如何根据 Odoo12 中的字段值更改列的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57737862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com