diff options
| author | Vo Minh Thu <vmt@openerp.com> | 2012-11-14 13:59:00 +0100 |
|---|---|---|
| committer | Vo Minh Thu <vmt@openerp.com> | 2012-11-14 13:59:00 +0100 |
| commit | c20e2afda178e4a5ba39edfaa3a6c4514fb814b0 (patch) | |
| tree | dc1763ae8c7e1ac2c474bac5391dba5999ab5987 /addons/base_import/static | |
| parent | b2e32b21faf1362a718d9e07106394c5eef77b40 (diff) | |
| parent | 9d8a2ea8e9d75bcc284a19e10173314b80d78eda (diff) | |
[MERGE] merged trunk.
bzr revid: vmt@openerp.com-20121114125900-egz3k82n98kwz47x
Diffstat (limited to 'addons/base_import/static')
11 files changed, 505 insertions, 30 deletions
diff --git a/addons/base_import/static/csv/External_id_3rd_party_application_product_categories.csv b/addons/base_import/static/csv/External_id_3rd_party_application_product_categories.csv new file mode 100644 index 00000000000..5b77f269d85 --- /dev/null +++ b/addons/base_import/static/csv/External_id_3rd_party_application_product_categories.csv @@ -0,0 +1,6 @@ +External ID,Name,Parent Category/External ID
+a1,Expenses,product.product_category_all
+a2,Other Products,product.product_category_all
+a3,Sellable Products,product.product_category_all
+a4,Tables,a1
+a5,Seating furniture,a2
diff --git a/addons/base_import/static/csv/External_id_3rd_party_application_products.csv b/addons/base_import/static/csv/External_id_3rd_party_application_products.csv new file mode 100644 index 00000000000..bf2a5238696 --- /dev/null +++ b/addons/base_import/static/csv/External_id_3rd_party_application_products.csv @@ -0,0 +1,6 @@ +External ID,Name,Internal Reference,Category/External ID,Can be Expensed,Can be Purchased,Can be Sold,Sale Price,Cost,Supply Method,Product Type,Procurement Method
+a6,Aluminum Stool,ALS,a5,False,True,True,49.00,25.00,Buy,Stockable Product,Make to Stock
+a7,Chair,CHR,a5,False,True,True,89.00,40.00,Buy,Stockable Product,Make to Stock
+a8,Table,TBL,a4,False,True,True,169.00,100.00,Buy,Stockable Product,Make to Stock
+a9,Software Book Tutorial,SBT,a2,False,True,False,19.00,8.00,Buy,Consumable,Make to Stock
+a10,Fuel,FL,a1,True,False,False,0.30,0.25,Buy,Service,Make to Stock
diff --git a/addons/base_import/static/csv/Name_products.csv b/addons/base_import/static/csv/Name_products.csv new file mode 100644 index 00000000000..b3fa9b572bd --- /dev/null +++ b/addons/base_import/static/csv/Name_products.csv @@ -0,0 +1,6 @@ +Name,Internal Reference,Can be Expensed,Can be Purchased,Can be Sold,Sale Price,Cost,Supply Method,Product Type,Procurement Method
+Aluminum Stool,ALS,False,True,True,49.00,25.00,Buy,Stockable Product,Make to Stock
+Chair,CHR,False,True,True,89.00,40.00,Buy,Stockable Product,Make to Stock
+Table,TBL,False,True,True,169.00,100.00,Buy,Stockable Product,Make to Stock
+Software Book Tutorial,SBT,False,True,False,19.00,8.00,Buy,Consumable,Make to Stock
+Fuel,FL,True,False,False,0.30,0.25,Buy,Service,Make to Stock
diff --git a/addons/base_import/static/csv/database_import_test.sql b/addons/base_import/static/csv/database_import_test.sql new file mode 100644 index 00000000000..1f79179145e --- /dev/null +++ b/addons/base_import/static/csv/database_import_test.sql @@ -0,0 +1,155 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = off; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET escape_string_warning = off; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: companies; Type: TABLE; Schema: public; Owner: fp; Tablespace: +-- + +CREATE TABLE companies ( + id integer NOT NULL, + company_name character varying +); + + +ALTER TABLE public.companies OWNER TO fp; + +-- +-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: fp +-- + +CREATE SEQUENCE companies_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.companies_id_seq OWNER TO fp; + +-- +-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: fp +-- + +ALTER SEQUENCE companies_id_seq OWNED BY companies.id; + + +-- +-- Name: companies_id_seq; Type: SEQUENCE SET; Schema: public; Owner: fp +-- + +SELECT pg_catalog.setval('companies_id_seq', 3, true); + + +-- +-- Name: persons; Type: TABLE; Schema: public; Owner: fp; Tablespace: +-- + +CREATE TABLE persons ( + id integer NOT NULL, + company_id integer, + person_name character varying +); + + +ALTER TABLE public.persons OWNER TO fp; + +-- +-- Name: persons_id_seq; Type: SEQUENCE; Schema: public; Owner: fp +-- + +CREATE SEQUENCE persons_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE public.persons_id_seq OWNER TO fp; + +-- +-- Name: persons_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: fp +-- + +ALTER SEQUENCE persons_id_seq OWNED BY persons.id; + + +-- +-- Name: persons_id_seq; Type: SEQUENCE SET; Schema: public; Owner: fp +-- + +SELECT pg_catalog.setval('persons_id_seq', 4, true); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: fp +-- + +ALTER TABLE ONLY companies ALTER COLUMN id SET DEFAULT nextval('companies_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: fp +-- + +ALTER TABLE ONLY persons ALTER COLUMN id SET DEFAULT nextval('persons_id_seq'::regclass); + + +-- +-- Data for Name: companies; Type: TABLE DATA; Schema: public; Owner: fp +-- + +COPY companies (id, company_name) FROM stdin; +1 Bigees +2 Organi +3 Boum +\. + + +-- +-- Data for Name: persons; Type: TABLE DATA; Schema: public; Owner: fp +-- + +COPY persons (id, company_id, person_name) FROM stdin; +1 1 Fabien +2 1 Laurence +3 2 Eric +4 3 Ramsy +\. + + +-- +-- Name: companies_pkey; Type: CONSTRAINT; Schema: public; Owner: fp; Tablespace: +-- + +ALTER TABLE ONLY companies + ADD CONSTRAINT companies_pkey PRIMARY KEY (id); + + +-- +-- Name: persons_company_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: fp +-- + +ALTER TABLE ONLY persons + ADD CONSTRAINT persons_company_id_fkey FOREIGN KEY (company_id) REFERENCES companies(id); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/addons/base_import/static/csv/m2m_customers_tags.csv b/addons/base_import/static/csv/m2m_customers_tags.csv new file mode 100644 index 00000000000..e6d74d4f844 --- /dev/null +++ b/addons/base_import/static/csv/m2m_customers_tags.csv @@ -0,0 +1,6 @@ +Name,Reference,Tags,Customer,Street,City,Country
+Credit & Leasing,3,Services,True,Central Avenue 814,Johannesburg,South Africa
+Services & Finance,5,"Consultancy Services,IT Services",True,Grove Road 5,London,United Kingdom
+Hydra Supplies,6,"Manufacturer,Retailer",True,Palm Street 9,Los Angeles,United States
+Bolts & Screws,8,"Wholesaler,Components Buyer",True,Rua Américo 1000,Campinas,Brazil
+National Parts & Supplies,18,"Manufacturer,Wholesaler",True,Guangdong Way 20,Shenzen,China
diff --git a/addons/base_import/static/csv/o2m_purchase_order_lines.csv b/addons/base_import/static/csv/o2m_purchase_order_lines.csv new file mode 100644 index 00000000000..4778b99cb81 --- /dev/null +++ b/addons/base_import/static/csv/o2m_purchase_order_lines.csv @@ -0,0 +1,10 @@ +Order Date,Order Reference,Supplier,Destination,Pricelist,Order Lines / Product,Order Lines / Quantity
+2012-12-15,PO00008,ASUSTeK,Stock,Default Purchase Pricelist,ADPT,20
+,,,,,CARD,30
+,,,,,C-Case,40
+2012-12-15,PO00009,Axelor,Stock,Default Purchase Pricelist,CD,5
+,,,,,CPUa8,15
+2012-12-15,PO000010,China Export,Stock,Default Purchase Pricelist,HDD SH-1,10
+,,,,,HDD SH-2,20
+,,,,,LAP-CUS,35
+,,,,,LAP-E5,40
diff --git a/addons/base_import/static/csv/o2m_suppliers_contacts.csv b/addons/base_import/static/csv/o2m_suppliers_contacts.csv new file mode 100644 index 00000000000..6c7be9037b8 --- /dev/null +++ b/addons/base_import/static/csv/o2m_suppliers_contacts.csv @@ -0,0 +1,8 @@ +Name,Address type,Street,City,Country,Tags,Supplier,Customer,Is a company,Companies that refers to partner / Parent company
+Wood y Wood Pecker,,"Snow Street, 25",Kainuu,Finland,Supplier,1,0,1,
+Roger Pecker,Default,"Snow Street, 27",Kainuu,Finland,Supplier,1,0,0,Wood y Wood Pecker
+Sharon Pecker,Delivery,"Snow Street, 28",Kainuu,Finland,Supplier,1,0,0,Wood y Wood Pecker
+Thomas Pecker,Contact,"Snow Street, 27",Kainuu,Finland,Supplier,1,0,0,Wood y Wood Pecker
+Vicking Direct,,"Atonium Street, 45a",Brussels,Belgium,Supplier,1,0,1,
+Yvan Holiday,Invoice,"Atonium Street, 45b",Brussels,Belgium,Supplier,1,0,0,Vicking Direct
+Jack Unsworth,Contact,"Atonium Street, 45a",Brussels,Belgium,Supplier,1,0,0,Vicking Direct
diff --git a/addons/base_import/static/csv/purchase.order_functional_error_line_cant_adpat.csv b/addons/base_import/static/csv/purchase.order_functional_error_line_cant_adpat.csv new file mode 100644 index 00000000000..3b428763431 --- /dev/null +++ b/addons/base_import/static/csv/purchase.order_functional_error_line_cant_adpat.csv @@ -0,0 +1,6 @@ +"Order Reference","Supplier","Destination","Pricelist","Order Lines / Product","Order Lines / Quantity"
+"PO000020","ASUSTeK","Stock","Default Purchase Pricelist","ADPT",20
+,,,,"CARD",30
+,,,,"C-Case",40
+"PO000021","Axelor","Stock","Default Purchase Pricelist","CD",5
+,,,,"CPUa8",15
diff --git a/addons/base_import/static/src/css/import.css b/addons/base_import/static/src/css/import.css index 07b193c3dc4..00c8bd138a4 100644 --- a/addons/base_import/static/src/css/import.css +++ b/addons/base_import/static/src/css/import.css @@ -1,14 +1,17 @@ -.oe_import{ - display: inline-block; - width: 600px; - padding: 16px; -} .oe_import > p { margin-left: 8px; margin-right: 8px; text-align: justify } +.oe_import h2 { + margin-top: 0; + margin-bottom: 5px; +} + +.oe_padding { + padding: 13px; +} /* ----------- IMPORT BOX ----------- */ .oe_import .oe_import_box{ @@ -17,6 +20,7 @@ background: #F0EEEE; border-radius: 3px; border: solid 1px #dddddd; + width: 600px; } .oe_import .oe_import_toggle{ margin-top: 8px; @@ -156,5 +160,11 @@ border-right: 1px solid #D0D0D0; } +.oe_import .oe_import_error_report > p { + background: #efc9cb; +} +.oe_import .select2-results { + font-size: 12px; +} diff --git a/addons/base_import/static/src/js/import.js b/addons/base_import/static/src/js/import.js index 407d38dacd7..d29452cc138 100644 --- a/addons/base_import/static/src/js/import.js +++ b/addons/base_import/static/src/js/import.js @@ -123,10 +123,10 @@ openerp.base_import = function (instance) { this.exit(); } }, - init: function (parent, params) { + init: function (parent, action) { var self = this; this._super.apply(this, arguments); - this.res_model = params.model; + this.res_model = action.params.model; // import object id this.id = null; this.Import = new instance.web.Model('base_import.import'); @@ -139,7 +139,7 @@ openerp.base_import = function (instance) { this._super(), this.Import.call('create', [{ 'res_model': this.res_model - }]).then(function (id) { + }]).done(function (id) { self.id = id; self.$('input[name=import_id]').val(id); }) @@ -179,7 +179,8 @@ openerp.base_import = function (instance) { //- File & settings change section onfile_loaded: function () { - this.$('.oe_import_button').prop('disabled', true); + this.$('.oe_import_button, .oe_import_file_reload') + .prop('disabled', true); if (!this.$('input.oe_import_file').val()) { return; } this.$el.removeClass('oe_import_preview oe_import_error'); @@ -189,7 +190,8 @@ openerp.base_import = function (instance) { }, onpreviewing: function () { var self = this; - this.$('.oe_import_button').prop('disabled', true); + this.$('.oe_import_button, .oe_import_file_reload') + .prop('disabled', true); this.$el.addClass('oe_import_with_file'); // TODO: test that write // succeeded? this.$el.removeClass('oe_import_preview_error oe_import_error'); @@ -198,13 +200,14 @@ openerp.base_import = function (instance) { !this.$('input.oe_import_has_header').prop('checked')); this.Import.call( 'parse_preview', [this.id, this.import_options()]) - .then(function (result) { + .done(function (result) { var signal = result.error ? 'preview_failed' : 'preview_succeeded'; self[signal](result); }); }, onpreview_error: function (event, from, to, result) { this.$('.oe_import_options').show(); + this.$('.oe_import_file_reload').prop('disabled', false); this.$el.addClass('oe_import_preview_error oe_import_error'); this.$('.oe_import_error_report').html( QWeb.render('ImportView.preview.error', result)); @@ -212,7 +215,8 @@ openerp.base_import = function (instance) { onpreview_success: function (event, from, to, result) { this.$('.oe_import_import').removeClass('oe_highlight'); this.$('.oe_import_validate').addClass('oe_highlight'); - this.$('.oe_import_button').prop('disabled', false); + this.$('.oe_import_button, .oe_import_file_reload') + .prop('disabled', false); this.$el.addClass('oe_import_preview'); this.$('table').html(QWeb.render('ImportView.preview', result)); @@ -337,11 +341,11 @@ openerp.base_import = function (instance) { }, onvalidate: function () { return this.call_import({ dryrun: true }) - .then(this.proxy('validated')); + .done(this.proxy('validated')); }, onimport: function () { var self = this; - return this.call_import({ dryrun: false }).then(function (message) { + return this.call_import({ dryrun: false }).done(function (message) { if (!_.any(message, function (message) { return message.type === 'error' })) { self['import_succeeded'](); diff --git a/addons/base_import/static/src/xml/import.xml b/addons/base_import/static/src/xml/import.xml index 4f721032d1d..0da75eb69b9 100644 --- a/addons/base_import/static/src/xml/import.xml +++ b/addons/base_import/static/src/xml/import.xml @@ -2,20 +2,25 @@ <t t-name="ImportView"> <t t-set="_id" t-value="_.uniqueId('export')"/> <form action="" method="post" enctype="multipart/form-data" class="oe_import"> - <header> - <button type="button" disabled="disabled" - class="oe_button oe_import_button oe_import_validate oe_highlight" - >Validate</button> - <button type="button" disabled="disabled" - class="oe_button oe_import_button oe_import_import" - >Import</button> - <span class="oe_fade">or</span> - <a class="oe_import_cancel" href="#">Cancel</a> - </header> - <input type="hidden" name="session_id" - t-att-value="widget.session.session_id"/> - <input type="hidden" name="import_id"/> - <h2>Upload your file</h2> + <div class="oe_view_manager oe_view_manager_current"> + <div class="oe_view_manager_header oe_padding"> + <h2> + Import a CSV File + </h2> + <input type="hidden" name="session_id" + t-att-value="widget.session.session_id"/> + <input type="hidden" name="import_id"/> + <button type="button" disabled="disabled" + class="oe_button oe_import_button oe_import_validate oe_highlight" + >Validate</button> + <button type="button" disabled="disabled" + class="oe_button oe_import_button oe_import_import" + >Import</button> + <span class="oe_fade">or</span> + <a class="oe_import_cancel" href="#">Cancel</a> + </div> + </div> + <p>Select the <a href="http://en.wikipedia.org/wiki/Comma-separated_values" class="oe_import_csv" target="_blank">.CSV</a> @@ -25,7 +30,9 @@ <label t-attf-for="file_#{_id}" autofocus="autofocus">CSV File:</label> <input type="file" id-attf-id="file_#{_id}" name="file" class="oe_import_file"/> - <button type="button" class="oe_import_file_reload"> + <button type="button" class="oe_import_file_reload" + disabled="disabled" + title="Reload data to check changes."> <img src="/web/static/src/img/icons/gtk-refresh.png"/> </button> <div class="oe_import_with_file"> @@ -44,7 +51,7 @@ </div> </div> - <div class="oe_import_with_file"> + <div class="oe_import_with_file oe_padding"> <h2>Map your data to OpenERP</h2> <input type="checkbox" class="oe_import_has_header" id="oe_import_has_header" checked="checked"/> @@ -59,6 +66,7 @@ <table class="oe_import_grid" /> <h2>Frequently Asked Questions</h2> + <dl> <dt><a href="#" class="oe_import_toggle"> Need to import data from an other application?</a></dt> @@ -78,9 +86,259 @@ whenever possible</p> </dd> </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + What can I do when the Import preview table isn't + displayed correctly?</a></dt> + <dd> + <p>By default the Import preview is set on commas as + field separators and quotation marks as text + delimiters. If your csv file does not have these + settings, you can modify the File Format Options + (displayed under the Browse CSV file bar after you + select your file).</p> <p>Note that if your CSV file + has a tabulation as separator, OpenERP will not + detect the separations. You will need to change the + file format options in your spreadsheet application. + See the following question.</p> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + How can I change the CSV file format options when + saving in my spreadsheet application?</a></dt> + <dd> + <p>If you edit and save CSV files in speadsheet + applications, your computer's regional settings will + be applied for the separator and delimiter. + We suggest you use OpenOffice or LibreOffice Calc + as they will allow you to modify all three options + (in 'Save As' dialog box > Check the box 'Edit filter + settings' > Save).</p> <p>Microsoft Excel will allow + you to modify only the encoding when saving + (in 'Save As' dialog box > click 'Tools' dropdown + list > Encoding tab).</p> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + What's the difference between Database ID and + External ID?</a></dt> + <dd> + <p>Some fields define a relationship with another + object. For example, the country of a contact is a + link to a record of the 'Country' object. When you + want to import such fields, OpenERP will have to + recreate links between the different records. + To help you import such fields, OpenERP provides 3 + mechanisms. You must use one and only one mechanism + per field you want to import.</p> <p>For example, to + reference the country of a contact, OpenERP proposes + you 3 different fields to import: <ul> + <li>Country: the name or code of the country</li> + <li>Country/Database ID: the unique OpenERP ID for a + record, defined by the ID postgresql column</li> + <li>Country/External ID: the ID of this record + referenced in another application (or the .XML file + that imported it)</li> </ul></p> <p>For the country + Belgium, you can use one of these 3 ways to import: + <ul> <li>Country: Belgium</li> <li>Country/Database + ID: 21</li> <li>Country/External ID: base.be</li> + </ul></p> <p>According to your need, you should use + one of these 3 ways to reference records in relations. + Here is when you should use one or the other, + according to your need: <ul> <li>Use Country: This is + the easiest way when your data come from CSV files + that have been created manually.</li> <li>Use + Country/Database ID: You should rarely use this + notation. It's mostly used by developers as it's main + advantage is to never have conflicts (you may have + several records with the same name, but they always + have a unique Database ID)</li> <li>Use + Country/External ID: Use External ID when you import + data from a third party application.</li> </ul></p> + <p>When you use External IDs, you can import CSV files + with the "External ID" column to define the External + ID of each record you import. Then, you will be able + to make a reference to that record with columns like + "Field/External ID". The following two CSV files give + you an example for Products and their Categories.</p> + <a href="/base_import/static/csv/External_id_3rd_party_application_product_categories.csv">CSV file for categories</a><br/> + <a href="/base_import/static/csv/External_id_3rd_party_application_products.csv">CSV file for Products</a> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + What can I do if I have multiple matches for a field? + </a></dt> + <dd> + <p>If for example you have two product categories + with the child name "Sellable" (ie. "Misc. + Products/Sellable" & "Other Products/Sellable"), + your validation is halted but you may still import + your data. However, we recommend you do not import the + data because they will all be linked to the first + 'Sellable' category found in the Product Category list + ("Misc. Products/Sellable"). We recommend you modify + one of the duplicates' values or your product category + hierarchy.<br/> + However if you do not wish to change your + configuration of product categories, we recommend you + use make use of the external ID for this field + 'Category'.</p> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + How can I import a many2many relationship field + (e.g. a customer that has multiple tags)?</a></dt> + <dd> + <p>The tags should be separated by a comma without any + spacing. For example, if you want you customer to be + lined to both tags 'Manufacturer' and 'Retailer' + then you will encode it as follow "Manufacturer, + Retailer" in the same column of your CSV file.</p> + <a href="/base_import/static/csv/m2m_customers_tags.csv"> + CSV file for Manufacturer, Retailer</a><br/> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + How can I import a one2many relationship (e.g. several + Order Lines of a Sale Order)?</a></dt> + <dd> + <p>If you want to import sales order having several + order lines; for each order line, you need to reserve + a specific row in the CSV file. The first order line + will be imported on the same row as the information + relative to order. Any additional lines will need an + addtional row that does not have any information in + the fields relative to the order.</p> + <p>As an example, here is + purchase.order_functional_error_line_cant_adpat.CSV + file of some quotations you can import, based on demo + data.</p> + <a href="/base_import/static/csv/purchase.order_functional_error_line_cant_adpat.csv">File for some Quotations</a> + <p>The following CSV file shows how to import purchase + orders with their respective purchase order lines:</p> + <a href="/base_import/static/csv/o2m_purchase_order_lines.csv">Purchase orders with their respective purchase order lines</a> + <p>The following CSV file shows how to import + suppliers and their respective contacts</p> + <a href="/base_import/static/csv/o2m_suppliers_contacts.csv">Suppliers and their respective contacts</a> + </dd> + </dl> + + + <dl> + <dt><a href="#" class="oe_import_toggle"> + Can I import several times the same record?</a></dt> + <dd> + <p>If you import a file that contains one of the + column "External ID" or "Database ID", records that + have already been imported will be modified instead of + being created. This is very usefull as it allows you + to import several times the same CSV file while having + made some changes in between two imports. OpenERP will + take care of creating or modifying each record + depending if it's new or not.</p> <p> This feature + allows you to use the Import/Export tool of OpenERP to + modify a batch of records in your favorite spreadsheet + application.</p> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + What happens if I do not provide a value for a + specific field?</a></dt> + <dd> + <p>If you do not set all fields in your CSV file, + OpenERP will assign the default value for every non + defined fields. But if you + set fields with empty values in your CSV file, OpenERP + will set the EMPTY value in the field, instead of + assigning the default value.</p> + </dd> + </dl> + + <dl> + <dt><a href="#" class="oe_import_toggle"> + How to export/import different tables from an SQL + application to OpenERP?</a></dt> + <dd> + <p>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).</p> <p>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') + </p> <p>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 <a href="/base_import/static/csv/database_import_test.sql"> + dump of such a PostgreSQL database</a>).</p> + <p>We will first export all companies and their + "External ID". In PSQL, write the following command: + </p> <p>    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;</p> + <p>This SQL command will create the following CSV file: + <br/>    External ID,Name,Is a Company + <br/>    company_1,Bigees,True + <br/>    company_2,Organi,True + <br/>    company_3,Boum,True</p> + <p>To create the CSV file for persons, linked to + companies, we will use the following SQL command in + PSQL:</p> <p>    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</p> + <p>It will produce the following CSV file: + <br/>    External ID,Name,Is a + Company,Related Company/External ID + <br/>    person_1,Fabien,False,company_1 + <br/>    person_2,Laurence,False,company_1 + <br/>    person_3,Eric,False,company_2 + <br/>    person_4,Ramsy,False,company_3</p> + <p>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 orignial + database).</p> + <p>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.</p> + </dd> + </dl> + </div> </form> </t> + <t t-name="ImportView.preview"> <tr t-if="headers" class="oe_import_grid-header"> <td t-foreach="headers" t-as="header" class="oe_import_grid-cell" |
