This question has been flagged
3 Replies
36905 Views

How can I update the external_id? I've made a mistake during an import and I have some record with the wrong external_id in the form "res_partner_XXX" where XXX is the record id. How can I update those records with a csv file? I tried to import the csv in the external identifiers section, but with no luck: a new record is created instead of updating the old one (V 7.0) Is there a way to do it?

Avatar
Discard
Best Answer

Please be careful when doing this!

Every OpenERP module uses External ID's to "add" and/or "locate and update" information in the system. Changing or Deleting External ID records can cause serious limitations to the ability to install or upgrade modules in the future.

Make sure you understand what you are doing and change only External ID's related to data YOU have imported into OpenERP.


To access the record that contains the External ID for a particular database record, visit
Settings --> Technical --> Sequences and Identifiers --> External Identifiers

Each External ID maps to a Database Record ID. You will see that an External ID is constructed by a concatenation of the Module and External Identifier field.


ID and Export before change:

image description


image description


ID and Export after change:

image description


image description

Avatar
Discard
Author

Hi Ray, yes I've seen such approach and it can actually fix my needs, but I wondered if there was a way to do it in batch for all the "wrong" records importing some sort of csv file. Eternal ID, in my mind, should be exactly what the name suggests: the ID coming from an external source. And that's what I will use it for: connect the exported data to a different app. I think, but I might be wrong, that a simple csv file with just two columns, the primary key for the record and the "new" value for the external ID should do the work, but I can't figure out the right combination of fields to use.

Author

You got it perfectly right, that's exactly what I need to do, but I wonder: is there a way to change the external id from state_us_105 to state_us_110 using a csv file so that I can change all my "wrong" record as a whole instead of doing it by hand one record a time? What combination of columns should such a file contain to get the job done? I tried different combinations (with a csv containing just one record for testing) with no luck: I couldn't find a way to update the external id. Or the validate process fails either a new record is created!

Best Answer

If you can access the postgres db directly you can alter the database, external ids are store in the ir_model_data table.

The colum "res_model" is the name of the model, "res_id" is the database id, "module" is the name of the module which will be "__import__" if the record has been imported or "__export__" if the record has been created in odoo and then exported, "name" is the external id.

for example

update ir_model_data set name='new_external_id' where res_model='res.partner' and res_id=100;

will change the external id of the partner with id = 100.


BUT YOU NEED TO BE VERY CAREFUL.

Avatar
Discard
Best Answer

Hy,

External ID are very sensitive parts of OpenERP. In order to get things getting better you have to rework as the server does in its porcess while updating modules. First Identify the view you want to be updated through an XML Id. Consider its name and its ID in the URL. Then go to Configuration > sequences & Ids > External Ids and filter on the object ir.ui.view and the ID you kept before. Check if you have an XML id defind here for you view. If it is not the case, that means that you won't be able to update your view by updating a module. Two possibilities for you : - recreate in OpenERP via web a new external id with the same name and same module as the one you have in your module and set the res_id to the ID already identified - You already have one but with a weird xml_id. So consider my first item and try to find why there was such a weird xml_id associéted to your view. Then consider to break the weird association or maybe consider duplicating the view as well as xml_id

Hope it could help

Avatar
Discard
Author

Thank you, I'm not actually trying to update a view, but the database itself. I will use the external id to move data into another application in which the external id is the primary key for the customer (or to update records in openerp with the other app data; it work fine base upon eternal id). I tried to figure out how to make such an update exporting all the columns from the external identifiers section, but I haven't been able to find a combination of columns form my csv so that I can update the records with the wrong external id. Opererp won't update, at least it creates a new record!

Hy Andrea, I think you forget something, once the modules have been loaded in OpenERP, all the views that are used are the one stored in database. I'm not sure to understand what you really want? Do you need to export arch + external_id? if it's the case, consider exporting datas from the ir.ui.view menu the one that list all the views in OpenERP

Author

What I need is a way to update the external id for some customer that got the wrong external id (my mistake during an import, all the other datas are correct) using a csv file instead of doing it by hand one by one. When I export, for example, customer data in a csv file, I will use the external ID to match customer PK in another app and do what I got to do. It's not a matter of module or view, the problem regards the data: since I can change the external id value by hand, as shown below, I'd like to find a way to do it in batch using a csv file. Hope now my needs are clearer.