This question has been flagged
1 Reply
3236 Views

I've added a new field to "hr.contract" which is a one2many to another model "X". Each record of "X" has a many2one field to another model "Y".  So the design is like this:    "hr.contract" -----one2many----> "X" -------many2one-----> "Y"

In "hr.contract" view, I have a one2many widget for "X". Each line of it contains a dropdown for "Y".

Now, here's what I'm after. In each line of "one2many" widget, I want the dropdown list (for many2one field) to contains only records of "Y" that has not been selected in the previous lines on widget. I tried couple of things with the X2Many widget but didn't have any luck. any suggestion?

Note that I'm using Odoo version 9.0.

Thanks :)

Avatar
Discard
Best Answer

Dear Reyhaneh Abdi


you can do that by overwrite fields_view_get

you can pass previously lines on context and get the values... then make search values without previous values:

Try overwrite this: 

    @api.model    
    def fields_view_get(self, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
        res = super(MkStudyClass, self).fields_view_get(view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
        doc = etree.XML(res['arch'])
        nodes = doc.xpath("//field[@name='company_id']")
        company_ids = []
        company_recs= self.env['mk.study.year'].search([])
        company_ids = [x.company_id.id for x in company_recs]
        domain = "[('id', 'in', " + str(company_ids) + ")]"
        for node in nodes:
              node.set('domain', domain)
        res['arch'] = etree.tostring(doc)
        return res


I hope I helped you...
Avatar
Discard