如何在Odoo ListView中显示图标?

时间:2016-07-12 11:17:20

标签: xml python-2.7 listview treeview odoo-8

如果得分< = avg

,我想在Odoo树视图中显示警告图标
    <field name="score"/>
    <field name="avg"/>

2 个答案:

答案 0 :(得分:1)

您的Python代码(将字段score_lt_avg添加到包含scoreavg字段的模型中:

@api.multi
@api.depends('score', 'avg')
def _compute_score_lt_avg(self):
    for record in self:
        record.score_lt_avg = (record.score <= record.avg)

score_lt_avg = fields.Boolean(
    compute='_compute_acore_lt_avg',
    string='Score equal to/lower than average',
)

您的XML代码(您必须将scoreavgscore_lt_avg添加到表单视图中,而不仅仅是树视图,否则计算字段将不起作用):

<field name="score"/>
<field name="avg"/>
<field name="score_lt_avg" invisible="1"/>
<span class="fa fa-exclamation-triangle" attrs="{'invisible': [('score_lt_avg', '=', False)]}"/>

答案 1 :(得分:1)

并且不知道它是否是最佳方式,但我使用button标签在TreeView中显示图标

    <button readonly="True" class="oe_inline oe_stat_button" icon="STOCK_DIALOG_WARNING" attrs="{'invisible': [('score_lt_avg', '=', False)]}"/>