2016-09-26 44 views
3

我正在通過在odoo中的會計選項卡中過濾的過濾器添加組。並想獲取上下文due_date <當前日期,但我沒有得到當前日期任何地方,我不知道我怎麼能得到它,有人可以告訴我,如何獲得odoo當前日期?如何在odoo中獲取xml中的當前日期?

這裏是我組通過過濾器

<xpath expr="//filter[@string='Due Month']" position="after 
 
    <filter string="Past Due" context="{'group_by':'date_due < current date'}"/> 
 
</xpath>

這裏是我的其他代碼中,我做到了與計算領域,但並不怎麼我可以得到當前的日期

@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') 

回答

3
<xpath expr="//filter[@string='Due Month']" position="after 
    <filter string="Past Due" name="past_due_filter" domain="[('date_due','&lt;',current_date)]" /> 

</xpath> 
+0

電流場日期不存在有 –

+0

它不應該被使用的字段值。 'current_date'是一個全局變量。 –

+0

嗯......它可能''current_date'在上下文中不可用。 –

2

你可以使用「context_today」或time模塊,例:

<filter name="today" string="Today" domain="[('date','=',time.strftime('%%Y-%%m-%%d'))]"/> 

<filter name="last_24h" string="Last 24h" domain="[('start_date','&gt;', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d'))]"/> 
+0

嗯,我會試試看,謝謝:) –

相關問題