From f11d98ce7d4dd10c9e89b33554dd50c2ea48c014 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Fri, 20 Oct 2023 15:41:29 +0200 Subject: [PATCH] [IMP] base_automation: default record_getter matches default webhook payload The goal of this commit is to make it simpler for users to match an incoming Odoo webhook automation rules with an outgoing webhook action from another Odoo by having a default record_getter that uses the same syntax as the default payload of a webhook action. Task-3450200 Part-of: odoo/odoo#138804 --- addons/base_automation/models/base_automation.py | 3 ++- addons/base_automation/views/base_automation_views.xml | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/base_automation/models/base_automation.py b/addons/base_automation/models/base_automation.py index ebe5cb4bc76..dcb2031294f 100644 --- a/addons/base_automation/models/base_automation.py +++ b/addons/base_automation/models/base_automation.py @@ -86,7 +86,8 @@ class BaseAutomation(models.Model): ) url = fields.Char(compute='_compute_url') webhook_uuid = fields.Char(string="Webhook UUID", readonly=True, copy=False, default=lambda self: str(uuid4())) - record_getter = fields.Char(help="This code will be run to find on which record the automation rule should be run.\nExample: model.browse(payload.get('recordId')))") + record_getter = fields.Char(default="env[payload.get('_model')].browse(payload.get('id'))", + help="This code will be run to find on which record the automation rule should be run.") log_webhook_calls = fields.Boolean(string="Log Calls", default=False) active = fields.Boolean(default=True, help="When unchecked, the rule is hidden and will not be executed.") diff --git a/addons/base_automation/views/base_automation_views.xml b/addons/base_automation/views/base_automation_views.xml index f2b909822ab..c3d71deb809 100644 --- a/addons/base_automation/views/base_automation_views.xml +++ b/addons/base_automation/views/base_automation_views.xml @@ -105,8 +105,9 @@
- Available variables: -
    +
    The default target record getter will work out-of-the-box for any webhook coming from another Odoo instance.
    + Available variables: +
    • env: environment on which the action is triggered
    • model: model of the record on which the action is triggered; is a void recordset
    • time, datetime, dateutil, timezone: useful Python libraries
    • @@ -156,6 +157,7 @@ 'remove_followers': 'fa-user-times', 'next_activity': 'fa-clock-o', 'sms': 'fa-comments-o', + 'webhook': 'fa-paper-plane', }[record.state.raw_value]" />