This question has been flagged
1 Reply
5105 Views

In my product I have a tab for attributes. I have big problem to insert any value in this table like this for example:

I want to add a existing attribute_id and the values_ids inside a product like in this image:



I tried a lot of stuff and it's very difficult to insert data from the code.

I tried this:

write({'attribute_line_desc_ids': [(0, 0, {'attribute_id': 125, 'value_ids': [143, 144]})]})
write({'attribute_line_desc_ids': [(4, 0, {'attribute_id': new_att.id, 'values_ids': [(4, 0, att_val.id)]})]})
write({'attribute_line_desc_ids': [[0, new_att.id, {'value_ids': [[6, False, [143, 144, 145]]]}]]})

new_att.id="attribute_id" and att_val.id="value_ids"

can someone help with this problem?

Thank you.






Avatar
Discard
Best Answer

hello

try with below code.

write({'attribute_line_desc_ids': [(0, 0, {'attribute_id': 125, 'value_ids': [(6, 0, [143, 144])]})]})
Avatar
Discard
Author

and how to add multiple attribute_id on new lines?

write({'attribute_line_desc_ids':

[(0, 0, {'attribute_id': 125, 'value_ids': [(6, 0, [143, 144])]}),

(0, 0, {'attribute_id': 126, 'value_ids': [(6, 0, [145, 146])]})]]})

like above code you can do.

Author

Okay thank you, when I want to update an attribute_line_desc_ids that I writed already, how can I do that? I tried it with 1, 0 or 6,0 but it's not working well.

write({'attribute_line_desc_ids': [(0, 125, {'attribute_id': 125, 'value_ids': [(6, 0, [143, 144])]})]})

write({'attribute_line_desc_ids': [(1, 125, {'attribute_id': 125, 'value_ids': [(6, 0, [143, 144])]})]})

write({'attribute_line_desc_ids': [(6, 125, {'attribute_id': 125, 'value_ids': [(6, 0, [143, 144])]})]})

Author

I mean, I can unlink() a the attribute_line_desc_ids and then write() it again, but is there not a better way to just update it?