Connecting Shopify to Odoo looks simple: fetch orders, push stock. Then the first sale weekend arrives, and with it come duplicated orders, overselling, refunds that never reach accounting and a cron job that is always fifteen minutes behind. I've built and rescued enough e-commerce integrations (Shopify, WooCommerce, Magento) to have a firm opinion on the architecture. Here it is.
Principle 1: push, don't poll
Polling Shopify every few minutes is slow at quiet times and too slow during peaks. Subscribe to webhooks instead: orders/create, orders/updated, refunds/create, products/update and app/uninstalled. Keep a scheduled reconciliation job only as a safety net, to catch anything a webhook missed.
Principle 2: verify, store, answer fast
Shopify expects a quick response and retries otherwise. So the webhook endpoint does exactly three things: verify the HMAC signature, store the raw event, return 200. No order creation happens inside the request.
import base64, hashlib, hmac
class ShopifyWebhook(http.Controller):
@http.route('/shopify/webhook', type='http', auth='public',
methods=['POST'], csrf=False)
def webhook(self, **kw):
req = request.httprequest
raw = req.get_data()
secret = request.env['ir.config_parameter'].sudo().get_param('shopify.api_secret', '')
digest = base64.b64encode(hmac.new(secret.encode(), raw, hashlib.sha256).digest()).decode()
if not hmac.compare_digest(digest, req.headers.get('X-Shopify-Hmac-Sha256', '')):
return request.make_response('invalid signature', status=401)
request.env['shopify.event'].sudo().create({
'topic': req.headers.get('X-Shopify-Topic'),
'webhook_id': req.headers.get('X-Shopify-Webhook-Id'),
'payload': raw.decode(),
})
return request.make_response('ok')
Principle 3: process in a queue, idempotently
A job queue (OCA's queue_job, or a simple event table processed by a cron) turns events into Odoo documents in the background, with retries and a visible error state. Two details make it bullet-proof:
- Unique keys. Put a unique constraint on the webhook id and on the Shopify order id stored on the sale order. A duplicated webhook then simply does nothing.
- Ordered processing per order. An
orders/updatedthat arrives before itsorders/createmust wait, not create a half-empty order.
Mapping that doesn't break
| Shopify | Odoo | Watch out for |
|---|---|---|
| Variant ID / SKU | Product variant | Match on a stored Shopify ID, not on the name |
| Customer | Contact | Guest checkouts, B2B companies, duplicate emails |
| Line + order discounts | Discount lines | Rounding: compare the Odoo total with Shopify's to the paisa |
| Taxes | Fiscal position + taxes | Tax-included prices and per-region rules |
| Location | Warehouse | One Shopify location per Odoo warehouse |
Stock: Odoo is the source of truth
Push available quantity (on hand minus reserved) from Odoo to Shopify whenever a stock move is done, batched per product to respect API rate limits. Never let both systems decrement stock independently, or you will oversell during peaks. For bundles and kits, compute availability from the components.
Refunds and payouts
Refunds create credit notes and, if items come back, a return picking. Shopify payouts arrive in the bank net of fees, so import the payout report and reconcile it as one bank line against the orders and fee entries. Your accountant will thank you at month-end.
Monitoring
Give the operations team a simple event dashboard: done, retrying and failed, with a retry button and the error message in plain language. Most integration "outages" are a single product without a SKU, and a good dashboard turns a support ticket into a 30-second fix.
Summary
Webhooks for speed, a queue for resilience, unique keys for idempotency, and Odoo as the single source of truth for stock. Building or fixing an e-commerce integration? Let's talk.