odoo导入关联表的数据
来源:互联网 发布:2016高速公路数据分析 编辑:程序博客网 时间:2024/06/03 10:37
好在odoo给出了方法,以前用过一次,这次竟忘记该怎么做了,看odoo文档,试了试,发现对头:
odoo文档就在导入页里,粘在这里:
- How to export/import different tables from an SQL application to Odoo?
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 for).
To manage relations between tables, you can use the "External ID" facilities of Odoo. 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 for. (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,TrueTo 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_3As 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 orignial database).
The two files produced are ready to be imported in Odoo 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.
例子:
先导出两个关联表的数据如下:部门表:hr_department:
"id","name"
"__export__.hr_department_16","营销一中心"
"__export__.hr_department_17","营销二中心res_users:
login,name,department_id/idzhangsan,张三,__export__.hr_department_16
lisi,李四,__export__.hr_department_17
根据上面odoo的帮助文档,更改如下:
hr_department:
"External ID","name"
"hr_department_6","营销一中心"
"hr_department_7","营销二中心
login,name,department_id/External ID
zhangsan,张三,hr_department_6
lisi,李四,hr_department_7
- 利用odoo的导出功能,不需要操作postgresql的表。
2016.02.14
记住: 要把两表重新导入,这样两边才能对应起来,这次试了好多 次,才大成功。还是重新导入一次比较好。
- odoo导入关联表的数据
- odoo系统中如何导入/导出数据?
- 关联表的数据组合
- 关联表导入
- 关联表多数据的批量insert (批量导入,测试10W条数据用时46秒)
- 【Odoo】Odoo_CRM数据操作
- 批量更新关联表的数据
- 插入关联表数据的优化方法
- Struts2 接收多表关联的数据
- sqlserver批量更新关联表的数据
- MySQL删除关联表的数据
- 表数据的导入导出
- Hadoop 从零开始学习系列-hive与hbase外部关联表建立及数据导入
- Odoo中的层次数据组织
- odoo连接数据库操作数据
- Odoo的安装
- Odoo的Domain (一)
- Odoo的ir.values
- obj.setCapture()
- CSU-ACM2017暑假集训2-二分搜索 poj-2785-4 Values whose Sum is 0
- sequenceFile 转换,并导入至hbase中 (图文解说 2017-7-23)
- GIMMS NDVI 3g V1.0 数据
- Android 性能优化
- odoo导入关联表的数据
- 读取properties实现数据库连接
- Linux环境使用Nexus搭建Maven私服
- c++ 运算符优先级:
- Fine-Grained Classification之车型识别
- 进程、线程间通信机制
- spring mvc 4.1支持protobuf converters
- CNN卷积神经网络全面生动解读-深度学习笔记
- python相关知识总结