Odoo Help

0

which operators are available for attrs in a view?

By
Christian Werner
on 7/29/13, 7:53 AM 5,522 views

I need something like "not contains" for attrs of a field

I have already tested:

<field name="my_field" attrs="{'invisible': [('other_field', 'not like' , 'blabla')]}"/> <field name="my_field" attrs="{'invisible': [('other_field', 'not ilike' , 'blabla')]}"/> <field name="my_field" attrs="{'invisible': [('other_field', 'not contains' , 'blabla')]}"/>

The field is everytime hidden. Other field has type="char"

1
Nishant Kashyap
On 7/29/13, 9:27 AM

Use

<field name="my_field" attrs="{'invisible': [('other_field', 'not in' , ['blabla'])]}"/>

Put the values in the list. And use the operator not in

it doesn't work, because the value of the field contains also other characters. i.e. 100245-45-(blabla)

Christian Werner
on 7/29/13, 11:09 AM
0
Pouya Maleki
On 1/23/16, 12:47 PM

The point is domain calculations (attrs is also using domain) are done in JS not the database, so you can not use SQL commands such as 'ilike'. You can see this discussion in my \blog. 

But there is a way to add this function to Odoo rather easily with some coding. Edit `view_form.js` ( in openerp/addons/web/static/src/js), find this line:

            case 'not in':
                if (!_.isArray(val)) val = [val];
                stack.push(!_(val).contains(field_value));
                break;

and add these lines after it:

            case 'like':
                stack.push(field_value.indexOf(val)>=0);
                break;
            case 'not like':
                stack.push(field_value.indexOf(val)<0);
                break;
            case 'ilike':
                stack.push(field_value.toUpperCase().indexOf(val.toUpperCase())>=0);
                break;
            case 'ilike':
                stack.push(field_value.toUpperCase().indexOf(val.toUpperCase())<0);
                break; 

and save it, TADA you can use it now. 

warning: if you use it with a field which is not string, it will cause an error

Cheers, 

Pouya

0
FEDERICO LEONI
On 5/22/15, 2:00 PM

I'm facing the same problem. Seems 'attrs' works fine just with '=' or '!=' but when you try to filter a field looking for a string, or an array of results, is quite unhelpful. Create a new field using python shows how some functions are still not well implemented/described in Odoo, even if the rest is superb. 


0
René Schuster
On 2/25/14, 11:28 AM

Try this:

<field name="your_field" 
       attrs="{'readonly': ['!', ('other_field', 'ilike', 'blabla')]}"/>

Regards

0
Christian Werner
On 2/25/14, 11:02 AM

I solved it by using another boolean field and on_change.

python:

_columns = {
 'wf_copy_product':fields.boolean('Copy of Product'),
}

def onchange_default_code(self, cr, uid, ids, default_code, context=None):
            result={}
            if 'blabla' in default_code:
                result['wf_copy_product'] = True
...

xml:

<field name="wf_readonly" invisible="1"/>
<field name="default_code" on_change="onchange_default_code(default_code, context)" required="1" attrs="{'readonly': [('wf_readonly','=', True)]}"/>

hope it help

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/29/13, 7:53 AM
Seen: 5522 times
Last updated: 1/23/16, 12:47 PM