英文:
Error when trying to add a filter to a view
问题
I'm working on an Odoo 14 module but I ran into a problem when trying to add a filter to a view that allows viewing records for today.
Here is the error i get
```Error: Control panel model extension failed to evaluate domain:/n{}``
Here is my code
<record id="models_cashouts_search" model="ir.ui.view">
<field name="name">cash_in_out.request.search.view</field>
<field name="model">cash_in_out.request</field>
<field name="arch" type="xml">
<search>
<field name="appliquand_uid"/>
<field name="amount"/>
<field name="create_date" string="Date"/>
<field name="acceptor_uid" />
<filter string="Aujourd'hui" name="today" domain="[('create_date', '>=', (context_today().strftime('%Y-%m-%d %H:%M:%S') - datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')), ('create_date', '<=', context_today().strftime('%Y-%m-%d %H:%M:%S'))]" />
</search>
</field>
</record>
英文:
I'm working on an Odoo 14 module but I ran into a problem when trying to add a filter to a view that allows viewing records for today.
Here is the error i get
`Error: Control panel model extension failed to evaluate domain:/n{}`
Here is my code
<record id="models_cashouts_search" model="ir.ui.view">
<field name="name">cash_in_out.request.search.view</field>
<field name="model">cash_in_out.request</field>
<field name="arch" type="xml">
<search>
<field name="appliquand_uid"/>
<field name="amount"/>
<field name="create_date" string="Date"/>
<field name="acceptor_uid" />
<filter string="Aujourd'hui" name="today" domain="[('create_date', '&gt;=', (context_today().strftime('%Y-%m-%d %H:%M:%S') - datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')), ('create_date', '&lt;=', context_today().strftime('%Y-%m-%d %H:%M:%S'))]" />
</search>
</field>
</record>
答案1
得分: 0
<filter name="today" string="今天" domain="[('create_date', '=', context_today().strftime('%Y-%m-%d'))]" />
英文:
You can try the below:
<filter name="today" string="Today" domain="[('create_date', '=', context_today().strftime('%Y-%m-%d'))]" />
答案2
得分: 0
context_today 返回一个 datetime.date
对象,而日期 strftime 函数仅处理 %Y
、%m
和 %d
占位符。Odoo 在评估 %H
时会失败。
过滤条件的第一个值尝试从字符串中减去一个时间差,您需要删除 .strftime()
。要使用 datetime
格式,您需要使用 datetime.datetime
对象。
您可以使用 datetime
的 combine
函数将时间设置为 00:00:00
:
datetime.datetime.combine(context_today(), datetime.time(0,0,0)))
要解决此问题,请删除不支持的占位符:%H:%M:%S
英文:
The context_today returns a datetime.date
and the date strftime function only handles %Y
, %m
, and %d
placeholders. Odoo will fail while evaluating %H
.
The first value of the filter domain tries to subtract a time delta from a string, you need to remove the .strftime()
. To use the datetime
format, you need to use datetime.datetime
object.
You can use the datetime combine
function to set time to 00:00:00
:
datetime.datetime.combine(context_today(), datetime.time(0,0,0)))
To fix the issue, remove the unsuporrted placeholders: %H:%M:%S
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论