Data export to CSV with Filtering in V7
Zb_export is a module to export the records of any model with user-defined column sequences and filters into CSV (Spreadsheet) File
OpenERP by default provides us with the facility of printing the details of many models, for eg. the list of sale orders or the details of a particular sale order ect through reports. But the format of the report is defined by openerp and the normal user cannot alter it.Then there is the normal import/export functionalty using which one is able to export the data stored into a csv file. But the csv file obtained works well for importing data into another Database but it cannot be used for office use as it contains extra colums like 'external_id' and the column headers are not user defined.
Zb_export module provides the user with both flexibility of printing reports in csv format the way one wants and the user friendly appearence of a normal report.
On installing this module a new menuitem appears in Settings > Zb Export Tool > Export To CSV
Creating a New Export Tool
As shown in the screenshot here one is able to create a new export to CSV tool. The main fields to noted here are:
- Name: The name of the tool Can Be Specified in this field. (here: "Invoice Details").
- Object to Export: The Model that needs to exported can be selected from the drop down list in this field
- Active: field needs to be ticked.
- Serial No : if marked would insert Serial Number in the CSV file.
Adding Fields and Subfields
In the Fields to Export tab all the fields required can be added. (Note: The columns in the CSV file is arranged as per the sequence of the fields entered)
the Above Screenshot shows the form that appears to add a new field. The main fields in this view to be noted are
- Field : This is used to Select any field present in The Selected model
- Name: This is the Column header in the CSV that would represent this field
- Field Type: This is automatically Loaded and Contains the type for the selected field
On Selecting fields of type one2many and many2many 2 new fields need to be Noted
- Sub Field : This field belongs to the model to which the one2many/many2many field points at. For eg: here the field selected in model Invoice is Invoice Lines that corresponds to model Invoice Line. Invoice Reference is a field in the Invoice Line and it will be printed in the CSV file.
- Rules: For filtering. (use will be Discussed later )
Create/Delete an Action
In the tab Advanced there is a button called Create Action. On clicking it a new action is created and 2 fields appear Window Action and Wizard Button as shown below. These represent the new action created. Button delete Action is used to delete the created action
Downloading the CSV
The Created action can be now accessed in the tree and form view of the corressponding model as shown below and clicking it a csv file is created which can be downloaded and viewed as shown in the screenshots below.
Click on Invoice Details. A wizard Appears as shown below
Click on Export to CSV
On Clicking The Download link the Invoice Report is Downloaded
Filtering Using Rules
The Module also has an additional functionality of specifying rules. Setting rules enables obtaining filtered results. For example if the requirement is to view only the Invoices that are in done state this condition can be Specified in The Rule section as [('state','=','done')]. Here state is a field in the model.
The rule can be specified both for the Main Model and for the one2many and many2many fields. After entering the required rules and saving the record the user will be able to obtain the filtered results on downloading the CSV file. The rules must be Specified correctly in the corrrect format i.e the domain format else an error message will appear.
Rules for subfields follow the same pattern.
Thanks