Odoo Help


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.


Generate and download my own CSV file

Jerome Guerriat
on 1/26/16, 10:00 AM 499 views

Hi everyone!

I would like to add a menu item that would create a CSV file and let me download it when i click on that item. I already created my menuitem and a related action:

<record id="my_action" model="ir.actions.server">
   <field name="sequence" eval="5"/>  
   <field name="state">code</field>
   <field name="type">ir.actions.server</field>
   <field name="model_id" ref="hr_timesheet_sheet.model_hr_timesheet_sheet_sheet"/> 
   <field name="name">Export CSV</field>   
   <field name="code">self.my_action(cr, uid, context.get('active_ids', []))</field>
<menuitem name="action" parent="hr_attendance.menu_hr_time_tracking" sequence="99"    id="my_id action="my_action"/>

When i click on that button, i would like to generate a CSV file and allow the user to download it.

Could anyone help me? I searched with google, but what i find is always related to odoo's standard export feature.

Thanks a lot!

Dr Obx
On 1/26/16, 11:26 AM

Custom module:

Python, def create_csv(), browse data, append, create list, save to file.

That's the way I would start :)

Well, thanks for your answer but this is a little bit vague, since of course i know that this is what i should do :). What i didn't suceed to do is specifically to write and open the CSV file from the browser. Expected behavior: - the user click on a menu item - the CSV is generated back-end - the classic browser prompt to download the file opens up in front-end. Writing in the CSV shouldn't be a problem, but right now, i can't find the way to allow the user to download the generated file. I'm now trying to use a wizard, but i still don't know how to allow the user to download the file i would generate :/

Niboo SPRL, Jerome Guerriat
on 1/26/16, 12:59 PM

Once the file is created/generated and saved, you can create a link to the file/location and display it .... I would use attrs to hide or show if link is ready so user can just click on link and save this file ? Dont know i'm an amateur :)

Dr Obx
on 1/27/16, 8:00 AM

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)


Asked: 1/26/16, 10:00 AM
Seen: 499 times
Last updated: 1/26/16, 11:26 AM