diff --git a/iap_alternative_provider/README.rst b/iap_alternative_provider/README.rst new file mode 100644 index 000000000..013669b69 --- /dev/null +++ b/iap_alternative_provider/README.rst @@ -0,0 +1,83 @@ +======================== +IAP Alternative Provider +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/15.0/iap_alternative_provider + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-iap_alternative_provider + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Abstract module that provide base functionality for implementing alternative provider for the IAP application. + +An example of alternative provider can be found in [the `connector-telephony` repository](https://github.com/OCA/connector-telephony), with the module **sms_ovh_http** (sending sms with ovh instead of odoo iap) + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Sébastien BEAU + +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-sebastienbeau| image:: https://github.com/sebastienbeau.png?size=40px + :target: https://github.com/sebastienbeau + :alt: sebastienbeau + +Current `maintainer `__: + +|maintainer-sebastienbeau| + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/iap_alternative_provider/__init__.py b/iap_alternative_provider/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/iap_alternative_provider/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/iap_alternative_provider/__manifest__.py b/iap_alternative_provider/__manifest__.py new file mode 100644 index 000000000..f785d598e --- /dev/null +++ b/iap_alternative_provider/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2020 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +{ + "name": "IAP Alternative Provider", + "summary": "Base module for providing alternative provider for iap apps", + "version": "16.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/server-tools", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainers": ["sebastienbeau"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["iap"], + "data": ["views/iap_account_view.xml"], +} diff --git a/iap_alternative_provider/i18n/ca.po b/iap_alternative_provider/i18n/ca.po new file mode 100644 index 000000000..7592d6943 --- /dev/null +++ b/iap_alternative_provider/i18n/ca.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * iap_alternative_provider +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ca\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" + +#. module: iap_alternative_provider +#: model:ir.model,name:iap_alternative_provider.model_iap_account +msgid "IAP Account" +msgstr "" + +#. module: iap_alternative_provider +#: model_terms:ir.ui.view,arch_db:iap_alternative_provider.iap_account_view_form +msgid "Info" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields,field_description:iap_alternative_provider.field_iap_account__name +msgid "Name" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields.selection,name:iap_alternative_provider.selection__iap_account__provider__odoo +msgid "Odoo IAP" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields,field_description:iap_alternative_provider.field_iap_account__provider +msgid "Provider" +msgstr "" diff --git a/iap_alternative_provider/i18n/iap_alternative_provider.pot b/iap_alternative_provider/i18n/iap_alternative_provider.pot new file mode 100644 index 000000000..dcd15fac1 --- /dev/null +++ b/iap_alternative_provider/i18n/iap_alternative_provider.pot @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * iap_alternative_provider +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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: iap_alternative_provider +#: model:ir.model,name:iap_alternative_provider.model_iap_account +msgid "IAP Account" +msgstr "" + +#. module: iap_alternative_provider +#: model_terms:ir.ui.view,arch_db:iap_alternative_provider.iap_account_view_form +msgid "Info" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields,field_description:iap_alternative_provider.field_iap_account__name +msgid "Name" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields.selection,name:iap_alternative_provider.selection__iap_account__provider__odoo +msgid "Odoo IAP" +msgstr "" + +#. module: iap_alternative_provider +#: model:ir.model.fields,field_description:iap_alternative_provider.field_iap_account__provider +msgid "Provider" +msgstr "" diff --git a/iap_alternative_provider/models/__init__.py b/iap_alternative_provider/models/__init__.py new file mode 100644 index 000000000..966d7e1af --- /dev/null +++ b/iap_alternative_provider/models/__init__.py @@ -0,0 +1 @@ +from . import iap_account diff --git a/iap_alternative_provider/models/iap_account.py b/iap_alternative_provider/models/iap_account.py new file mode 100644 index 000000000..10c2a1324 --- /dev/null +++ b/iap_alternative_provider/models/iap_account.py @@ -0,0 +1,35 @@ +# Copyright 2020 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class IapAccount(models.Model): + _inherit = "iap.account" + _name = "iap.account" + + name = fields.Char() + provider = fields.Selection([("odoo", "Odoo IAP")], required=True, default="odoo") + + def _get_service_from_provider(self): + """In case that the provider only propose one service you can + return the service_name in you module to simplify the user interface""" + return None + + def _set_service_from_provider(self): + for record in self: + service = record._get_service_from_provider() + if service and record.service_name != service: + record.service_name = service + + @api.model_create_multi + def create(self, vals_list): + record = super().create(vals_list) + record._set_service_from_provider() + return record + + def write(self, vals): + super().write(vals) + self._set_service_from_provider() + return True diff --git a/iap_alternative_provider/readme/CONTRIBUTORS.rst b/iap_alternative_provider/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9e0ae5f27 --- /dev/null +++ b/iap_alternative_provider/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sébastien BEAU diff --git a/iap_alternative_provider/readme/DESCRIPTION.rst b/iap_alternative_provider/readme/DESCRIPTION.rst new file mode 100644 index 000000000..85ecbc36e --- /dev/null +++ b/iap_alternative_provider/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Abstract module that provide base functionality for implementing alternative provider for the IAP application. + +An example of alternative provider can be found in [the `connector-telephony` repository](https://github.com/OCA/connector-telephony), with the module **sms_ovh_http** (sending sms with ovh instead of odoo iap) diff --git a/iap_alternative_provider/static/description/icon.png b/iap_alternative_provider/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/iap_alternative_provider/static/description/icon.png differ diff --git a/iap_alternative_provider/static/description/index.html b/iap_alternative_provider/static/description/index.html new file mode 100644 index 000000000..577b176ba --- /dev/null +++ b/iap_alternative_provider/static/description/index.html @@ -0,0 +1,422 @@ + + + + + + +IAP Alternative Provider + + + +
+

IAP Alternative Provider

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

Abstract module that provide base functionality for implementing alternative provider for the IAP application.

+

An example of alternative provider can be found in [the connector-telephony repository](https://github.com/OCA/connector-telephony), with the module sms_ovh_http (sending sms with ovh instead of odoo iap)

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

sebastienbeau

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/iap_alternative_provider/tests/__init__.py b/iap_alternative_provider/tests/__init__.py new file mode 100644 index 000000000..caa11bc67 --- /dev/null +++ b/iap_alternative_provider/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). +# @author Pierre Verkest +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_iap_account diff --git a/iap_alternative_provider/tests/test_iap_account.py b/iap_alternative_provider/tests/test_iap_account.py new file mode 100644 index 000000000..666eaf50b --- /dev/null +++ b/iap_alternative_provider/tests/test_iap_account.py @@ -0,0 +1,53 @@ +# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr). +# @author Pierre Verkest +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from unittest import mock + +from odoo.tests import TransactionCase + + +class IapAccountCase(TransactionCase): + def test_create_odoo_iap(self): + account = self.env["iap.account"].create( + { + "name": "Odoo IAP", + "provider": "odoo", + "service_name": "some-service", + } + ) + self.assertEqual(account.service_name, "some-service") + + def test_create_with_mock(self): + with mock.patch( + "odoo.addons.iap_alternative_provider.models." + "iap_account.IapAccount._get_service_from_provider", + return_value="other-service", + ): + account = self.env["iap.account"].create( + { + "name": "Odoo IAP", + "provider": "odoo", + "service_name": "some-service", + } + ) + self.assertEqual(account.service_name, "other-service") + + def test_write_odoo_iap(self): + account = self.env["iap.account"].create( + { + "name": "Odoo IAP", + "provider": "odoo", + "service_name": "", + } + ) + self.assertEqual(account.service_name, "") + account.write({"service_name": "some-service"}) + self.assertEqual(account.service_name, "some-service") + with mock.patch( + "odoo.addons.iap_alternative_provider.models." + "iap_account.IapAccount._get_service_from_provider", + return_value="other-service", + ): + account.write({"service_name": "some-service-2"}) + self.assertEqual(account.service_name, "other-service") diff --git a/iap_alternative_provider/views/iap_account_view.xml b/iap_alternative_provider/views/iap_account_view.xml new file mode 100644 index 000000000..c3b6226fc --- /dev/null +++ b/iap_alternative_provider/views/iap_account_view.xml @@ -0,0 +1,21 @@ + + + + iap.account + + + + + + + + + + + {'invisible': [('provider', '!=', 'odoo')]} + + + + diff --git a/setup/iap_alternative_provider/odoo/addons/iap_alternative_provider b/setup/iap_alternative_provider/odoo/addons/iap_alternative_provider new file mode 120000 index 000000000..fedcf555f --- /dev/null +++ b/setup/iap_alternative_provider/odoo/addons/iap_alternative_provider @@ -0,0 +1 @@ +../../../../iap_alternative_provider \ No newline at end of file diff --git a/setup/iap_alternative_provider/setup.py b/setup/iap_alternative_provider/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/iap_alternative_provider/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)