Skip to Content
Menu
This question has been flagged
1 Reply
6536 Views

I want to implement the functionality of downloading an automatically generated word document. Similar to reports in the HR recruitment module. The functionality is available under Human resources -> recruitment -> Applications -> form view of any application on the top right side of the sheet you find the print interview button which downloads the survey.

I want a similar functionality however it should not be a report but a word document that is populated with data from the applicant such as his/her name date of applying, ... ect. I already have a python function that can populate Microsoft word documents with data from a given dictionary, but the main problem I am facing is how to make the generated document downloadable on click from the user. The document doesn't need to be associated with the applicant so there is no field for the document to be downloaded.

Avatar
Discard
Best Answer

Using wizard we can make the generated document downloadable on click from the user.

Example:-

wizard\sample_data.py

from osv import fields, osv
import base64 class sample_data(osv.osv_memory): _name = "sample.data" _columns = { 'data': fields.binary('Export to File',readonly=True), 'filename': fields.char('File Name', size=128), } _defaults = {'filename' : 'sampleword.doc'} def action_sample_data(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[0] output = 'Sample Content Print in the word document' self.write(cr, uid, ids, {'data': base64.encodestring(output)}, context=context) return { 'type': 'ir.actions.act_window', 'res_model': 'sample.data', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
 

wizard\sample_data._view.xml

  <record id="view_sample_data_form" model="ir.ui.view">
        <field name="name">sample.data.form</field>
        <field name="model">sample.data</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Export">
              <group colspan="4" col="4">               
                 <button  icon="gtk-ok" name="action_sample_data"  string="Generate Data" type="object"/>                
               <field name="data"  filename="filename"/>
            </group>
            </form>
        </field>
    </record>

    <record id="action_generate_data" model="ir.actions.act_window">
        <field name="name">Data</field>
        <field name="res_model">sample.data</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
       <field name="view_id" ref="view_sample_data_form"/>
       <field name="target">new</field>
       <field name="context">{'model':'sample.data'}</field>
    </record>  

   <act_window name="Data"
               res_model="sample.data"
               src_model="sample.data"
               view_mode="form"
               target="new"
               key2="client_action_multi"
               id="window_action_sample_data_download"/>

After clicking the wizard button it will allows the download options in the wizard pop up itself.

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 15
5477
0
Dec 24
7642
3
Sep 24
19193
5
Aug 24
48977
4
Jul 24
8651