This question has been flagged
1 Reply
2861 Views

Hello, i have a question related to default search views.

Suppose i need to dynamically enable or disable a default filters how could i do? I tried this but it's not working:

<field name="context">

{

'search_default_not_closed':1,

'search_default_lancement':[('defaultLancement','=', True)]

}

</field>

Thanks

Avatar
Discard
Author Best Answer

I tried using a computed field as folowing:

watingFor = fields.Char(string="En attente de", compute="setWaitingForField", search="searchInWaitingFor")

my compute function works fine.

But i have an endless loop with my search function (this one is called indefinitely):

def searchInWaitingFor(self, operator, value):

    value = 'Lancement'

    return [('watingFor', operator, value)]

The main idea in the function above is:

- if i can change the value params depending on rules i will define then ...

- i can define a field in my search_view as following

<field name="watingFor" string="En attente du groupe Lancement"/>

- and i can enable default_filter on waitingFor field

{ 'search_default_watingFor': 1}

but as i said the search function is called again and again ... thanks for helping



######## I finally got a solution #########


Found workaround ... changing the computed field i was searching on solved the endless loop issue (i was computing value of the same field i was searching on). fell free to improve. So ...

- my search view has a field looks like

<search>

<field name="watingFor" string="En attente de mon groupe"/>

</search>

- my menu context

<field name="context">

{

'search_default_not_closed':1,

'search_default_watingFor': 'Oui'

}

</field>

- my model

watingFor = fields.Char(string="En attente de", compute="setWaitingForField", search="searchInWaitingFor")

// duplicated and stored just to search on

filterUsingWatingFor = fields.Char(string="En attente de", compute="setfilterUsingWatingFor", store=True)

def searchInWaitingFor(self, operator, value):

value = self.getUserGroupName()

return [('filterUsingWatingFor', operator, value)]

Avatar
Discard