错误尝试向视图添加筛选器时

huangapple go评论54阅读模式
英文:

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

&lt;record id=&quot;models_cashouts_search&quot; model=&quot;ir.ui.view&quot;&gt;
        &lt;field name=&quot;name&quot;&gt;cash_in_out.request.search.view&lt;/field&gt;
        &lt;field name=&quot;model&quot;&gt;cash_in_out.request&lt;/field&gt;
        &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;
            &lt;search&gt;
                &lt;field name=&quot;appliquand_uid&quot;/&gt;
                &lt;field name=&quot;amount&quot;/&gt;
                &lt;field name=&quot;create_date&quot; string=&quot;Date&quot;/&gt;
                &lt;field name=&quot;acceptor_uid&quot; /&gt;
                &lt;filter string=&quot;Aujourd&#39;hui&quot; name=&quot;today&quot; domain=&quot;[(&#39;create_date&#39;, &#39;&amp;gt;=&#39;, (context_today().strftime(&#39;%Y-%m-%d %H:%M:%S&#39;) - datetime.timedelta(days=1)).strftime(&#39;%Y-%m-%d %H:%M:%S&#39;)), (&#39;create_date&#39;, &#39;&amp;lt;=&#39;, context_today().strftime(&#39;%Y-%m-%d %H:%M:%S&#39;))]&quot; /&gt;
            &lt;/search&gt;
        &lt;/field&gt;
&lt;/record&gt;

答案1

得分: 0

&lt;filter name=&quot;today&quot; string=&quot;今天&quot; domain=&quot;[(&#39;create_date&#39;, &#39;=&#39;, context_today().strftime(&#39;%Y-%m-%d&#39;))]&quot; /&gt;
英文:

You can try the below:

&lt;filter name=&quot;today&quot; string=&quot;Today&quot; domain=&quot;[(&#39;create_date&#39;, &#39;=&#39;, context_today().strftime(&#39;%Y-%m-%d&#39;))]&quot; /&gt;

答案2

得分: 0

context_today 返回一个 datetime.date 对象,而日期 strftime 函数仅处理 %Y%m%d 占位符。Odoo 在评估 %H 时会失败。

过滤条件的第一个值尝试从字符串中减去一个时间差,您需要删除 .strftime()。要使用 datetime 格式,您需要使用 datetime.datetime 对象。

您可以使用 datetimecombine 函数将时间设置为 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

huangapple
  • 本文由 发表于 2023年4月11日 14:20:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定