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.