Skip to content
Permalink
Browse files

⬆️1️⃣1️⃣ port base_automation_webhook

  • Loading branch information...
yelizariev committed Aug 12, 2019
1 parent df0bfd7 commit 7a1afb682cf50b6fcbbffced5b728ca61e58be87
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
@@ -18,7 +17,7 @@
"currency": "EUR",

"depends": [
"base_action_rule",
"base_automation",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
@@ -35,7 +34,7 @@
"uninstall_hook": None,

"auto_install": False,
"installable": False,
"installable": True,

# "demo_title": "Outgoing Webhooks",
# "demo_addons": [
@@ -2,21 +2,17 @@
<!-- Copyright 2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
<odoo>
<record id="test_action" model="ir.actions.server">
<field name="name">Server Action for unittests</field>
<field name="model_id" ref="base.model_res_partner"/>

<record id="test_rule_on_create" model="base.automation">
<field name="name">Base Automation: test rule on create</field>
<field name="state">code</field>
<field name="code">
log("code is executed")
# don't make actual request, but just check the package is available
requests.get
</field>
</record>

<record id="test_rule" model="base.action.rule">
<field name="name">Test rule</field>
<field name="kind">on_create</field>
<field name="trigger">on_create</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="server_action_ids" eval="[(4, ref('base_automation_webhook.test_action'))]"/>
</record>

</odoo>
@@ -9,27 +9,25 @@ Configuration

* `Activate Developer Mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__
* Open menu ``[[ Settings ]] >> Technical >> Automation >> Automated Actions``
* Create new record and attach an action to **Server actions to run** field.
The action must have field **Action To Do** set to *Execute Python Code*.
* Create new record and set field **Action To Do** to *Execute Python Code*.
For example:

* **Name**: *Test*
* **Action Name**: *Test*
* **Model**: *Contact*
* **Trigger Condition**: *On Creation*
* **Filter**: Optional. You can specify a condition that must be satisfied before executing the Rule.
* **Server actions to run**:

* **Action Name**: *Test Action*
* **Action To Do**: *Execute Python Code*
* **Condition**: Optional. You can specify a condition that must be satisfied before executing the Action.
* **Python Code**:
::
WEBHOOK="https://PASTE-YOUR-WEBHOOK-URL"
data = {
"partner_id": record.id,
"partner_name": record.name,
}
requests.post(WEBHOOK, data)
* **Before Update Domain**: Optional. You can specify a condition that must be
satisfied before executing the Rule. The field may not be available
depending on **Trigger Condition** value.
* **Action To Do**: *Execute Python Code*
* **Apply on**: Optional. You can specify a condition that must be satisfied before executing the Action.
* **Python Code**:
::
WEBHOOK="https://PASTE-YOUR-WEBHOOK-URL"
data = {
"partner_id": record.id,
"partner_name": record.name,
}
requests.post(WEBHOOK, data)

* Save everything

@@ -45,5 +43,7 @@ Handling field changing

If you need to call a webhook on updating specific field, do as following:

* set Rule's **Filter** to a domain like ``FIELD is not equal to TARGET_VALUE``
* set Action's **Condition** to a domain like ``FIELD is equal to TARGET_VALUE``
* set **Before Update Domain** to a domain like ``[['FIELD', '!=', TARGET_VALUE]]``
* set **Apply On** to a domain like ``[['FIELD', '=', TARGET_VALUE]]``

RESULT: webhook will be sent only when field value is changed to *TARGET_VALUE*.
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

# The file name is choosen in favor of model name in next odoo versions
# The file name is incorrect and should be called ir_actions_server.py instead
from odoo import models, api
import requests

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

0 comments on commit 7a1afb6

Please sign in to comment.
You can’t perform that action at this time.