Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5630 Lượt xem

i wanted to append data to the one2many field but this implementation i am using only replaces the value and it is not what i needed


_property = self.env['estate.property'].browse(vals['property_id'])
_users = self.env['res.users'].search([('partner_id', '=', vals['partner_id'])])
for user in _users:
user.write({ 'property_ids': _property })


additional input:

i have tried this code as i have seen in the forum

user.write({ 'property_ids':[(0,0,_property)] })

but it causes an error

ValueError: dictionary update sequence element #0 has length 1; 2 is required


thank you for the help! i'm still new



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Try like below.

record_id.write({
'One2Many_field': [(0, 0, {
'field inside one2many field': value,
})]
})

Regards

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for the reply!

I tried your solution but got a validation error:
"""
The operation cannot be completed:
- Create/update: a mandatory field is not set.
- Delete: another model requires the record being deleted. If possible, archive it instead.
"""

Do i need to add ALL the fields inside the params {} ?
I just wanted to append the whole model that i got from this line of code (in the description):
_property = self.env['estate.property'].browse(vals['property_id'])

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 17
4297
0
thg 4 16
9
2
thg 8 15
4850
0
thg 3 15
4845
1
thg 1 25
1606