Odoo calls Zato
Odoo automation rules and webhooks posting record changes to Zato REST channels.
The previous chapters showed Zato services calling Odoo. Integrations work in the other direction too - Odoo can invoke your services whenever something happens in its database, e.g. a sale order is confirmed and the warehouse system needs to know about it. This is what Odoo's automation rules with webhooks are for, available out of the box since Odoo 17.
The receiving service
On the Zato side, the integration is a service mounted on a REST channel. The one below receives a notification about a confirmed order and passes it on:
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class OnOrderConfirmed(Service):
name = 'demo.odoo.on-order-confirmed'
input = 'id', 'name', 'amount_total'
def handle(self) -> 'None':
# Local alias for readability
request = self.request.input
# Log what Odoo sent us
self.logger.info('Order confirmed -> %s (%s)', request.name, request.amount_total)
# This is where the order is handed over to other systems,
# e.g. a warehouse platform or an accounting one.
# Confirm the receipt to Odoo
self.response.payload = {'status': 'received'}
Create a channel for the service in the Dashboard under Connections > Channels > REST, e.g. with /api/orders/confirmed as its URL path, and assign a security definition to it, e.g. Basic Auth - the resulting address is what Odoo will invoke.
The automation rule in Odoo
In Odoo, go to Settings > Technical > Automation Rules and create a rule:
- Model: Sales Order
- Trigger: Stage is set to - Sales Order, i.e. the rule fires when a quotation becomes a confirmed order
- Action: Send Webhook Notification
- URL: the address of your REST channel, e.g. https://example.com/api/orders/confirmed
- Fields to send: ID, Order Reference, Total - these arrive in the service as id, name and amount_total
From now on, each time an order is confirmed in Odoo, the service runs with that order's data on input. The same mechanism works for any model and any trigger Odoo supports - new CRM leads, invoice state changes, inventory moves and everything else.