Skip to Content
Menu
This question has been flagged
1 Reply
8924 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>
</record> 
<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!

Avatar
Discard

Did you find any solution?

Best Answer

Custom module:

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

That's the way I would start :)
 

Avatar
Discard
Author

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 :/

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 :)