Odoo14, how to modify the default query conditions of search views in custom modules

37 Views Asked by At

I want to filter the current year's data when entering the contact module dashboard view.

I tried using custom components to add default search criteria, but it didn't take effect. enter image description here enter image description here

1

There are 1 best solutions below

0
Kenly On

Use the Search defaults

Search fields and filters can be configured through the action’s context using search_default_name keys. For fields, the value should be the value to set in the field, for filters it’s a boolean value or a number

You can find a similar example in the CRM module:

  • Define a filter in the search view with a default period:

    <filter name="filter_create_date" date="create_date" default_period="this_year"/>
    
  • Use the filter in the action context:

    <field name="context">{
              ...
              'search_default_filter_create_date': 1}</field>