Openerp: Wizard for exporting to excel

Submitted by sean on Wed, 05/19/2010 - 17:07



To do: Expalin the code below....


[Update 21.jun'10:
- There was a bug in the webinterface when downloading the excel file, see , hopefully the fix will be included in 5.0.12.
- This example use a classical wizard, it can also be be using osv_memory ... must add an example


In the modules view xml, create a wizard and menu item that calls it:

<wizard string="My Excel export" model="" id="wizard_ti_my_excel" name=""    />
<menuitem name="My/Excel" id="menu_my_excel" action="wizard_ti_my_excel" type="wizard" sequence="40"/>

Create the ".py" file with the wizard class:
import StringIO
import base64
from   osv import osv, fields
import pooler
import wizard
import csv
import pprint

class wiz_ti_my_excel(wizard.interface):
    view_form_finish="""<?xml version="1.0"?>
<form string="Export list">
    <image name="gtk-dialog-info" colspan="2"/>
    <group colspan="2" col="4">
        <separator string="Export to Excel" colspan="4"/>
    <field name="data" readonly="1" colspan="3" filename="file_name" />
        <label align="0.0" string="Save this document to a .XLS file and open it with\n Excel." colspan="4"/>
        'data': {'string':'File', 'type':'binary', 'readonly': True,},
        'file_name':{'string':'File Name', 'type':'char'}
    ## Only one step in this GUI, call the action _get_file
    ## return the result data + file_name and go to end state.
            'actions': [_get_file],
            'result': {'type': 'form',
                'arch': view_form_finish,
                'fields': fields_finish,
                'state': [ ('end', 'Close', 'gtk-cancel', True) ]

Creating Excel docs

to do



Create excel sheets from python…