Managing statistical reports Configuring reports

414 Many-to-many fields Many-to-many fields are handled just like many-to-one fields in trying to recreate the relationship between tables: either by searching for names or by using identifiers. There are several possible values in a single many-to-many field. Therefore a partner can be given several associated categories. You must separate the different values with a comma. One-to-many fields One-to-many fields are a bit different. Take as an example the Partner Contacts field in the Customer form, which contains all of the linked contacts. To import such a field you do not have to link to an existing entry in another table, but can instead create and link to several partner contacts using the same file. You can then specify several values for different fields linked to that object by the one-to-many field. Each field must be put in a column of the table, and the title of that column must be expressed in the form field_one-to- manyfield_linked-object . The partner data you imported earlier took that form. Note: Symmetry in relation fields Depending on the structure of your data it can be easier to use the one-to-many form or the many-to-one form in relating two tables, so long as the relevant fields exist on both ends of the relationship. For example, you can: • import one partner with different contact in a single file one-to-many, • import the partners first, and then contacts with the field linking to the partner in a many-to-one form.

27.8.4 Another example of a CSV import file

To illustrate data importing, you can see another example below. First import partner categories, and then import some partners and their contacts along with links to the categories just created. Although you can create new contacts at the same time as creating partners because you can do this for one-to-many relations, you cannot create new categories this way because they use many-to-many relations. You must create new categories in a separate step. Partner categories Start by creating partner categories in a CSV file: 1. Create the following table in your spreadsheet program: Table 27.2: Partner categories file Column A Column B Line 1 Category Name Parent Category Line 2 Quality Line 3 Gold Quality Line 4 Silver Quality Line 5 Bronze Quality On the first line, Category Name and Parent Category are the column titles that correspond to field names in the Partner category form. Column A is for the different partner categories and Column B indicates if that category has a parent category. If Column B is blank then the category sits at the top level. 2. Save spreadsheet file in CSV format – separated by commas – and name the file categories.csv. 3. In Open ERP, select Sales → Configuration → Address Book → Localisation → Partner Categories. 415 4. Click Import to the bottom right of the list to bring up the Import Data dialog box, in which you will find the list of fields that can be imported. 5. Click Browse... on the File to import field and select the CSV file you just created, categories.csv . If you are using GTK client, click Auto Detect to match the column names in the CSV file with the field names available in Partner Categories. 6. Click Import at the top-left of the dialog box to load your data. You should get the message Imported 4 objects in a new dialog box. Close both this and the Import Data dialog box to return to the original page. 7. Refresh the Partner Categories list to view the tree of categories, including the new Quality branch and its child branches that you loaded. New partners Here is how to create new partners with more than one contact, as you did before, and how to link them to these new categories: 1. Enter the table below into your spreadsheet program. Table 27.3: Partner data file - partners.csv Column A Column B Column C Column D Line 1 Name Categories ContactsContact Name Salesman Line 2 Black Advertising Silver,Gold George Black Administrator Line 3 Jean Green Line 4 Tiny sprl Fabien Pinckaers Administrator 2. The second line corresponds to the creation of a new partner, with two existing categories, that has two contacts and is linked to a salesman. 3. Save the file using the name partners.csv 4. In OpenERP, select Sales → Address Book → Customers then import the file that you have just saved. You will get a message confirming that you have imported and saved the data. 5. Verify that you have imported the data. A new partner should have appeared Black Advertising, with a salesman Administrator, two contacts George Black and Jean Green and two categories Silver and Gold.

27.8.5 Exporting data in other forms

Open ERP’s generic export mechanism lets you easily export any of your data to any location on your system. You are not restricted to what you can export, although you can restrict who can export that data using the rights management facilities discussed above. You can use this to export your data into spreadsheets or into other systems such as specialist accounts packages. The export format is usually in the CSV format but you can also connect directly to Microsoft Excel using Microsoft’s COM mechanism. Tip: Access to the database Developers can also use other techniques to automatically access the Open ERP database. The two most useful are: • using the XML-RPC web service, • accessing the PostgreSQL database directly. 416 Tip: Module Recorder If you want to enter data into Open ERP manually, you should use the Module Recorder, described in the first section of this chapter. By doing that you will generate a module that can easily be reused in different databases. Then if there are problems with a database you will be able to reinstall the data module you generated with all of the entries and modifications you made for this system.