Odoo Help

Welcome!

This community 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.

1

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

By
Pragmatic
on 4/13/13, 5:49 AM 6,626 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

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 (SA)
on 4/13/13, 7:53 AM

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

priyankahdp
on 4/22/13, 6:12 AM
1

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 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. :)

Pragmatic
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
0
superpan86
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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