Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
9718 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
6
ago 19
63859
2
ago 19
4880
6
mar 16
4757
1
set 23
3806
1
set 21
26978