This question has been flagged
3 Replies
65161 Views

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
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

Avatar
Discard

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.

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

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.

Avatar
Discard

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

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])]

Best Answer

As an addon, if you have created a new filter using studio, you will need to use the filter name (something like "studio_filter_xyz") which is attributed by Odoo automatically, and which is not the same as the string that is shown to the end user (something like "my filter". I mistakenly tried the latter, and after reading this post I understood it had to be th 'name'.

Avatar
Discard