im using odoo13, and want try to make download excel file, heres my models odoo :
class CustomExcel(models.TransientModel):
_name = 'custom.excel'
_rec_name = 'datas_fname'
file_name = fields.Binary(string="Report", readonly=True)
datas_fname = fields.Char(string="Filename")
class MailingContact(models.Model):
_inherit = 'mailing.contact'
def action_download(self):
filename = "template.xlsx"
workbook = xlwt.Workbook(encoding='utf-8')
sheet1 = workbook.add_sheet('saff', cell_overwrite_ok=True)
format1 = xlwt.Style.easyxf('font: color black, bold True;')
sheet1.col(0).width = 7000
sheet1.write(0,0,"column 1", format1)
stream = BytesIO()
workbook.save(stream)
out = base64.encodebytes(stream.getvalue())
excel_id = self.env['custom.excel'].create({"datas_fname":filename,
"file_name": out
})
return {
'res_id': excel_id.id,
'name': 'Template Download',
'view_mode': 'form',
'res_model': 'custom.excel',
'view_id': False,
'type': 'ir.actions.act_window'
}
When I run the action_download() function, the downloaded file has the name "custom.excel-<id
>-file_name" without the ".xlsx" extension. I want to rename the downloaded file to "template.xlsx".
How can I rename the downloaded file to "template.xlsx" in this Odoo model?