Odoo Help

Welcome!

This community 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.

0

Return an Excel file to the web client

By
Mohamed Essakali
on 9/27/14, 4:50 PM 1,690 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
0
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

 

       workbook.close()

        # Rewind the buffer.
        output.seek(0)
        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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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