Wizard to export something to a csv (Excel) file
report.py
***************************************************
import base64
from osv import fields,osv
from tools.translate import _
import time
class Report(osv.osv_memory):
"""
Wizard to create custom report
"""
_name = "report"
_description = "Create Report"
_columns = {
'start_date' : fields.date('Start Date', required=True),
'end_date' : fields.date('End Date', required=True),
'data': fields.binary('File', readonly=True),
'name': fields.char('Filename', 16, readonly=True),
'state': fields.selection( ( ('choose','choose'), # choose date
('get','get'), # get the file
) ),
}
def create_report(self,cr,uid,ids,context={}):
this = self.browse(cr, uid, ids)[0]
output = 'Start;Ende'
output += '\n' + this.start_date + ';' + this.end_date
print this.start_date
out=base64.encodestring(output)
return self.write(cr, uid, ids, {'state':'get', 'data':out, 'name':'test.csv'}, context=context)
_defaults = {
'state': lambda *a: 'choose',
'start_date' : lambda *a: time.strftime('%Y-%m-%d'),
'end_date' : lambda *a: time.strftime('%Y-%m-%d'),
}
Report()
************************************************
report.xml
************************************************
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- =========== VIEWS =========== -->
<record model="ir.ui.view" id="view_wizard">
<field name="name">Custom Report</field>
<field name="model">report</field>
<field name="type">form</field>
<field name="priority">16</field>
<field name="arch" type="xml">
<form col="3" string="Custom Report">
<group col="2" fill="0" height="2500" states="choose">
<separator string="Report" colspan="2"/>
<field name="start_date" width="200"/>
<field name="end_date" width="200"/>
<separator colspan="2"/>
<group colspan="2">
<button special="cancel" icon="gtk-cancel" string="Cancel"/>
<button type="object" name="create_report" icon="gtk-go-forward"
string="Create"/>
</group>
<field invisible="1" name="state"/>
</group>
<group col="3" fill="0" states="get">
<separator colspan="3" string="Export done"/>
<field name="name" invisible="1" width="100"/>
<field name="data" nolabel="1" readonly="1" width="100" fieldname="name"/>
</group>
</form>
</field>
</record>
<!-- =========== ACTIONS =========== -->
<record model="ir.actions.act_window" id="action_report">
<field name="name">Custom Report</field>
<field name="res_model">report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- =========== MENU ITEMS =========== -->
<menuitem id="menu_report" name="Report"
action="action_report"
parent="account.menu_finance_reporting"
sequence="40" />
</data>
</openerp>

thanks for sharing
I just want to say thank you very much to share this information,
I've been searching for this topic since a few months a go...
and this information is very helpful to me.
thank you.