2 <t t-name="ImportView">
3 <t t-set="_id" t-value="_.uniqueId('export')"/>
4 <form action="" method="post" enctype="multipart/form-data" class="oe_import">
5 <div class="oe_view_manager oe_view_manager_current">
6 <div class="oe_view_manager_header oe_padding">
10 <input type="hidden" name="session_id"
11 t-att-value="widget.session.session_id"/>
12 <input type="hidden" name="import_id"/>
13 <button type="button" disabled="disabled"
14 class="oe_button oe_import_button oe_import_validate oe_highlight"
16 <button type="button" disabled="disabled"
17 class="oe_button oe_import_button oe_import_import"
19 <span class="oe_fade">or</span>
20 <a class="oe_import_cancel" href="#">Cancel</a>
25 href="http://en.wikipedia.org/wiki/Comma-separated_values"
26 class="oe_import_csv" target="_blank">.CSV</a>
27 file to import. If you need a sample importable file, you
28 can use the export tool to generate one.</p>
29 <div class="oe_import_box">
30 <label t-attf-for="file_#{_id}" autofocus="autofocus">CSV File:</label>
31 <input type="file" id-attf-id="file_#{_id}"
32 name="file" class="oe_import_file"/>
33 <button type="button" class="oe_import_file_reload"
35 title="Reload data to check changes.">
36 <img src="/web/static/src/img/icons/gtk-refresh.png"/>
38 <div class="oe_import_with_file">
39 <a href="#" class="oe_import_toggle">
40 File Format Options…</a>
41 <div class="oe_import_toggled oe_import_options">
42 <p t-foreach="widget.opts" t-as="option">
43 <!-- no @name, avoid submission when file_update called -->
44 <label t-attf-for="#{option.name}_#{_id}">
45 <t t-esc="option.label"/></label>
46 <input t-attf-id="#{option.name}_#{_id}"
47 t-attf-class="oe_import_#{option.name}"
48 t-att-value="option.value"/>
54 <div class="oe_import_with_file oe_padding">
55 <h2>Map your data to Odoo</h2>
56 <div title="If the model uses openchatter, history tracking
57 will set up subscriptions and send notifications
58 during the import, but lead to a slower import.">
59 <input type="checkbox" id="oe_import_tracking"
61 <label for="oe_import_tracking">
62 Track history during import
65 <input type="checkbox" class="oe_import_has_header"
66 id="oe_import_has_header" checked="checked"/>
67 <label for="oe_import_has_header">The first row of the
68 file contains the label of the column</label>
69 <p class="oe_import_noheaders">If the file contains
70 the column names, Odoo can try auto-detecting the
71 field corresponding to the column. This makes imports
72 simpler especially when the file has many columns.</p>
74 <div class="oe_import_error_report"></div>
75 <table class="oe_import_grid" />
77 <div class="oe_padding">
78 <h2>Frequently Asked Questions</h2>
81 <dt><a href="#" class="oe_import_toggle">
82 Need to import data from an other application?</a></dt>
84 <p>In order to re-create relationships between
85 different records, you should use the unique
86 identifier from the original application and
87 map it to the <abbr title="External ID">ID</abbr>
88 column in Odoo. When you
89 import an other record that links to the first
90 one, use <abbr title="XXX/External ID">XXX/ID</abbr>
91 to the original unique identifier.</p>
92 <p>The <abbr title="External ID">ID</abbr>
93 will also be used to update the original
94 import if you need to re-import modified data
95 later, it's thus good practice to specify it
101 <dt><a href="#" class="oe_import_toggle">
102 What can I do when the Import preview table isn't
103 displayed correctly?</a></dt>
105 <p>By default the Import preview is set on commas as
106 field separators and quotation marks as text
107 delimiters. If your csv file does not have these
108 settings, you can modify the File Format Options
109 (displayed under the Browse CSV file bar after you
110 select your file).</p> <p>Note that if your CSV file
111 has a tabulation as separator, Odoo will not
112 detect the separations. You will need to change the
113 file format options in your spreadsheet application.
114 See the following question.</p>
119 <dt><a href="#" class="oe_import_toggle">
120 How can I change the CSV file format options when
121 saving in my spreadsheet application?</a></dt>
123 <p>If you edit and save CSV files in speadsheet
124 applications, your computer's regional settings will
125 be applied for the separator and delimiter.
126 We suggest you use OpenOffice or LibreOffice Calc
127 as they will allow you to modify all three options
128 (in 'Save As' dialog box > Check the box 'Edit filter
129 settings' > Save).</p> <p>Microsoft Excel will allow
130 you to modify only the encoding when saving
131 (in 'Save As' dialog box > click 'Tools' dropdown
132 list > Encoding tab).</p>
137 <dt><a href="#" class="oe_import_toggle">
138 What's the difference between Database ID and
139 External ID?</a></dt>
141 <p>Some fields define a relationship with another
142 object. For example, the country of a contact is a
143 link to a record of the 'Country' object. When you
144 want to import such fields, Odoo will have to
145 recreate links between the different records.
146 To help you import such fields, Odoo provides 3
147 mechanisms. You must use one and only one mechanism
148 per field you want to import.</p> <p>For example, to
149 reference the country of a contact, Odoo proposes
150 you 3 different fields to import: <ul>
151 <li>Country: the name or code of the country</li>
152 <li>Country/Database ID: the unique Odoo ID for a
153 record, defined by the ID postgresql column</li>
154 <li>Country/External ID: the ID of this record
155 referenced in another application (or the .XML file
156 that imported it)</li> </ul></p> <p>For the country
157 Belgium, you can use one of these 3 ways to import:
158 <ul> <li>Country: Belgium</li> <li>Country/Database
159 ID: 21</li> <li>Country/External ID: base.be</li>
160 </ul></p> <p>According to your need, you should use
161 one of these 3 ways to reference records in relations.
162 Here is when you should use one or the other,
163 according to your need: <ul> <li>Use Country: This is
164 the easiest way when your data come from CSV files
165 that have been created manually.</li> <li>Use
166 Country/Database ID: You should rarely use this
167 notation. It's mostly used by developers as it's main
168 advantage is to never have conflicts (you may have
169 several records with the same name, but they always
170 have a unique Database ID)</li> <li>Use
171 Country/External ID: Use External ID when you import
172 data from a third party application.</li> </ul></p>
173 <p>When you use External IDs, you can import CSV files
174 with the "External ID" column to define the External
175 ID of each record you import. Then, you will be able
176 to make a reference to that record with columns like
177 "Field/External ID". The following two CSV files give
178 you an example for Products and their Categories.</p>
179 <a href="/base_import/static/csv/External_id_3rd_party_application_product_categories.csv">CSV file for categories</a><br/>
180 <a href="/base_import/static/csv/External_id_3rd_party_application_products.csv">CSV file for Products</a>
185 <dt><a href="#" class="oe_import_toggle">
186 What can I do if I have multiple matches for a field?
189 <p>If for example you have two product categories
190 with the child name "Sellable" (ie. "Misc.
191 Products/Sellable" & "Other Products/Sellable"),
192 your validation is halted but you may still import
193 your data. However, we recommend you do not import the
194 data because they will all be linked to the first
195 'Sellable' category found in the Product Category list
196 ("Misc. Products/Sellable"). We recommend you modify
197 one of the duplicates' values or your product category
199 However if you do not wish to change your
200 configuration of product categories, we recommend you
201 use make use of the external ID for this field
207 <dt><a href="#" class="oe_import_toggle">
208 How can I import a many2many relationship field
209 (e.g. a customer that has multiple tags)?</a></dt>
211 <p>The tags should be separated by a comma without any
212 spacing. For example, if you want you customer to be
213 lined to both tags 'Manufacturer' and 'Retailer'
214 then you will encode it as follow "Manufacturer,
215 Retailer" in the same column of your CSV file.</p>
216 <a href="/base_import/static/csv/m2m_customers_tags.csv">
217 CSV file for Manufacturer, Retailer</a><br/>
222 <dt><a href="#" class="oe_import_toggle">
223 How can I import a one2many relationship (e.g. several
224 Order Lines of a Sales Order)?</a></dt>
226 <p>If you want to import sales order having several
227 order lines; for each order line, you need to reserve
228 a specific row in the CSV file. The first order line
229 will be imported on the same row as the information
230 relative to order. Any additional lines will need an
231 addtional row that does not have any information in
232 the fields relative to the order.</p>
233 <p>As an example, here is
234 purchase.order_functional_error_line_cant_adpat.CSV
235 file of some quotations you can import, based on demo
237 <a href="/base_import/static/csv/purchase.order_functional_error_line_cant_adpat.csv">File for some Quotations</a>
238 <p>The following CSV file shows how to import purchase
239 orders with their respective purchase order lines:</p>
240 <a href="/base_import/static/csv/o2m_purchase_order_lines.csv">Purchase orders with their respective purchase order lines</a>
241 <p>The following CSV file shows how to import
242 customers and their respective contacts</p>
243 <a href="/base_import/static/csv/o2m_customers_contacts.csv">Customers and their respective contacts</a>
249 <dt><a href="#" class="oe_import_toggle">
250 Can I import several times the same record?</a></dt>
252 <p>If you import a file that contains one of the
253 column "External ID" or "Database ID", records that
254 have already been imported will be modified instead of
255 being created. This is very usefull as it allows you
256 to import several times the same CSV file while having
257 made some changes in between two imports. Odoo will
258 take care of creating or modifying each record
259 depending if it's new or not.</p> <p> This feature
260 allows you to use the Import/Export tool of Odoo to
261 modify a batch of records in your favorite spreadsheet
267 <dt><a href="#" class="oe_import_toggle">
268 What happens if I do not provide a value for a
269 specific field?</a></dt>
271 <p>If you do not set all fields in your CSV file,
272 Odoo will assign the default value for every non
273 defined fields. But if you
274 set fields with empty values in your CSV file, Odoo
275 will set the EMPTY value in the field, instead of
276 assigning the default value.</p>
281 <dt><a href="#" class="oe_import_toggle">
282 How to export/import different tables from an SQL
283 application to Odoo?</a></dt>
285 <p>If you need to import data from different tables,
286 you will have to recreate relations between records
287 belonging to different tables. (e.g. if you import
288 companies and persons, you will have to recreate the
289 link between each person and the company they work
290 for).</p> <p>To manage relations between tables,
291 you can use the "External ID" facilities of Odoo.
292 The "External ID" of a record is the unique identifier
293 of this record in another application. This "External
294 ID" must be unique accoss all the records of all
295 objects, so it's a good practice to prefix this
296 "External ID" with the name of the application or
297 table. (like 'company_1', 'person_1' instead of '1')
298 </p> <p>As an example, suppose you have a SQL database
299 with two tables you want to import: companies and
300 persons. Each person belong to one company, so you
301 will have to recreate the link between a person and
302 the company he work for. (If you want to test this
303 example, here is a <a href="/base_import/static/csv/database_import_test.sql">
304 dump of such a PostgreSQL database</a>).</p>
305 <p>We will first export all companies and their
306 "External ID". In PSQL, write the following command:
307 </p> <p>    copy
308 (select 'company_'||id as "External ID",company_name
309 as "Name",'True' as "Is a Company" from companies) TO
310 '/tmp/company.csv' with CSV HEADER;</p>
311 <p>This SQL command will create the following CSV file:
312 <br/>    External ID,Name,Is a Company
313 <br/>    company_1,Bigees,True
314 <br/>    company_2,Organi,True
315 <br/>    company_3,Boum,True</p>
316 <p>To create the CSV file for persons, linked to
317 companies, we will use the following SQL command in
318 PSQL:</p> <p>    copy (select
319 'person_'||id as "External ID",person_name as
320 "Name",'False' as "Is a Company",'company_'||company_id
321 as "Related Company/External ID" from persons) TO
322 '/tmp/person.csv' with CSV</p>
323 <p>It will produce the following CSV file:
324 <br/>    External ID,Name,Is a
325 Company,Related Company/External ID
326 <br/>    person_1,Fabien,False,company_1
327 <br/>    person_2,Laurence,False,company_1
328 <br/>    person_3,Eric,False,company_2
329 <br/>    person_4,Ramsy,False,company_3</p>
330 <p>As you can see in this file, Fabien and Laurence
331 are working for the Bigees company (company_1) and
332 Eric is working for the Organi company. The relation
333 between persons and companies is done using the
334 External ID of the companies. We had to prefix the
335 "External ID" by the name of the table to avoid a
336 conflict of ID between persons and companies (person_1
337 and company_1 who shared the same ID 1 in the orignial
339 <p>The two files produced are ready to be imported in
340 Odoo without any modifications. After having
341 imported these two CSV files, you will have 4 contacts
342 and 3 companies. (the firsts two contacts are linked
343 to the first company). You must first import the
344 companies and then the persons.</p>
352 <t t-name="ImportView.preview">
353 <tr t-if="headers" class="oe_import_grid-header">
354 <td t-foreach="headers" t-as="header" class="oe_import_grid-cell"
355 ><t t-esc="header"/></td>
357 <tr class="oe_import_fields">
358 <!-- Iterate on first row to ensure we have all columns -->
359 <td t-foreach="preview[0]" t-as="column">
360 <input class="oe_import_match_field"/>
363 <tr t-foreach="preview" t-as="row" class="oe_import_grid-row">
364 <td t-foreach="row" t-as="cell" class="oe_import_grid-cell"
365 ><t t-esc="cell"/></td>
368 <t t-name="ImportView.preview.error">
369 <p>Import preview failed due to: <t t-esc="error"/>. The issue is
370 usually an incorrect file encoding.</p>
371 <p>Here is the start of the file we could not import:</p>
372 <pre><t t-esc="preview"/></pre>
374 <ul t-name="ImportView.error">
375 <li t-foreach="errors" t-as="error"
376 t-attf-class="oe_import_report oe_import_report_#{error_value[0].type}">
377 <t t-call="ImportView.error.each">
378 <t t-set="error" t-value="error_value[0]"/>
381 <a href="#" class="oe_import_report_count" t-if="error_value.length gt 1">
382 <t t-esc="more(error_value.length - 1)"/>
384 <ul class="oe_import_report_more" t-if="error_value.length gt 1">
385 <li t-foreach="error_value.length - 1" t-as="index">
386 <t t-call="ImportView.error.each">
387 <t t-set="error" t-value="error_value[index + 1]"/>
393 <t t-name="ImportView.error.each">
394 <span class="oe_import_report_message">
395 <t t-esc="error.message"/>
397 <t t-if="error.rows" t-esc="at(error.rows)"/>
398 <t t-if="error.moreinfo" t-raw="info(error.moreinfo)"/>
400 <t t-extend="ListView.buttons">
401 <t t-jquery="span.oe_alternative">
402 this.attr('t-if', 'widget.options.import_enabled');
404 <t t-jquery="span.oe_alternative" t-operation="append">
405 <a href="#" class="oe_bold oe_list_button_import">Import</a>