Odoo Help


Force id in csv import

John Doe (jd)
on 9/2/14, 7:03 AM 3,335 views

When doing csv imports, how to force a column mapping to an id of an OpenERP element?

I know it can be done manually using the menus by opening the mapping menu and selecting "OpenERP element / BD Id" instead of "OpenERP element" (which tends to map itself to the name of that entity and not the id).

How can this be automated?

mapping menu????

Pascal Tremblay
on 10/3/14, 9:46 AM

A menu is by essence not automatable, although there might be solutions for automating browsers.... but anyway now am having a policy of by no means importing CSV documents by browser, doing it programmatically through XML-RPC 'creates' issued using client libraries.

John Doe (jd)
on 10/3/14, 9:56 AM

« by opening the mapping menu » .... Where is this menu? I don't see it in Odoo

Pascal Tremblay
on 10/3/14, 10:08 AM

By « by opening the mapping menu » I was referring the columns selection that appears in OpenERP 7 after selecting a file for importing, possibly after the user has explicited a file encoding, data separator, and quoting. If everything went fine, OpenERP 7 will open a table (I'm sorry now, it is really more a table than a menu) when the user would possibly do manual mapping from CSV columns to OpenERP fields.

John Doe (jd)
on 10/6/14, 3:28 AM

Anil R. Kesariya

--Anil R. Kesariya--
| 7 6 8
Rajkot, India
--Anil R. Kesariya--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya
On 9/2/14, 8:35 AM

provide the technical name inside the csv file for which field you are importing data. give that column as name it will automatically map to name field inside openerp.

Do you call _technical name_ to the OpenERP source code field name, or the PostgreSQL column name? In the later case, is not working for me. Mapping works but maps to _entity name_ instead of the exact PostgreSQL column name!

John Doe (jd)
on 9/2/14, 9:20 AM

Name which is given inside the model is the table name it self. so whatever field name are define in spefice table in _columns {} dictionary you need to use that field name as column header to import data.

Anil R. Kesariya
on 9/2/14, 9:32 AM

Ah ja, but the problem comes when... I'm actually doing manual mappings to database id of an entity (which is not a field but an ORM elsething) because I can not use a mapping based on field. We are talking about detecting a type of account, but there are two instance rows for this type of account, if you consider its name ('Capital' type of account), each for a different chart of accounts (in a multi-company environment)! I solve it doing a mapping to the actual row id in the CSV, but that way, when doing the import, I have to manually specify it as a "Entity BD Id" where has been mapped to "Entity", which btw is containing the name.

John Doe (jd)
on 9/2/14, 9:43 AM

I finally solved these and all other issues performing imports using XML-RPC against OpenERP (hence committing after each import, I suppose, BTW), instead of using the browser CSV import, that makes a single commit if the import of all rows is successful and hence more expensive in terms of developer time.

John Doe (jd)
on 9/22/14, 9:08 AM

Aha, understood. I guess the browser import is actually far more complex than the approach I used. However, at this point of expertise, to me it seems easier not to import using browser but using the 'create' method of the 'osv.Model' class, using a small script that reads a file and creates an entity per line. All the comlexity of calculating column lines is distributed among previous scripts that query PostgreSQL e.g. for row ids retrieving.

John Doe (jd)
on 10/9/14, 6:30 AM

'column lines'* i meant 'values for each field in a row'.

John Doe (jd)
on 10/9/14, 6:33 AM

John Doe, what you pointed out in your comment, as an answer, might be the most correct answer possible, given the literal question.

John Doe (jd)
on 10/9/14, 9:18 AM



| 5 3 6
Jakarta, Indonesia
On 10/10/14, 2:52 AM

Although you have solved your problem, allow me to provide a different solution. You can specify XML ID as a replacement of that field. The column into which this value need to be imported is field/id (e.g. parent_id/id). To obtain the XML ID, first perform export first for that particular model and make sure that you exported the id field.


If you want the ids to map existing objects you can generate one file ir.model.data.csv and associate the xml_ids that you are going to import to existing objects (model, res_id).

For example if your database has already the stock locations (110, 111, 112) and you want to reference them :

After importing the new xml_ids you can import your csv with those xml_id references.

John Doe (jd)
On 10/10/14, 2:56 AM

Mapping to ids instead of names is also easy when importing using 'osv.Model' 'create(cr, uid, values, context=None)' method through XML-RPC or JSON-RPC.


Stephen Mack

--Stephen Mack--

| 8 8 9
Santiago, Chile
--Stephen Mack--

Some people call me a karma whore, I only ask for 10 points if you like my answer and 15 if I happen to get it correct.

Stephen Mack
On 10/3/14, 9:51 AM

There is some information about importing CVS files in odoo's developers documentation.

That page prompts "country_id:id" to force mapping to id. John Doe prompted to use "parent_id/id". Do you know which of either is older or which of either's deprecation is more probable?

John Doe (jd)
on 10/27/14, 4:58 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 9/2/14, 7:03 AM
Seen: 3335 times
Last updated: 5/11/18, 10:33 AM