Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5368 Vizualizări
Hello
i have one2many computed field
attachment_ids = fields.One2many('ir.attachment', 'res_partner_id', string='Attachment', compute='_get_files')
in my function _get_files i build data:
data_attach = {
'name': fileo['Name'],
'type': 'url',
'url': url1,
'datas_fname': fileo['Name'],
'res_model': 'res.partner',
'res_id': self.id,
}
when i want to attach this data to my one2many field i write :
self.attachment_ids = [(0, 0, data_attach)] ==> doesn't work
i tried with :
self.attachment_ids |= self.env['ir.attachment'].create(data_attach)

it's work but not what i want if someone had this issue please thank you in advance
Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

As the  res_partner_id field is the inverse relation(many2one) from the one2many model to main model, you have to set corresponding value in the res_partner_id during the creation and see.

data_attach = {
'name': fileo['Name'],
'type': 'url',
'url': url1,
'datas_fname': fileo['Name'],
'res_model': 'res.partner',
'res_id': self.id,
'res_partner_id': value,
}


Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
sept. 22
2550
0
ian. 20
5603
4
mai 18
11576
1
nov. 24
40393
0
mar. 23
5601