1. Event-Driven Architecture
Use @api.model.create() and @api.model.write() overrides or @api.onchange/@api.depends to detect changes in:
-
product.template and product.product (for product sync)
-
stock.move, stock.picking, and stock.quant (for inventory sync)
Each change triggers an outbound API call to the other database.
2. Custom REST APIs on Each Odoo Instance
Create a custom module in each database to expose endpoints like:
-
POST /api/sync/product → create/update product
-
POST /api/sync/stock → update inventory quantities or stock moves
Use Odoo’s @http.route to build REST APIs using the http.Controller.
3. Two-Way Sync Logic
-
Each product and stock update in DB1 triggers a call to DB2.
-
Each update in DB2 does the same to DB1.
-
Use a sync origin identifier to avoid circular loops:
-
e.g., if DB1 sends an update, DB2 will mark it as origin=DB1 and not echo it back.
4. Use Global Unique Identifiers (UUIDs)
Each product should carry a unique sync_id or external_id that maps across both databases.
Example:
python
CopyEdit
product.sync_uuid = uuid.uuid4()
This ensures mapping even if internal IDs differ.
5. Use Job Queue for Reliability
Use the Queue Job module (queue_job from OCA) to:
-
Queue sync jobs
-
Retry failed deliveries
-
Avoid losing data during temporary downtime
Optional: Use RabbitMQ or Celery for advanced queuing.
6. Secure the Communication
-
Use HTTPS for all API traffic
-
Use token-based authentication or API keys
-
Optionally whitelist IP addresses
7. Conflict Handling and Logging
-
Log all sync events in a custom model (sync.log) for debugging
-
Detect and skip redundant updates using last_sync_timestamp or change hashes
8. Inventory Sync Best Practices
Sync quantities only, not the full move history:
-
Use stock.quant or stock.inventory to update quantities
-
For real stock moves (like shipments), sync only validated transfers
-
Avoid syncing draft or canceled operations.
Thanks & Regards,
Email :- contact@datainteger.com