Skip to Content
Menu
This question has been flagged

Hi, i am a newbe developper in Odoo12, I am actually creating a text file in attachment. Odoo seems to create this file in utf-8 format, but i need this file to be in ASCII format.


Here is my code so far :

def create_attachment(self, filename, payment_file_str):
attachment = self.env['ir.attachment'].create({
'res_model': self._name,
'res_id': self.id,
'name': filename,
'datas': base64.b64encode(payment_file_str), # base64.b64encode(payment_file_str) payment_file_str.encode('latin-1').encode('base64')
'datas_fname': filename,
})
simplified_form_view = self.env.ref(
'customer_payment_order.view_attachment_simplified_form')
action = {
'name': _('Payment File'),
'view_mode': 'form',
'view_id': simplified_form_view.id,
'res_model': 'ir.attachment',
'type': 'ir.actions.act_window',
'target': 'current',
'res_id': attachment.id,
}

return action


Avatar
Discard
Related Posts Replies Views Activity
0
Aug 19
1496
2
Nov 24
117
0
Oct 20
2468
1
Mar 19
3574
2
Dec 23
12004