[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
This commit is contained in:
@@ -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.")
|
||||
|
||||
|
||||
@@ -105,8 +105,9 @@
|
||||
<div invisible="trigger != 'on_webhook'">
|
||||
<field name="record_getter" string="Target Record"/>
|
||||
<div>
|
||||
<span colspan="2" class="text-muted"> Available variables: </span>
|
||||
<ul colspan="2" class="text-muted">
|
||||
<div class="text-muted"><i class="fa fa-info-circle"/> The default target record getter will work out-of-the-box for any webhook coming from another Odoo instance.</div>
|
||||
<span class="text-muted"> Available variables: </span>
|
||||
<ul class="text-muted">
|
||||
<li><code>env</code>: environment on which the action is triggered</li>
|
||||
<li><code>model</code>: model of the record on which the action is triggered; is a void recordset</li>
|
||||
<li><code>time</code>, <code>datetime</code>, <code>dateutil</code>, <code>timezone</code>: useful Python libraries</li>
|
||||
@@ -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]"
|
||||
/>
|
||||
<field name="name" class="text-truncate" />
|
||||
|
||||
Reference in New Issue
Block a user