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

Hi,

I have this

key = [a, b, c, d, e, f]

I want to put these values in my one2many field. The Problem is that I need to add it like this:

all_attributes.write({'value_ids': [[0, 0, {'name': key}]]})

I get an error and only 1 value is setting inside that one2many field.

How can I add there 10 rows if my key has every loop an other value inside?



Avatar
Discard
Best Answer

Hi
Basicaly, heres some example that you can try

record = self.env['model.model'].search([('id','=',1)])
updated_data = {
    'o2m_field':[
    (0,0,{
        'name':'line no #1',
        'otherfield':'*****'
        })
    ,(0,0,{
        'name':'line no #2',
        'otherfield':'*****'
        })
    ,(0,0,{
        'name':'line no #3',
        'otherfield':'*****'
        })
    ]
}
record.write(updated_data)


In your case,, you have list key = [a, b, c, d, e, f]
So you must map the values before write it

o2mfield_value = [
    (0,0,{
        'name':'a',
        })
    ,(0,0,{
        'name':'b',
        })
    ,(0,0,{
        'name':'c',
        })
    # ,********* UNTIL "f"
]


Hope Helps

Regards
La Jayuhni Yarsyah

Avatar
Discard
Related Posts Replies Views Activity
6
Aug 19
60733
2
Aug 19
3703
6
Mar 16
3659
1
Sep 23
2026
1
Sep 21
22752