Skip to Content
Menu
This question has been flagged
2 Replies
8566 Views

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',
}

Avatar
Discard
Best Answer

Experiencing a similar issue today when upgrading code to v13. To anyone who come here later: the solution is to store the related binary data back to the wizard data table and it should work like v12. 

data_csv = fields.Binary('CSV', readonly=True, attachment=False)
Avatar
Discard
Related Posts Replies Views Activity
3
Aug 22
1845
3
Mar 15
7263
1
Mar 15
8629
2
Feb 24
11408
0
Sep 18
3033