تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
20830 أدوات العرض

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.

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. :-)

أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

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!

أفضل إجابة

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال