I am adding group by filter of past due in accounting tab in odoo. And want to get context due_date < current date, but i am not getting current date anywhere, I don't know how i can get it, anybody can tell me that how to get current date in odoo?
我在odoo的会计标签中通过过期的过滤器添加组。并希望得到上下文due_date <当前日期,但我没有得到任何地方的当前日期,我不知道我怎么能得到它,任何人都可以告诉我如何获得当前日期在odoo?< p>
here is my group by filter
这是我的过滤器组
<xpath expr="//filter[@string='Due Month']" position="after
<filter string="Past Due" context="{'group_by':'date_due < current date'}"/>
</xpath>
and here is my other code in which i did it with computed field but don't how i can get current date
这是我的其他代码,我用计算字段做了它,但不知道如何获得当前日期
@api.depends('date_due')
@api.multi
def _compute_due_date(self):
for record in self:
record.past_due = record.date_due < record.date.today().strftime('%Y-%m-%d')
2 个解决方案
#1
3
<xpath expr="//filter[@string='Due Month']" position="after
<filter string="Past Due" name="past_due_filter" domain="[('date_due','<',current_date)]" />
</xpath>
#2
2
you can use "context_today" or time
module, examples:
你可以使用“context_today”或时间模块,例子:
<filter name="today" string="Today" domain="[('date','=',time.strftime('%%Y-%%m-%%d'))]"/>
<filter name="last_24h" string="Last 24h" domain="[('start_date','>', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') )]"/>
#1
3
<xpath expr="//filter[@string='Due Month']" position="after
<filter string="Past Due" name="past_due_filter" domain="[('date_due','<',current_date)]" />
</xpath>
#2
2
you can use "context_today" or time
module, examples:
你可以使用“context_today”或时间模块,例子:
<filter name="today" string="Today" domain="[('date','=',time.strftime('%%Y-%%m-%%d'))]"/>
<filter name="last_24h" string="Last 24h" domain="[('start_date','>', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') )]"/>