Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4718 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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...
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 21
3448
2
thg 7 24
1467
0
thg 11 15
4991
0
thg 3 15
4660
1
thg 5 20
8054