0

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>
Rob
  • 14,746
  • 28
  • 47
  • 65

2 Answers2

0

You can try the below:

<filter name="today" string="Today" domain="[('create_date', '=', context_today().strftime('%Y-%m-%d'))]" />
Waleed Mohsen
  • 965
  • 6
  • 8
0

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

Kenly
  • 24,317
  • 7
  • 44
  • 60