Configuring workflows and processes

413 Note: Foreground table Each of these types is described in relation to a foreground table – the table whose entry form you are viewing and whose entries would be updated by a simple CSV file. Just because one of these relation fields appears on the foreground table, does not mean that there is an inverse field on the related table – but there may be. So there is no one-to-many field in the User form to reflect the many-to-one user_id Salesman field in the Customer form, but there is a many-to-one partner_id Partner Name field in the Addresses form to reflect the one-to-many child_ids Partner Contacts field in the Customer form. Have a look at the screenshots below to see the differences. Figure 27.15: A many-to-one field: a salesperson linked to a partner Figure 27.16: A many-to-many field: partner categories Figure 27.17: A one-to-many field: partner contacts All of the other fields are coded in the CSV file as just one text string in each column. Many-to-one fields Many-to-one fields represent a relationship between the foreground table and another table in the database where the foreground table has a single entry for the other table. Open ERP tries to link the new record in the foreground table with the field in the other table by matching the field values. Tip: Field identifiers If you are working on the server side you can use identifiers rather than the names of resources to link tables. To do this you import the first file for example, Products with a column named id in your CSV file that contains a unique identifier for each product. This could be an incrementing number. When you import other files which link to the first table, you can use the identifier in preference to the names so, for example, when you are saving inventory you can use product:id instead of the product name. You then do not need any complex conversion to create links between the two tables. This considerably simplifies the importation of another database into Open ERP. You just create a linking id column for each table that you are importing that contains the identifier used in the first table. 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.