Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] edi_webservice_oca: Migration to 17.0 #123

Merged
merged 33 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2e98eb8
[ADD] edi_webservice
etobella Dec 10, 2020
1a76394
[UPD] Update edi_webservice.pot
oca-travis Mar 15, 2021
99d010d
[UPD] README.rst
OCA-git-bot Mar 15, 2021
c8e7ebf
[MIG] edi_webservice_oca: Migration to 14.0
etobella May 14, 2021
1925424
[UPD] Update edi_webservice_oca.pot
oca-travis May 26, 2021
797dc1b
[UPD] README.rst
OCA-git-bot May 26, 2021
596683c
edi: improve backend view extension
simahawk Sep 17, 2021
39b562f
edi_webservice_oca: add missing page label
simahawk Oct 13, 2021
4ce83cd
[UPD] Update edi_webservice_oca.pot
oca-travis Oct 13, 2021
7323e3c
edi_webservice_oca 14.0.1.1.0
OCA-git-bot Oct 13, 2021
a65e246
[MIG] edi_service_oca: Migration to 15.0
pedroguirao Feb 28, 2022
e3da2ca
[UPD] Update edi_webservice_oca.pot
Mar 1, 2022
9283aa6
[UPD] README.rst
OCA-git-bot Mar 1, 2022
033a6f1
[IMP] edi_webservice: Promote to Beta
pedrobaeza Mar 3, 2022
bd1e7d5
edi_webservice_oca 15.0.1.1.0
OCA-git-bot Mar 9, 2022
3261bc0
[UPD] README.rst
OCA-git-bot Sep 3, 2023
6a1f2b7
edi_webservice: fix tests setup
simahawk Sep 12, 2023
2e13691
edi_webservice_oca 15.0.1.1.1
OCA-git-bot Sep 12, 2023
971e269
[UPD] README.rst
OCA-git-bot Sep 12, 2023
43dd6bf
[IMP] edi_webservice_oca: pre-commit stuff
EvaSForgeFlow Jul 10, 2023
d1a2538
[MIG] edi_webservice_oca: Migration to 16.0
EvaSForgeFlow Jul 10, 2023
9d7735b
[UPD] Update edi_webservice_oca.pot
Nov 9, 2023
1cf45e3
edi_webservice: add generic send component
simahawk Aug 26, 2022
feeed69
edi_webservice: allow to send bytes
simahawk Oct 3, 2022
ff49884
edi_webservice_oca: Adapt to 15.0
etobella Sep 15, 2023
816a0b3
rename documentation file
gurneyalex Feb 28, 2024
6423d9c
[UPD] Update edi_webservice_oca.pot
Mar 5, 2024
49fe5ec
[BOT] post-merge updates
OCA-git-bot Mar 5, 2024
8894fdd
Added translation using Weblate (Italian)
mymage May 13, 2024
c766ec8
Translated using Weblate (Italian)
mymage May 13, 2024
ee8e6da
[IMP] edi_webservice_oca: pre-commit auto fixes
john-herholz-dt Jul 27, 2024
e2eab18
[MIG] edi_webservica_oca: Migration to 17.0
john-herholz-dt Jul 27, 2024
499ef8a
[FIX] edi_webservice_oca: add ``responses`` to test-requirements.txt
SilvioC2C Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions edi_webservice_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
==============
EDI WebService
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b49ba422bb24a12e29e1ec5342b317b7ccc48c4f4af81746a22fffd872ca3224
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github
:target: https://github.com/OCA/edi-framework/tree/17.0/edi_webservice_oca
:alt: OCA/edi-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-framework-17-0/edi-framework-17-0-edi_webservice_oca
: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/edi-framework&target_branch=17.0
:alt: Try me on Runboat

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

Plug webservice module within EDI framework. Allows to configure attach
webservices on an EDI backend and/or on an exchange type.

**Table of contents**

.. contents::
:local:

Configuration
=============

Go to "EDI -> Config -> Backends" and edit or create one. Find the tab
"Webservice" and add a webservice. On the webservice record you can
specify all the general parameters to connect to the service (see
webservice README for more details).

If you want to take full control on if/how the webservice is used you
can do it via exchange type's advanced settings.

Hence, assuming your webservice has a URL configured as
\`\ https://my.endpoint/%7Bpath%7D\ \`:

::

components:
send:
usage: webservice.send # or any custom component usage inheriting from this
work_ctx:
webservice:
method: post # mandatory
url_params:
path: endpoint1/foo

For each call related to this type, you'll get a POST request against
https://my.endpoint/endpoint/foo.

``url_params`` can contain all the keys need for URL interpolation.

In addition, you can user ``url`` to override the full url used for the
call per exchange type.

If you want to send data as bytes you can use the option send_as_bytes
like:

::

[...]
webservice:
send_as_bytes: true
[...]

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi-framework/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/edi-framework/issues/new?body=module:%20edi_webservice_oca%0Aversion:%2017.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
-------

* Creu Blanca
* Camptocamp

Contributors
------------

- Enric Tobella <[email protected]>
- Simone Orsi <[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.

.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
:target: https://github.com/etobella
:alt: etobella
.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-etobella| |maintainer-simahawk|

This module is part of the `OCA/edi-framework <https://github.com/OCA/edi-framework/tree/17.0/edi_webservice_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions edi_webservice_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import components
from . import models
17 changes: 17 additions & 0 deletions edi_webservice_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "EDI WebService",
"summary": """
Defines webservice integration from EDI Exchange records""",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"development_status": "Beta",
"author": "Creu Blanca, Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["etobella", "simahawk"],
"website": "https://github.com/OCA/edi-framework",
"depends": ["edi_oca", "webservice"],
"data": ["views/edi_backend.xml", "security/ir.model.access.csv"],
"demo": ["demo/edi_backend.xml"],
}
1 change: 1 addition & 0 deletions edi_webservice_oca/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import send
48 changes: 48 additions & 0 deletions edi_webservice_oca/components/send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, exceptions

from odoo.addons.component.core import Component


class EDIWebserviceSend(Component):
"""Generic component for webservice requests.

Configuration is expected to come from the work ctx key `webservice`.
You can easily pass via exchange type advanced settings.
"""

_name = "edi.webservice.send"
_inherit = [
"edi.component.mixin",
]
_usage = "webservice.send"

def __init__(self, work_context):
super().__init__(work_context)
self.ws_settings = getattr(work_context, "webservice", {})
self.webservice_backend = self.backend.webservice_backend_id

def send(self):
method, pargs, kwargs = self._get_call_params()
return self.webservice_backend.call(method, *pargs, **kwargs)

def _get_call_params(self):
try:
method = self.ws_settings["method"].lower()
except KeyError as err:
raise exceptions.UserError(
_("`method` is required in `webservice` type settings.")
) from err
pargs = self.ws_settings.get("pargs", [])
kwargs = self.ws_settings.get("kwargs", {})
kwargs["data"] = self._get_data()
return method, pargs, kwargs

def _get_data(self):
# By sending as bytes `requests` won't try to guess and/or alter the encoding.
# TODO: add tests
as_bytes = self.ws_settings.get("send_as_bytes")
return self.exchange_record._get_file_content(as_bytes=as_bytes)
20 changes: 20 additions & 0 deletions edi_webservice_oca/demo/edi_backend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="demo_ws_backend" model="webservice.backend">
<field name="name">Demo backend</field>
<field name="tech_name">edi_demo_ws</field>
<field name="protocol">http</field>
<field name="url">https://foo.test/{endpoint}</field>
<field name="content_type">application/xml</field>
<field name="auth_type">none</field>
</record>
<record id="demo_edi_backend_type" model="edi.backend.type">
<field name="name">Demo backend type WS</field>
<field name="code">demo_ws_backend</field>
</record>
<record id="demo_edi_backend" model="edi.backend">
<field name="name">Demo backend w/ WS</field>
<field name="backend_type_id" ref="demo_edi_backend_type" />
<field name="webservice_backend_id" ref="demo_ws_backend" />
</record>
</odoo>
24 changes: 24 additions & 0 deletions edi_webservice_oca/i18n/edi_webservice.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * edi_webservice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: edi_webservice
#: model:ir.model,name:edi_webservice.model_edi_backend
msgid "EDI Backend"
msgstr ""

#. module: edi_webservice
#: model:ir.model.fields,field_description:edi_webservice.field_edi_backend__webservice_backend_id
msgid "Webservice Backend"
msgstr ""
36 changes: 36 additions & 0 deletions edi_webservice_oca/i18n/edi_webservice_oca.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * edi_webservice_oca
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: edi_webservice_oca
#: model:ir.model,name:edi_webservice_oca.model_edi_backend
msgid "EDI Backend"
msgstr ""

#. module: edi_webservice_oca
#: model_terms:ir.ui.view,arch_db:edi_webservice_oca.edi_backend_view_form
msgid "Webservice"
msgstr ""

#. module: edi_webservice_oca
#: model:ir.model.fields,field_description:edi_webservice_oca.field_edi_backend__webservice_backend_id
msgid "Webservice Backend"
msgstr ""

#. module: edi_webservice_oca
#. odoo-python
#: code:addons/edi_webservice_oca/components/send.py:0
#, python-format
msgid "`method` is required in `webservice` type settings."
msgstr ""
39 changes: 39 additions & 0 deletions edi_webservice_oca/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * edi_webservice_oca
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-05-13 12:34+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: edi_webservice_oca
#: model:ir.model,name:edi_webservice_oca.model_edi_backend
msgid "EDI Backend"
msgstr "Backend EDI"

#. module: edi_webservice_oca
#: model_terms:ir.ui.view,arch_db:edi_webservice_oca.edi_backend_view_form
msgid "Webservice"
msgstr "Servizio web"

#. module: edi_webservice_oca
#: model:ir.model.fields,field_description:edi_webservice_oca.field_edi_backend__webservice_backend_id
msgid "Webservice Backend"
msgstr "Backend servizio web"

#. module: edi_webservice_oca
#. odoo-python
#: code:addons/edi_webservice_oca/components/send.py:0
#, python-format
msgid "`method` is required in `webservice` type settings."
msgstr "`method` è richiesto nelle impostazioni tipo `webservice`."
1 change: 1 addition & 0 deletions edi_webservice_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import edi_backend
34 changes: 34 additions & 0 deletions edi_webservice_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class EdiBackend(models.Model):
_inherit = "edi.backend"

webservice_backend_id = fields.Many2one("webservice.backend")
_webservice_actions = ("send", "receive")

def _get_component_usage_candidates(self, exchange_record, key):
candidates = super()._get_component_usage_candidates(exchange_record, key)
if not self.webservice_backend_id or key not in self._webservice_actions:
return candidates
return [f"webservice.{key}"] + candidates

def _component_match_attrs(self, exchange_record, key):
# Override to inject `webservice_protocol` as match attribute
res = super()._component_match_attrs(exchange_record, key)
if not self.webservice_backend_id or key not in self._webservice_actions:
return res
res["webservice_protocol"] = self.webservice_backend_id.protocol
return res

def _component_sort_key(self, component_class):
res = super()._component_sort_key(component_class)
# Override to give precedence by `webservice_protocol` when needed.
if not self.webservice_backend_id:
return res
return (
1 if getattr(component_class, "_webservice_protocol", False) else 0,
) + res
3 changes: 3 additions & 0 deletions edi_webservice_oca/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Loading
Loading