Skip to content
Permalink
Browse files

Merge pull request #691 from yelizariev/misc-addons-10.0-openapi-fix-…

…refs

openapi 10.0
  • Loading branch information...
yelizariev committed Aug 11, 2019
2 parents 6c0b796 + cdb12b7 commit 5687fca0fc41205c8218d1159b315ce3a72a1987
@@ -0,0 +1,47 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3

===================
Outgoing Webhooks
===================

The modules extends ``base.action.rule`` model to allow sending webhook on Odoo events. Technically, it adds ``requests`` package to eval context.

Credits
=======

Contributors
------------
* `Ivan Yelizariev <https://it-projects.info/team/yelizariev>`__

Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`__

Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__

To get a guaranteed support
you are kindly requested to purchase the module
at `odoo apps store <https://apps.odoo.com/apps/modules/10.0/base_automation_webhook/>`__.

Thank you for understanding!

`IT-Projects Team <https://www.it-projects.info/team>`__

Further information
===================

Demo: http://runbot.it-projects.info/demo/misc-addons/10.0

HTML Description: https://apps.odoo.com/apps/modules/10.0/base_automation_webhook/

Usage instructions: `<doc/index.rst>`_

Changelog: `<doc/changelog.rst>`_

Notifications on updates: `via Atom <https://github.com/it-projects-llc/misc-addons/commits/10.0/base_automation_webhook.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/misc-addons/commits/10.0/base_automation_webhook.atom>`_

Tested on Odoo 10.0 af3f6e596df6a558de8b465019028ff8cc2d7439
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
@@ -0,0 +1,50 @@
# -*- 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).
{
"name": """Outgoing Webhooks""",
"summary": """Send webhook on Odoo events: when record is created/updated/deleted""",
"category": "Extra Tools",
# "live_test_url": "http://apps.it-projects.info/shop/product/DEMO-URL?version=10.0",
"images": [],
"version": "10.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Ivan Yelizariev",
"support": "apps@it-projects.info",
"website": "https://apps.odoo.com/apps/modules/10.0/base_automation_webhook/",
"license": "LGPL-3",
# "price": 9.00,
# "currency": "EUR",

"depends": [
"base_action_rule",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
],
"demo": [
"data/base_automation_demo.xml"
],
"qweb": [
],

"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,

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

# "demo_title": "Outgoing Webhooks",
# "demo_addons": [
# ],
# "demo_addons_hidden": [
# ],
# "demo_url": "DEMO-URL",
# "demo_summary": "{SHORT_DESCRIPTION_OF_THE_MODULE}",
# "demo_images": [
# "images/MAIN_IMAGE",
# ]
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="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). -->
<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"/>
<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="model_id" ref="base.model_res_partner"/>
<field name="server_action_ids" eval="[(4, ref('base_automation_webhook.test_action'))]"/>
</record>

</odoo>
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**
@@ -0,0 +1,38 @@
===================
Outgoing Webhooks
===================

* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way

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*.
For example:

* **Name**: *Test*
* **Model**: *Contact*
* **Trigger Condition**: *On Creation*
* **Server actions to run**:

* **Action Name**: *Test Action*
* **Action To Do**: *Execute Python Code*
* **Python Code**: ```
WEBHOOK="https://PASTE-YOUR-WEBHOOK-URL"
data = {
"partner_id": record.id,
"partner_name": record.name,
}
requests.post(WEBHOOK, data)
```

* Save everything

Usage
=====

* Make corresponding action (in our example, create new Contact)
* RESULT: the event is notified via webhook
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import base_automation
@@ -0,0 +1,18 @@
# -*- 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
from odoo import models, api
import requests


class IrActionsServer(models.Model):

_inherit = 'ir.actions.server'

@api.model
def _get_eval_context(self, action=None):
eval_context = super(IrActionsServer, self)._get_eval_context(action)
eval_context['requests'] = requests
return eval_context
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import test_base
@@ -0,0 +1,14 @@
# -*- 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).

from odoo.tests.common import TransactionCase


class TestAutomation(TransactionCase):
at_install = True
post_install = True

def test_requests(self):
"""Check that requests package is available"""
self.env['res.partner'].create({'name': 'New Contact'})
@@ -2,9 +2,9 @@
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3

===============================
REST API / Open API (Swagger)
===============================
==========================
REST API/Openapi/Swagger
==========================

Set up REST API and export Open API (Swagger) specification file for
integration with whatever you need.
@@ -1,3 +1,6 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import controllers
from . import models

def post_load():
from .controllers import apijsonrequest
@@ -2,7 +2,7 @@
# Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": """REST API / Open API (Swagger)""",
"name": """REST API/Openapi/Swagger""",
"summary": """Set up API and export OpenAPI specification file for integration with whatever system you need""",
"category": "",
# "live_test_url": "",
@@ -41,7 +41,7 @@
# "static/src/xml/configure_api_button.xml"
],

"post_load": None,
"post_load": "post_load",
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,
@@ -1,4 +1,5 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import main
from . import api
from . import pinguin
@@ -2,7 +2,7 @@
# Copyright 2018, XOE Solutions
# Copyright 2018 Rafis Bikbov <https://it-projects.info/team/bikbov>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

# pylint: disable=redefined-builtin
import json
import logging

@@ -58,6 +58,10 @@ class ApiV1Controller(http.Controller):
_api_endpoint_model = _api_endpoint + '/<model>'
# ReadOne # UpdateOne # UnlinkOne
_api_endpoint_model_id = _api_endpoint + '/<model>/<int:id>'
# Call Method on Singleton Record
_api_endpoint_model_id_method = _api_endpoint + '/<model>/<int:id>/<method_name>'
# Call Method on RecordSet
_api_endpoint_model_method_ids = _api_endpoint + '/<model>/<method_name>/<ids>'
# Get Reports
_api_report_docids = _api_endpoint + '/report/<any(pdf, html):converter>/<report_external_id>/<docids>'

@@ -69,7 +73,7 @@ class ApiV1Controller(http.Controller):
@pinguin.route(
_api_endpoint_model,
methods=['POST'],
type='http',
type='api',
auth='none',
csrf=False)
def create_one__POST(self, namespace, model, **data):
@@ -115,7 +119,7 @@ def read_one__GET(self, namespace, model, id, **kw):
@pinguin.route(
_api_endpoint_model_id,
methods=['PUT'],
type='http',
type='json',
auth='none',
csrf=False)
def update_one__PUT(self, namespace, model, id, **data):
@@ -143,7 +147,7 @@ def unlink_one__DELETE(self, namespace, model, id, **data):

# Call Method on Singleton Record (optional: method parameters)
@pinguin.route(
_api_endpoint_model_id,
_api_endpoint_model_id_method,
methods=['PATCH'],
type='http',
auth='none',
@@ -161,7 +165,7 @@ def call_method_one__PATCH(self, namespace, model, id, method_name, method_param

# Call Method on RecordSet (optional: method parameters)
@pinguin.route(
_api_endpoint_model,
_api_endpoint_model_method_ids,
methods=['PATCH'],
type='http',
auth='none',

0 comments on commit 5687fca

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