How to color a field in tree view with today as filter

戏子无情 提交于 2020-01-03 04:45:08

问题


I am new to openERP. I am working on changing the color in tree view for those record whose due_date is less then Today. Those record should be in red color.

I am not able to get the current date as filter in tree view.

xml what I need but not working:

<tree colors="blue:Due_date < Today()" string="Invoice">
                    <field name="Due_date" />
                    <field name="date_invoice"/>
                    <field name="state"/>
                </tree>

Working code

<tree colors="blue:state == 'open'" string="Invoice">
                    <field name="partner_id" groups="base.group_user"/>
                    <field name="date_invoice"/>                      
                    <field name="state"/>
                </tree>

I tried with

context_today()

and

datetime.datetime.now()

Nothing work.

Please help me on this.


回答1:


In .xml side <, >, <=, >= is not supported. So we need to use &lt;, &gt;, &lt;= and &gt;=

This will work, try this,

<tree colors="blue:due_date &lt; current_date;" string="Invoice">
    <field name="Due_date" />
    <field name="date_invoice"/>
    <field name="state"/>
</tree>



回答2:


This will work, try this:

<tree colors="red:due_date &lt; datetime.datetime.combine(context_today(), datetime.time(23,59,59));" string="Invoice"></tree>


来源:https://stackoverflow.com/questions/25699625/how-to-color-a-field-in-tree-view-with-today-as-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!