0
votes

Here's is what i've tried to do:

<field name="of_num" domain="[('etat','=','Terminé')]"/>

where 'of_num' is a many2one field and 'etat' is a function field of char type.

But it seems not working.I still get all records in my dropdown list.

I have also tried with some other text with no unicode chars but still the same.

I tried also to use 'ilike' operator and tried to put domain in python code with the field definition but with no chance.

EDITED

I've figured out the source of my problem : the field 'etat' is computed but not stored since I'am using 'store=false'.

it's working with store=True. Still, I don't wan't to store it because my value needs to be computed every time a view is loaded.

Could anyone please help me to do that without having to store my value ? thank you

2

2 Answers

0
votes

The only solution I've found to get around my problem is to use a Boolean field that is stored and updated every time my function is computed (of the function field 'etat').

0
votes

Use fnct_search. For functional fields there is an argument called 'fnct_search' which returns a search domain condition. For example

_columns = {
'a':fields.float('A'),
'b':fields.float('B'),
'total_fn': fields.function(_total, fnct_search=_total_search, string='Total'),
}
def _total(self, cr, uid, ids, name, arg, context=None):
    res = {}
    for obj in self.browse(cr, uid, ids, context):
       res[obj.id] = obj.a + obj.b
    return res

def _total_search(self, cursor, user, obj, name, args, domain=None, context=None):
    ids = set()
    for cond in args:
        amount = cond[2]
        cr.execute("select id from your_table having sum(a,b) %s %%s" % (cond[1]),(amount,))
        res_ids = set(id[0] for id in cr.fetchall())
        ids = ids and (ids & res_ids) or res_ids
    if ids:
        return [('id', 'in', tuple(ids))]
    return [('id', '=', '0')]

Here _total returns the value to display for the field total_fn, fnct_search returns the list of tuple need for searching. So whenever we are giving the argument [('total_fn','=',1500)]