Odoo Implementation Services migration script that creates 40,000 res.partner records works exactly once. The second rehearsal creates 40,000 more, and cutover weekend begins with a duplicate-merge ticket for the sales team. This happens in most legacy enterprise resource planning (ERP) moves, because teams run the load several times: staging dry runs, a full rehearsal, and a final delta. This guide shows how Odoo implementation services handle data migration with idempotent loads. You will key every record to an external ID, load in dependency order, and isolate bad rows. The stack is Python 3, Odoo’s XML-RPC API, and PostgreSQL.
Context and Setup
An idempotent migration leaves Odoo in the same state whether you run it once or five times. Odoo supports this through external IDs stored in ir.model.data. According to the Odoo Data Flow documentation, load updates a record when its external ID exists and creates one when it does not.
The target is Odoo 17 Community on PostgreSQL, loaded from legacy CSV exports. You need four things first:
A staging copy of the production database
An API key for a user with import rights
Target modules installed (Contacts, Sales, Inventory)
A stable primary key for every legacy row
One trap deserves a warning. The same documentation notes that setting parent_id on 500 child records can rewrite the parent’s child_ids list 500 times, slowing large imports sharply.
Building the Pipeline for Odoo Implementation Services
The pipeline has three moves: key every row, load in batches, and tune for failure.
Step 1: Derive a Stable External ID from the Legacy Key
In Odoo Implementation Services a stable external ID is a deterministic string built from the legacy primary key. A rerun can only find its earlier records if that key never changes, so avoid row numbers, names, and timestamps. Use a prefix, table, and key:
csv
id,name,parent_id/id
legacy_migration.partner_10432,Acme Dairy,
legacy_migration.partner_10433,Acme Depot,legacy_migration.partner_10432
Step 2: Load in Batches with a Row-Level Fallback
Odoo rejects an entire load batch when one row fails. The script below retries a failed batch row by row, which isolates bad records without halting the run.
python
import csv, xmlrpc.client as rpc
URL, DB, USER, KEY = "https://odoo.example.com", "staging", "mig@example.com", "API_KEY"
uid = rpc.ServerProxy(f"{URL}/xmlrpc/2/common").authenticate(DB, USER, KEY, {})
models = rpc.ServerProxy(f"{URL}/xmlrpc/2/object")
def load(model, header, rows):
# Why: load() upserts by the "id" column, so reruns update instead of duplicating
return models.execute_kw(DB, uid, KEY, model, "load", [header, rows])
def migrate(model, path, size=200):
with open(path, newline="", encoding="utf-8") as f:
header, *rows = csv.reader(f) # first column must be the external ID
failed = []
for i in range(0, len(rows), size):
batch = rows[i:i + size]
if load(model, header, batch)["ids"]:
continue # Why: ids is False when any row fails, and Odoo rolls the batch back
for row in batch: # Why: retry singly to pinpoint the bad row
res = load(model, header, [row])
if not res["ids"]:
failed.append((row[0], res["messages"]))
return failed
Step 3: Weigh Batch Size and Load Order for Odoo Implementation Services
Bigger batches cut transaction overhead but widen the blast radius of one bad row. The Odoo Data Flow guide suggests dropping the batch size from 1,000 to 200 or 100 when imports time out. Load relational data in this order:
Reference data first: countries, units of measure, pricelists.
Partners and products without self-referencing columns.
A second pass setting only parent_id/id fields.
A count check: search_count on ir.model.data for the prefix.
We rejected two alternatives. Raw SQL inserts skip ORM constraints, stored computed fields, and ir.model.data entries. Plain create() calls are not idempotent, so every rerun duplicates data.
Real-World Application
In one of our Odoo implementation services projects at Oodles, a dairy-products client moved manual order and commission workflows onto Odoo Community with PostgreSQL, covering CRM, Manufacturing, Bills of Materials, Inventory, Sales, Purchase, and Accounting.
Key Takeaways
External IDs built from legacy primary keys turn every rerun into an update, not an insert.
Use load instead of create() to get both upserts and row-level error messages.
Odoo rolls back a whole failed batch, so keep a row-by-row fallback.
Set self-referencing fields in a second pass to avoid repeated parent rewrites.
Lower the batch size from 1,000 toward 200 or 100 when timeouts appear.
Have a cutover story or a failing batch? Share it in the comments, or talk to us about Odoo implementation services.
What are Odoo implementation services?
Odoo implementation services cover requirements analysis, configuration, data migration, integrations, testing, training, and go-live support. For developers, migration is usually the riskiest layer, because it must preserve relationships, balances, and external IDs across repeated loads.
How does Odoo’s load() differ from create()?
load takes column headers and rows, resolves external IDs, and either updates or creates records. create() always inserts from field dictionaries. For migrations, load adds idempotent reruns and row-level error messages that create() lacks.
What batch size works best for Odoo imports?
Start near 200 records per transaction and adjust. The Odoo Data Flow guide suggests lowering batches from 1,000 to 200 or 100 after timeouts. Larger batches cut overhead, but one bad row rejects the whole batch.
Can I insert migration data directly into PostgreSQL?
Direct SQL skips ORM constraints, stored computed field updates, mail tracking, and ir.model.data entries, so records exist but misbehave in Odoo. Keep SQL for read-only reconciliation queries, not for writing business records.
How do I import self-referencing fields like parent_id?
Load records in two passes. Pass one creates them without the parent column, and pass two updates only the parent external ID. This avoids dangling references and repeated rewrites of the parent’s child_ids list.
Top comments (0)