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 can we use dynamic domains in new Odoo API?

By
Alexei R. Acosta
on 12/22/14, 11:10 AM 1,919 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--
3210
| 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.

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

2 follower(s)

Stats

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