diff --git a/base_preset_param/README.rst b/base_preset_param/README.rst new file mode 100644 index 0000000000..be4b2c059c --- /dev/null +++ b/base_preset_param/README.rst @@ -0,0 +1,133 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================= +Base Preset Param +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:257bddc3f6dfccea7700af174ca5d4d234807c30ddf3e10eeeb9e24e9d4d4a03 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/14.0/base_preset_param + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-base_preset_param + :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/social&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Many Odoo modules retrieve system parameter information embedded in +other functions that make it difficult to adapt the place information is +retrieved from. + +A point in case is the configuration of Client ID and Client Secret +Value, where both the fetchmail_outlook module and the microsoft_outlook +module just assume that an Odoo database can only be connected to one +Microsoft profile, and therefore have the information in a system +parameter. + +This module makes it possible to preset the value to be retrieved from a +system parameter in the context, making no assumptions of where the +alternative values will come from, allowing other modules to override +the standard methods. + +How to use +========== + +Suppose there is some Odoo method that has retrieving system parameter +information without using an overridable function for this: + +:: + + def _compute_outlook_uri(self): + Config = self.env['ir.config_parameter'].sudo() + microsoft_outlook_client_id = Config.get_param("microsoft_outlook_client_id") + ... + for record in self: + # More code + +However we have multiple connections with each their own value for +client id. + +With help of this module we can do: + +:: + + class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + microsoft_outlook_client_identifier = fields.Char( + "Outlook Client Id", + help="Specific client_id for this server", + ) + ..... + def _compute_outlook_uri(self): + self.ensure_one() + preset_self = self.with_context( + preset_microsoft_outlook_client_id=self.microsoft_outlook_client_identifier, + ) + uri = super(IrMailServer, preset_self)._compute_outlook_uri() + .... + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Therp BV + +Contributors +------------ + +- ``Therp BV ``\ \_: + + - Ronald Portier + +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/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_preset_param/__init__.py b/base_preset_param/__init__.py new file mode 100644 index 0000000000..83e553ac46 --- /dev/null +++ b/base_preset_param/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/base_preset_param/__manifest__.py b/base_preset_param/__manifest__.py new file mode 100644 index 0000000000..9828a27f6d --- /dev/null +++ b/base_preset_param/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 Therp BV . +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Base Preset Param", + "version": "14.0.1.0.0", + "author": "Therp BV, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Tools", + "website": "https://github.com/OCA/social", + "depends": [ + "base", + ], + "installable": True, +} diff --git a/base_preset_param/models/__init__.py b/base_preset_param/models/__init__.py new file mode 100644 index 0000000000..a9fd6e096d --- /dev/null +++ b/base_preset_param/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import ir_config_parameter diff --git a/base_preset_param/models/ir_config_parameter.py b/base_preset_param/models/ir_config_parameter.py new file mode 100644 index 0000000000..4dc953084d --- /dev/null +++ b/base_preset_param/models/ir_config_parameter.py @@ -0,0 +1,29 @@ +# Copyright 2026 Therp BV . +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +"""Patch get_param for microsoft client_id and client_secret. + +Might actually be used for any system parameter. + +To avoid having to re-implement a lot of the standard functions that assume +client_id and client_secret are defined in ir.config_parameter, we will patch get_param +to return these values if they have already been set in the context. +""" +from odoo import api, models + + +class IrConfigParameter(models.Model): + _inherit = "ir.config_parameter" + + @api.model + def get_param(self, key, default=False): + """Retrieve the value for a given key. + + Override to return value from context, if set there. This is to help + modules to override functions that expect a value from a system parameter + but already have the value set in some other way. + """ + preset_key = f"preset_{key}" + preset_value = self.env.context.get(preset_key, False) + if preset_value: + return preset_value + return super().get_param(key, default=default) diff --git a/base_preset_param/readme/CONTRIBUTORS.md b/base_preset_param/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..9527288e83 --- /dev/null +++ b/base_preset_param/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +* `Therp BV `_: + + * Ronald Portier diff --git a/base_preset_param/readme/DESCRIPTION.md b/base_preset_param/readme/DESCRIPTION.md new file mode 100644 index 0000000000..439ee78b15 --- /dev/null +++ b/base_preset_param/readme/DESCRIPTION.md @@ -0,0 +1,49 @@ +Many Odoo modules retrieve system parameter information embedded in other +functions that make it difficult to adapt the place information is retrieved +from. + +A point in case is the configuration of Client ID and Client Secret Value, where +both the fetchmail_outlook module and the microsoft_outlook module just assume +that an Odoo database can only be connected to one Microsoft profile, and therefore +have the information in a system parameter. + +This module makes it possible to preset the value to be retrieved from a system +parameter in the context, making no assumptions of where the alternative values +will come from, allowing other modules to override the standard methods. + +How to use +========== + +Suppose there is some Odoo method that has retrieving system parameter information +without using an overridable function for this: + +``` + def _compute_outlook_uri(self): + Config = self.env['ir.config_parameter'].sudo() + microsoft_outlook_client_id = Config.get_param("microsoft_outlook_client_id") + ... + for record in self: + # More code +``` + +However we have multiple connections with each their own value for client id. + +With help of this module we can do: + +``` +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + microsoft_outlook_client_identifier = fields.Char( + "Outlook Client Id", + help="Specific client_id for this server", + ) + ..... + def _compute_outlook_uri(self): + self.ensure_one() + preset_self = self.with_context( + preset_microsoft_outlook_client_id=self.microsoft_outlook_client_identifier, + ) + uri = super(IrMailServer, preset_self)._compute_outlook_uri() + .... +``` diff --git a/base_preset_param/static/description/icon.png b/base_preset_param/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/base_preset_param/static/description/icon.png differ diff --git a/base_preset_param/static/description/index.html b/base_preset_param/static/description/index.html new file mode 100644 index 0000000000..d509c6cffa --- /dev/null +++ b/base_preset_param/static/description/index.html @@ -0,0 +1,460 @@ + + + + + +README.rst + + + +
+ + +Odoo Community Association +
+

Base Preset Param

+ +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

Many Odoo modules retrieve system parameter information embedded in +other functions that make it difficult to adapt the place information is +retrieved from.

+

A point in case is the configuration of Client ID and Client Secret +Value, where both the fetchmail_outlook module and the microsoft_outlook +module just assume that an Odoo database can only be connected to one +Microsoft profile, and therefore have the information in a system +parameter.

+

This module makes it possible to preset the value to be retrieved from a +system parameter in the context, making no assumptions of where the +alternative values will come from, allowing other modules to override +the standard methods.

+
+

How to use

+

Suppose there is some Odoo method that has retrieving system parameter +information without using an overridable function for this:

+
+def _compute_outlook_uri(self):
+    Config = self.env['ir.config_parameter'].sudo()
+    microsoft_outlook_client_id = Config.get_param("microsoft_outlook_client_id")
+    ...
+    for record in self:
+       # More code
+
+

However we have multiple connections with each their own value for +client id.

+

With help of this module we can do:

+
+class IrMailServer(models.Model):
+    _inherit = "ir.mail_server"
+
+    microsoft_outlook_client_identifier = fields.Char(
+        "Outlook Client Id",
+        help="Specific client_id for this server",
+    )
+    .....
+    def _compute_outlook_uri(self):
+        self.ensure_one()
+        preset_self = self.with_context(
+            preset_microsoft_outlook_client_id=self.microsoft_outlook_client_identifier,
+        )
+        uri = super(IrMailServer, preset_self)._compute_outlook_uri()
+        ....
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+
    +
  • Therp BV <https://therp.nl>_:
      +
    • Ronald Portier
    • +
    +
  • +
+
+
+

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.

+

This module is part of the OCA/social project on GitHub.

+

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

+
+
+
+
+ + diff --git a/base_preset_param/tests/__init__.py b/base_preset_param/tests/__init__.py new file mode 100644 index 0000000000..e149cff82e --- /dev/null +++ b/base_preset_param/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import test_ir_config_parameter diff --git a/base_preset_param/tests/test_ir_config_parameter.py b/base_preset_param/tests/test_ir_config_parameter.py new file mode 100644 index 0000000000..d5c24691ac --- /dev/null +++ b/base_preset_param/tests/test_ir_config_parameter.py @@ -0,0 +1,17 @@ +# Copyright 2026 Therp BV . +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo.tests.common import SavepointCase + + +class TestIrConfigParameter(SavepointCase): + def test_override_get_param(self): + PARAM = "microsoft_outlook_client_identifier" + ICP = self.env["ir.config_parameter"].sudo() + ICP.set_param(PARAM, "test_client_id") + no_preset_value = ICP.get_param(PARAM) + self.assertEqual(no_preset_value, "test_client_id") + preset_value = ICP.with_context( + preset_microsoft_outlook_client_identifier="another_client_id", + ).get_param(PARAM) + self.assertEqual(preset_value, "another_client_id") diff --git a/setup/base_preset_param/odoo/addons/base_preset_param b/setup/base_preset_param/odoo/addons/base_preset_param new file mode 120000 index 0000000000..1b4babd15a --- /dev/null +++ b/setup/base_preset_param/odoo/addons/base_preset_param @@ -0,0 +1 @@ +../../../../base_preset_param \ No newline at end of file diff --git a/setup/base_preset_param/setup.py b/setup/base_preset_param/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/base_preset_param/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)