Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
7220 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 15
6337
0
gru 24
9577
3
wrz 24
21836
5
gru 24
53148
4
lip 24
10659