Skip to Content
Menu
This question has been flagged
1 Reply
1339 Views

Hello i have one many2many field called tech_id on which user can select multiple technology like python,react etc. I want to display those selected value on selection field how can i achive this.

Avatar
Discard
Author

Hello Cybrosys Techno Solutions Pvt.Ltd thanks for your reply my technology_id(M2o) is inside O2m filed table of tech_ids so in that can how can i add domain to it

Best Answer

Hi,

Instead of making your Selection field dynamic you can use a Many2One field and add the widget ‘selection’ in the xml file.

First we need to add 2 fields in your python file:

tech_ids = fields.Many2many('model.name')
technology_id = fields.Many2one('model.name')

then we need to add these fields into xml and need to use ‘selection’ widget in your Many2one field:

<field name="partner_ids" widget="many2many_tags"/>


<field name="partner_id" widget="selection"/>

after that we need to define a onchange function:

@api.onchange('partner_ids')
def _compute_new_selection(self):
    selected_list = []
    for rec in self.tech_ids:
        selected_list.append(rec._origin.id)
    return {'domain': {'technology_id': [('id', 'in', selected_list )]}}

Regards

Avatar
Discard