# 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, a built-in feature since Odoo 17.

## The receiving service {#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:

```python
# -*- 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)

        # At this point, the order can be sent on 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](https://zato.io/docs/security/basic-auth.html) - the resulting address is what Odoo will invoke.

## The automation rule in Odoo {#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.

## Learn more {#learn-more}

- [Odoo integrations](https://zato.io/docs/dev/odoo/) - Odoo models from Python services, over XML-RPC and JSON-RPC
- [Reading data](https://zato.io/docs/dev/odoo/reading-data/) - Searching, reading and field lists against any Odoo model
- [Creating records](https://zato.io/docs/dev/odoo/creating-records/) - New partners, leads and orders, with their related records
- [Updating and deleting](https://zato.io/docs/dev/odoo/updating-records/) - Writing to many records at once and removing them
- [Odoo Online](https://zato.io/docs/dev/odoo/odoo-online/) - What differs when the instance is hosted by Odoo
