Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding external Ids to Partners in OpenERP withouth a new module

My Question is a bit complex and iam new to OpenERP.

I have an external database and an OpenERP. the external one isn't PostgreSQL. MY job is that I need to synchronize the partners in the two databases. External one being the more important. This means that if the external one's data change so does the OpenERp's, but if OpenERP's data changes nothing changes onthe external one.

  • I can access to the external database, and using XML RCP I have acces to OpenERP's as well.

  • I can import data from the external database simply with XML RCP but the problem is the sync.

  • I can't just INSERT the modified partner and delete the old one
    because i have no way to identify the old one.

  • I need to UPDATE it. But then i need an id that says which is which. and external ID.

  • To my knowledge OpenERP can handle external IDs.

How does this work? and how can i add an external ID to my res.partner using this?

I was told that I cant create a new module for this alone I need to use the internal ID works.

like image 649
NaGeL182 Avatar asked Jan 16 '13 10:01

NaGeL182


1 Answers

Short answer: have a look at the way the CSV Import and Export wizard work - exporting a record automatically creates an external identifier so you can re-import that same CSV and the record will be updated rather than re-created.

Long answer:
OpenERP stores external IDs in the ir.model.data table, which you can access in the user interface via the Settings menu 1. This simple table maps an "External Identifier" in the form module_name.record_identifier to a pair (model,res_id) that points to the actual table and row.

These external IDs are used to find the database-local row that corresponds to a record created by some external source: a module (hence the module-based namespace) or an imported CSV file, usually.

For example the external identifier base.EUR maps to the database records that holds the EUR currency in the database, and is owned by the base module.

As of version 6.1, OpenERP automatically creates new external identifiers for all OpenERP records that are exported using the sidebar Export wizard: they're exported in a CSV column named id.

And if such an id column is present in a CSV file that is imported via the Import wizard, OpenERP will also create an external identifier to remember it. And when the external identifier already exists, the record is updated rather than created.

In theory, all you have to do is produce a proper CSV file with an extra id column2 from your master database (you could even use the actual DB ID), and import it in OpenERP. You should then be able to re-import updated versions of this CSV file whenever you want.

References:

  • The Import and Export wizards basically call the API methods export_data and import_data, so you can script this via XML-RPC if needed.
  • The ir.model.data model stores the external identifiers (historically called XML IDs because it corresponds to the id field of XML records in module data files).

1 In OpenERP 6.1 it is located under Settings>Configuration>Sequences & Identifiers>External Identifiers, and in OpenERP version 7 under Settings>Technical>Sequences & Identifiers>External Identifiers.

2 can be any string with no dot "." character in it: it will be stored in a special __export__ module namespace)

like image 163
odony Avatar answered Sep 24 '22 16:09

odony