Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
9688 Prikazi

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
Opusti
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
Opusti
Related Posts Odgovori Prikazi Aktivnost
6
avg. 19
63788
2
avg. 19
4858
6
mar. 16
4743
1
sep. 23
3793
1
sep. 21
26942