Skip to content

Odoo widget for download a customized file, may be used for generate custom reports like txt, excel...

License

Notifications You must be signed in to change notification settings

erickgnavar/custom_download_file

Repository files navigation

Custom Download File Odoo module

Widget for download a customized file

Generic custom file

class MyFile(models.AbstractModel):

    _inherit = 'download.file.base.model'
    _name = 'my.file'

    def setup(self, record_id):
        super().setup(record_id)
        # initialize values

    def get_filename(self):
        return 'filename'

    def get_content(self):
        # process a file and return content
        return 'file_content'
<widget name="custom_download_button" model="my.file" string="Download this file"/>

Excel report example

from StringIO import StringIO

import xlsxwriter


class MyExcelReport(models.TransientModel):

    _inherit = 'download.file.base.model'
    _name = 'my.excel.report'

    def get_filename(self):
        return 'my_report.xlsx'

    def get_content(self):
        output = StringIO()
        wb = xlsxwriter.Workbook(output)
        sheet = wb.add_worksheet('sheet1')
        # make something
        wb.close()
        output.seek(0)
        return output.read()
<widget name="custom_download_button" model="my.excel.report" string="Download Excel file"/>

About

Odoo widget for download a customized file, may be used for generate custom reports like txt, excel...

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published