This question has been flagged
3 Replies
19368 Views

Hello All,

I am trying to create dynamic domain to filter the values of many2one fields after call the onchange method:

XML View:

         <field name="type" on_change="get_values(type)"/>
         <field name="field1">

PY File:

          'type':fields.selection([('1','1'),('2','2')],'name'),
          'field1':fields.many2one('class','Name'),

And Method:

          def get_values(self, cr, uid, ids,type,context={}):
             res=[]
             ##here some code to filter values by search
             ##search values append into list
             ##like this where res store values like [1,2,3,4]
             res.append(product_id[0])
             return {
                'domain': {
                      'field1': [('id', 'in', res)],
             } }

This functionality is working in v6 but not in v7.

Welcome your suggestion

Thanks

Avatar
Discard

This is not enough to diagnose the problem. Post your actual get_values() code or an example that replicates the problem.

Returning domain in onchange is working in v7 also. Make sure you are working with latest branch of v7.

please paste here your get_values function.need to get something from your code. :-)

Best Answer

Hi, 

You can apply domain using a computed field in odoo using the web domain field module from OCA. See this: Return Dynamic Domain For Field Using Computed Field In Odoo


Thanks

Avatar
Discard
Best Answer

Update your OpenERP server branch because this problem has been solved, yet.

Avatar
Discard
Author

Thanks Francesco, after update OpenERP server it working properly. :)

If this answer is the correct one, please select it as correct so you can help other users that search the some problem. Thanks!

Best Answer

I can't comment, since my "karma" is low!it's been a long time since you've talked about this, but I want to ask something.This is totally working and is really helpful.

But what should this function returns ,if the "field1" is in an other class(the relation between the two classes is one2many)?What should I change?

For example can i say :

{'domain': {'other_object.field_name': ('model_id', '=', model_name)}} .I am looking for something similar

Avatar
Discard