Help

3

Set default filter value in search view

Avatar
Tajjajt

Hello !

how can I set default value to my filter button in search view? I try to set a context to the action like the way it is in partner module but no result :

<field name="context">{'default_customer':0, 'search_default_supplier': 1, 'default_supplier':1}</field>
Avatar
Discard
2 Answers
12
Avatar
Parth Gajjar
Best Answer

You can use only those fields which are defined in search view.

For this you need to pass proper key and value in context.key should like this

search_default_filter_name

Example: In res_partner search view there is one filter like this

<filter string="Persons" name="type_person" icon="terp-personal" domain="[('is_company','=',0)]"/>

If you want this filter as default pass context like this

<field name="context">{"search_default_customer":1,"search_default_type_person":1}</field>

If you don't want search_default_customer use {"search_default_type_person":1} instate of passing like this {"search_default_customer":0,"search_default_type_person":1}

You can also use field from search view

<field name="parent_id" filter_domain="[('parent_id','child_of',[self])]"/>

for use field pass context like this {"search_default_parent_id":1}

hope this will help

3 Comments
Avatar
Discard
Avatar
Vinod Singh
-

How can i Set default filter on company of logged-in user in search view for any object..? because user_id.company_id.id is not working for me.

Avatar
Atakem
-

this is a question related to default search views. Suppose i need to dynamically enable or disable a filter how could i do? I tried this but it's not working: {'search_default_not_closed':1, 'search_default_lancement':[('defaultLancement','=', True)]} Thanks

Avatar
Carlos A García
-

Excellent!!

4
Avatar
Vinod Singh
Best Answer

How can i Set default filter on company of logged-in user in search view for any object..? because user_id.company_id.id is not working for me.

2 Comments
Avatar
Discard
Avatar
Karolin Ar.
-

Hi, I have this issue too. How can i set default filter for Customers as per their logged in company ?!

Avatar
Adrien
-

You should have a look how multi company logic works. You should look at rules which are filters made before your actual search. See in security folder of various modules, look for model="ir.rule" with for example :

<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]