maharshi
maharshi

Reputation: 594

How to add multiple values to Many2many field in One2many field ?Odoo 10

I am trying to add a One2many field with create method and this field has a Many2many field which i need to fill, there can be multiple values..

The color_selector is a Many2many field, data of this field is something like this color.true(1, 5) or color.true(5)

location_env.sudo().create({'loc_id': loc_id.id,
                                    'loc_name': loc_id.loc_name,
                                    'purchase_order_line_id': line_id.id,
                                    'color_selector': (6, 0, colors_ids)})

I have tried :

'color_selector': (6, 0, colors_ids)
'color_selector': [(6, 0, colors_ids)]
'color_selector': (6, 0, [colors_ids])
c_ids = (4, colors)
'color_selector': (6, 0, c_ids)

Upvotes: 3

Views: 3160

Answers (1)

Andre Buschermöhle
Andre Buschermöhle

Reputation: 1091

To create a One2Many record in Odoo you should do it that way.

loc_id.your_one_two_many_field = [(0,0,
                                     {'loc_name': loc_id.loc_name,
                                      'purchase_order_line_id': line_id.id,
                                      'color_selector': [(6, 0, colors_ids)]}
                                 )]

Is your colors_ids variable a list? Or recordset?

It has to be a list of record IDs. For example [1,2,3,4,5].

If your colors_ids variable is a recordset then try this following

color_selector: [(6, 0, colors_ids.ids)]

Hopefully it will work for you.

Upvotes: 5

Related Questions