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

Download a microsoft document action

By
Ramy Wafa
on 4/13/14, 10:46 AM 1,357 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.

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 4/30/14, 11:25 AM

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.

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

3 follower(s)

Stats

Asked: 4/13/14, 10:46 AM
Seen: 1357 times
Last updated: 7/6/15, 7:59 AM