I search on the net, and i notice that the binary fileds are no more stored in the columns of database. So my code not working anymore.
The purpose is to generated a csv.file and store it in the database like in this v10 code, trought a wizard.
If someone can help me to adapt this code to working with ir.attachement or any other great solution
Here is the code :
class AccountWINBOOKSExport(models.TransientModel):
_name = 'account.winbooks.export'
_description = 'WINBOOKS Export Accounting'
data_csv = fields.Binary('CSV', readonly=True)
export_filename = fields.Char('Export CSV Filename', size=128, default='export.csv')
company_id = fields.Many2one('res.company', string='Company', readonly=True, default=lambda self: self.env.user.company_id)
date_from = fields.Date(string='Start Date', required=True)
date_to = fields.Date(string='End Date', required=True)
def action_manual_export_analytic_entries(self):
self.export_filename = 'ANT.txt'
rows = self.get_data("analytic_entries")
with tempfile.TemporaryFile() as file_data:
writer = AccountUnicodeWriter(file_data)
writer.writerows(rows)
with tempfile.TemporaryFile() as base64_data:
file_data.seek(0)
base64.encode(file_data, base64_data)
base64_data.seek(0)
self.env.cr.execute("""
UPDATE account_winbooks_export
SET data_csv = %s
WHERE id = %s""", (base64_data.read(), self.ids[0]))
return {
'type': 'ir.actions.act_window',
'res_model': 'account.winbooks.export',
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'views': [(False, 'form')],
'target': 'new',
}
Binary field in odoo: http://learnopenerp.blogspot.com/2016/06/using-binary-fields-in-odoo.html