跳至内容
菜单
此问题已终结
1 回复
9701 查看

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?



形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
6
8月 19
63798
2
8月 19
4859
6
3月 16
4746
1
9月 23
3793
1
9月 21
26949