Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
20825 Visualizzazioni

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
Abbandona

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

Risposta migliore

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
Abbandona
Risposta migliore

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

Avatar
Abbandona
Autore

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!

Risposta migliore

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

Hope it helps, Thanks

Avatar
Abbandona
Risposta migliore

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
Abbandona