Ir al contenido
Menú
Se marcó esta pregunta

I have a setup where two Odoo 16 databases are hosted on the same server, each accessed through separate domains and separate Odoo installations. The user wants real-time synchronization of products and inventory between both databases. 
Specifically:
a) The same set of products should exist in both databases. 
b) Any inventory change (inbound or outbound) in one database should automatically update the stock level in the other. 
c) At any point in time, stock levels must remain consistent across both systems. 

What is the best technical approach to implement this real-time, two-way synchronization of products and inventory between these two Odoo instances?

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
abr 22
1764
0
jun 20
2038
2
may 24
2389
1
jun 17
5056
1
sept 15
3679