Access Rights to Objects

411

27.8.1 Exporting Open ERP data to CSV

Start exploring Open ERP’s use of the CSV format by exporting a modestly complex set of data, the partners and partner addresses in the demonstration data. Go to Sales → Address Book → Customers for a list of partners and select the records to export by clicking the checkbox on the left of each record. Then look for the Other Options section on the right of the list and click the Export link. This pops up the Export Data dialog box. Select the following fields: • Name, • Contact Name under the Contacts menu, • City under the Contacts menu. You can either select and add them one at a time, or Ctrl-click them and add the multiple selection - the order in which you select them is the order in which they will be displayed. If you do not wish to export your your data just yet or would like to use the same fields for future exports, you have the option to save these settings. To do that click Save List and give your export a name. Then click Export and save the resulting data.csv file somewhere accessible - perhaps your Desktop. You can open that file in a spreadsheet program or a text editor. You will see that you have a list of partners, with the name and city of each partner’s contacts alongside. In the couple of cases where there is more than one address, the partner name is left out. So it is important to note that the order of entries is critical - do not sort that list Tip: List limits There is a limit to the number of items you can export in the clients - it is the number you can actually see and that is 20 items by default in the web client, but is arbitrary in the GTK client. You can change the number of items viewed by clicking on the link which shows the count of the items. You can then make a selection of limiting it to fixed number of items at a time, for example, 50 or 100, or you can choose to view unlimited number of items at a time.

27.8.2 Importing CSV data to Open ERP

Use this export file as a template for an import file by deleting all of the data and using new data here you will just import new data alongside the demonstration data, but the principle is the same for a blank database. For example, to import partners with several contacts for which you specify a name and a city, you would create the following CSV file from the export file: Table 27.1: Example of importing partner address fields Name ContactsContact Name ContactsCity Whole Globe Technologies Graham Global Athens Wanda World Rome Emerson Earth New York Miles A Minute From the list of partners, click the Import button and then in the Import Data window click Browse to search for and import the new data.csv file. The web client automatically matches column names but the GTK client requires that you click the Auto detect button. You can use the default Options or change them according to preference. Then click Import. You will get a dialog box showing that you have imported 2 objects, and you can see the new partners and partner addresses when you refresh the list on screen. 412

27.8.3 The CSV format for complex database structures

When you import data you have to overcome the problem of representing a database structure in .csv flat files. To do this, two solutions are possible in Open ERP: • importing a CSV file that has been structured in a particular way to enable you to load several different database tables from a single file such as partners and partner contacts in one CSV file, as you have just done above, • importing several CSV files, each corresponding to a specific database table, that have explicit links between the tables. Note: Server-side importing You can also import CSV data in through the server interface. The file format is the same, but column headings differ slightly. When importing through the user interface it checks that the column heading names match the names seen in the forms on the user interface itself. In contrast, when importing through the server the column heading names must match the internal names of the fields. Start by building the header of the CSV file. Open the import tool on the object that you are interested in and select the fields that you want to import into your Open ERP database. You must include every field that is colored blue because those fields are required unless you know that they get filled by default with an appropriate value, and also any other field that is important to you. Figure 27.14: Selecting fields to import using a CSV file Use the field names as the column names in the first line of your CSV file, adding one field per column. If your CSV file has these names in the first line then when you import your CSV file, Open ERP will automatically match the column name to the field name of the table. When you have created your CSV file you will do that by clicking the Nothing button to clear the Fields to Import, then select your CSV file by browsing for a File to import , and then clicking the Auto Detect button. To import CSV data that matches your database structure, you should distinguish between the following types of field in the Open ERP interface: many-to-many fields between multiple sources and destinations, many-to-one fields from multiple sources to a single destination, and one-to-many fields from a single origin to multiple destinations.