Skip to content

Commit

Permalink
[ADD] webhook_(base,incoming): receive and send webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangtrann committed Jul 26, 2024
1 parent 848c21f commit 208010b
Show file tree
Hide file tree
Showing 34 changed files with 2,011 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/webhook_base/odoo/addons/webhook_base
6 changes: 6 additions & 0 deletions setup/webhook_base/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/webhook_incoming/odoo/addons/webhook_incoming
6 changes: 6 additions & 0 deletions setup/webhook_incoming/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
82 changes: 82 additions & 0 deletions webhook_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
============
Webhook Base
============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8bdaa6bf8f8de957410bd7bde59aa2ef3a84eaecce4da8d7d349b040e297dd77
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebhook-lightgray.png?logo=github
:target: https://github.com/OCA/webhook/tree/16.0/webhook_base
:alt: OCA/webhook
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/webhook-16-0/webhook-16-0-webhook_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/webhook&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Create a webhook consumer to send request to an endpoint when the automated action is triggered.

Go to *Webhooks > Webhook Consumers* and add a consumer to receive requests upon trigger. The body
template is drafted using Jinja. After adding a new Webhook Consumer, go to Automated Action and
add a new one, choose Custom Webhook for action to execute, and choose the corresponding consumer.

You can config to have the webhook executed by queue job by choosing *Delay Execution*.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/webhook/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/webhook/issues/new?body=module:%20webhook_base%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Hoang Tran

Contributors
~~~~~~~~~~~~

* Hoang Tran <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/webhook <https://github.com/OCA/webhook/tree/16.0/webhook_base>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions webhook_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions webhook_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Hoang Tran <[email protected]>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Webhook Base",
"summary": "Webhook to publish events based on automated triggers",
"version": "16.0.0.0.1",
"author": "Hoang Tran,Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/webhook",
"depends": [
"base",
"base_automation",
"queue_job",
],
"data": [
"security/ir.model.access.csv",
"data/queue_data.xml",
"views/webhook_consumer_views.xml",
"views/webhook_logging_views.xml",
"views/ir_action_server_views.xml",
"views/menus.xml",
],
"installable": True,
}
19 changes: 19 additions & 0 deletions webhook_base/data/queue_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='utf-8' ?>
<odoo>
<record id="webhook_channel" model="queue.job.channel">
<field name="name">webhook</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<record id="job_webhook_provider" model="queue.job.function">
<field name="model_id" ref="model_webhook_consumer" />
<field name="method">execute_action</field>
<field name="channel_id" ref="webhook_channel" />
</record>

<record id="job_webhook_provider_graphql" model="queue.job.function">
<field name="model_id" ref="model_webhook_consumer" />
<field name="method">execute_graphql_action</field>
<field name="channel_id" ref="webhook_channel" />
</record>
</odoo>
3 changes: 3 additions & 0 deletions webhook_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import webhook_consumer
from . import webhook_logging
from . import ir_action_server
22 changes: 22 additions & 0 deletions webhook_base/models/ir_action_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Hoang Tran <[email protected]>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ServerAction(models.Model):
_inherit = "ir.actions.server"

state = fields.Selection(
selection_add=[("custom_webhook", "Custom Webhook")],
ondelete={"custom_webhook": "cascade"},
)
webhook_consumer_id = fields.Many2one(
"webhook.consumer",
string="Webhook",
)

def _run_action_custom_webhook_multi(self, eval_context):
records = eval_context.get("records", self.model_id.browse())
self.webhook_consumer_id.action_batch_execute(records)
return eval_context.get("action")

Check warning on line 22 in webhook_base/models/ir_action_server.py

View check run for this annotation

Codecov / codecov/patch

webhook_base/models/ir_action_server.py#L20-L22

Added lines #L20 - L22 were not covered by tests
Loading

0 comments on commit 208010b

Please sign in to comment.