Odoo Help


Return an Excel file to the web client

Mohamed Essakali
on 9/27/14, 4:50 PM 2,665 views

I have a module that aims to generate an Excel file, I used a wizard to let user select some parameter and when he clicks on a button my methode must return the file generated as response and lets user choose where to store the file.

Any help!

any suggestions are welcome

Mohamed Essakali
on 9/28/14, 10:58 AM
Mohamed Essakali
On 11/15/14, 3:00 PM

I think I can achieve this by using controllers (see this link for more details https://www.odoo.com/forum/help-1/question/writing-controllers-in-openerp-modules-18656), but I opt for another solution. I  create an attachment this way the user can access and download the file  from anywhere. Here is the trick :

def method_that_generate_may_file(self, cr, uid, ids, context=None):

        output = StringIO.StringIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})     

       ####### create worksheet



        # Rewind the buffer.
        vals = {
                    'name': 'something',
                    'datas_fname': 'name.xlsx',
                    'description': 'XXXXXXXXXXXXX',
                    'parent_id': directory_id,
                    'type': 'binary',
                    'db_datas': base64.encodestring(output.read()),
        file_id = self.pool.get('ir.attachment').create(cr,uid,vals,context=context)


I am using xlsxwriter to generate my file.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/27/14, 4:50 PM
Seen: 2665 times
Last updated: 4/23/16, 2:36 PM