Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
9711 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
6
août 19
63828
2
août 19
4866
6
mars 16
4753
1
sept. 23
3796
1
sept. 21
26957