Skip to content

Instantly share code, notes, and snippets.

@JRSalasM
Last active December 3, 2019 09:25
Show Gist options
  • Save JRSalasM/d5d518a42b1a369ca27855a0b59c1d2e to your computer and use it in GitHub Desktop.
Save JRSalasM/d5d518a42b1a369ca27855a0b59c1d2e to your computer and use it in GitHub Desktop.
ODOO - Generar excel
# -*- coding: utf-8 -*-
from odoo import models, api, fields
import io
import base64
import xlwt
class ControlAsistenciaWizard(models.TransientModel):
_name = 'control.asistencia.wizard'
def create_report(self):
wb = xlwt.Workbook()
ws = wb.add_sheet("A test sheet 1")
ws.write(0, 0, 'Test value')
archivo = io.BytesIO()
wb.save(archivo)
archivo.seek(0)
data = archivo.read()
if data:
file_id = self.env['file.imp'].create(
{'filecontent': base64.b64encode(data)}
)
filename_field = (
'prueba'
)
if file_id and file_id.id:
return {
'res_model': 'ir.actions.act_url',
'type': 'ir.actions.act_url',
'target': 'new',
'url': (
'web/content/?model=file.imp&id={0}'
'&filename_field={1}'
'&field=filecontent&download=true'
'&filename={1}.xls'.format(
file_id.id,
filename_field,
)
),
}
else:
raise UserError(
'Error de Descarga - No se pudo generar el archivo solicitado.'
)
class FileImp(models.TransientModel):
_name = 'file.imp'
_description = u'Documentos para descargar'
filecontent = fields.Binary(string='Impresión')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment