If you need to import data from different tables, you will have to recreate relations between records belonging to different tables. (e.g. if you import companies and persons, you will have to recreate the link between each person and the company they work ).
To manage relations between tables, you can use the "external ID" facilities of openerp. the "external ID" of a record is the unique identifier of this record in another application. this "external ID" must be unique accoss all the records of all objects, so it's a good practice to prefix this "external ID" with the name of the application or table. (Like 'Company _ 1', 'person _ 1' instead of '1 ')
As an example, suppose you have a SQL database with two tables you want to import: companies and persons. each person belong to one company, so you will have to recreate the link between a person and the company he work. (If you want to test this example, here is a dump of such a PostgreSQL database ).
We will first export all companies and their "external ID". In Psql, write the following command:
Copy (select 'Company _ '| ID as "external ID", company_name as "name", 'true' as "is a company" from companies) to '/tmp/company.csv' with CSV header;
This SQL command will create the following CSV file:
External ID, name, is a company
Company_1, bigees, true
Company_2, organi, true
Company_3, Boum, true
To create the CSV file for persons, linked to companies, we will use the following SQL command in Psql:
Copy (select 'person _ '| ID as "external ID", person_name as "name", 'false' as "is a company ", 'Company _ '| company_id as "related company/external ID" from persons) to'/tmp/person.csv 'with CSV
It will produce the following CSV file:
External ID, name, is a company, related company/external ID
Person_1, Fabien, false, company_1
Person_2, Laurence, false, company_1
Person_3, Eric, false, company_2
Person_4, Ramsy, false, company_3
As you can see in this file, Fabien and Laurence are working for the bigees Company (company_1) and Eric is working for the organi company. the relation between persons and companies is done using the external ID of the companies. we had to prefix the "external ID" by the name of the table to avoid a conflict of ID between persons and companies (person_1 and company_1 who shared the same ID 1 in the origin database).
The two files produced are ready to be imported in openerp without any modifications. after having imported these two CSV files, you will have 4 contacts and 3 companies. (The firsts two contacts are linked to the first company ). you must first import the companies and then the persons.