You are hereOpenerp: Wizard for exporting to excel

Openerp: Wizard for exporting to excel


By sean - Posted on 19 May 2010

 

Wizard

To do: Expalin the code below....

 

[Update 21.jun'10:
- There was a bug in the webinterface when downloading the excel file, see https://bugs.launchpad.net/openobject-client-web/+bug/591102 , 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="ti.my" id="wizard_ti_my_excel" name="ti.my.excel"    />
<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"/>
    </group>
</form>"""
    fields_finish={
        '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.
    states={
        'init':{
            'actions': [_get_file],
            'result': {'type': 'form',
                'arch': view_form_finish,
                'fields': fields_finish,
                'state': [ ('end', 'Close', 'gtk-cancel', True) ]
            }
        },
    }
wiz_ti_my_excel('ti.my.excel')


Creating Excel docs

to do

Reading

wizards:

http://doc.openerp.com/developer/3_10_wizard/index.html

Create excel sheets from python

http://ntalikeris.blogspot.com/2007/10/create-excel-file-with-python-my-sort.html

http://files.blog-city.com/files/F05/96843/b/cheatsheet.pdf

http://www.simplistix.co.uk/software/python/xlutils

Tags