Creando attachments en Odoo con xmlprc
Gustavo Orrillo
El día de ayer alguien me lo pregunto asi que subo el código para agregar como attachment un archivo llamado "gustavo.txt" a un res.partner de id 10
fo_attachment = open("gustavo.txt",'rb')
file_name = "gustavo.txt"
attachment_data = base64.b64encode(fo_attachment.read()).decode('ascii')
vals_attachment = {
'res_model': 'account.invoice',
'res_id': 10,
'type': 'binary',
'mimetype': 'application/octet-stream',
'company_id': 1, #company ID
'datas': attachment_data,
'name': file_name,
'datas_fname': file_name,
'res_name': file_name,
'indext_content': 'application',
}
attachment_id = sock.execute(dbname,uid,pwd,'ir.attachment','create',vals_attachment)
fo_attachment.close()
Sirve tambien para archivos binarios. Este pedazo de código lo saque de un script que agrega planillas de Excel a facturas en Odoo. Espero que les sirva!
Acerca de:
Gustavo Orrillo
Passionate about programming, he has implemented Odoo for different types of businesses since 2010. In Moldeo Interactive he is a founding Partner and Programmer; In addition to writing on the Blog about different topics related to the developments he makes.