Odoo Help

1

How can we use dynamic domains in new Odoo API?

By
Alexei R. Acosta
on 12/22/14, 11:10 AM 2,095 views

How can we use dynamic domains in new Odoo API?

I'm trying to do it, I have an Many2one field, and a compute One2many field. Options to be select by Many2one field should be in this One2many field.

Here are my code lines:

    days = fields.One2many('af.week.day', string='Class days', compute='_compute_days',
                           help='Week days in which this group has classes')
    day_of_week = fields.Many2one('af.week.day', string='Day of week', domain="[('id','in',days)]")

Any idea? In old api we can use something like this: def onchange_type(self,cr,uid,ids, type,context=None): product_obj = self.pool.get('product.product') product_ids = product_obj.search(cr,uid, [('type','=',type)]) return {'domain':{'product_id':[('id','in',product_ids)]}} But in new api... Thanks in advanced!

Alexei R. Acosta
on 12/22/14, 1:29 PM

No anwers?

Alexei R. Acosta
on 12/22/14, 4:58 PM

Send the real example what you did from your side. here in comment you have given the example of onchange method what you want to do it. you can not set dynamic domain on onchange method. give more description of your requirement. dynamic domain can be set by overriding search method of that particular model.

Anil R. Kesariya
on 12/23/14, 1:59 AM
2
Andre de Kock
On 6/17/15, 4:08 AM

In the new Odoo API it is the same as in Version 7.0. Look at this example:

@api.onchange('field')
def onchange_field(self):
    if condition_a:
        return {
            'domain': {
                'field_b': [('domain', '=', 'something')],
            },
        }
    else:
        return {
            'domain': {
                 'field_b': [('domain', '=', 'something_else')],
            },
        }

0

Ivan

--Ivan--
3235
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/23/14, 12:27 AM

Dynamic domain can only be implemented in view.  You can add domain attribute for the field tag and it can accept any other fields' name within the domain.

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.

Register

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

2 follower(s)

Stats

Asked: 12/22/14, 11:10 AM
Seen: 2095 times
Last updated: 6/17/15, 4:08 AM