Allow third parties services to contact a base_automation via the route "/web/hook/<uuid>" Base Automations now have an additional field "record_getter", which contains a python expression that should return a record set on which the webhook will apply. A base automation configured as a webhook takes in its eval_context, the "payload", that is, a shortcut to the request's data. task-id-3450200 Part-of: odoo/odoo#135932 Co-authored-by: Damien Bouvy <dbo@odoo.com>
24 lines
920 B
Python
24 lines
920 B
Python
from odoo.http import request, route, Controller
|
|
|
|
from json import JSONDecodeError
|
|
|
|
class BaseAutomationController(Controller):
|
|
|
|
@route(['/web/hook/<string:rule_uuid>'], type='http', auth='none', methods=['GET', 'POST'], csrf=False, save_session=False)
|
|
def call_webhook_http(self, rule_uuid, **kwargs):
|
|
""" Execute an automation webhook """
|
|
rule = request.env['base.automation'].sudo().search([('webhook_uuid', '=', rule_uuid)])
|
|
if not rule:
|
|
return request.make_json_response({'status': 'error'}, status=404)
|
|
|
|
try:
|
|
data = request.get_json_data()
|
|
except JSONDecodeError:
|
|
data = kwargs or {}
|
|
|
|
try:
|
|
rule._execute_webhook(data)
|
|
except Exception: # noqa: BLE001
|
|
return request.make_json_response({'status': 'error'}, status=500)
|
|
return request.make_json_response({'status': 'ok'}, status=200)
|