Odoo Help


How to create dynamic domain on many2one fields with onchange function?

on 4/13/13, 5:49 AM 8,688 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:


And Method:

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

This functionality is working in v6 but not in v7.

Welcome your suggestion


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

Mohammad Alhashash
on 4/13/13, 6:03 AM

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

Sudhir Arya (ERP Harbor Consulting Services)
on 4/13/13, 7:53 AM

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

on 4/22/13, 6:12 AM

Francesco OpenCode

--Francesco OpenCode--

| 6 8 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/13/13, 6:56 AM

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

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

on 4/16/13, 3:05 AM

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

Francesco OpenCode
on 4/16/13, 7:04 AM
On 7/2/15, 6:46 AM

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

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.


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

0 follower(s)


Asked: 4/13/13, 5:49 AM
Seen: 8688 times
Last updated: 7/2/15, 10:50 AM