Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 base_preset_param/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/social/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/social/issues/new?body=module:%20base_preset_param%0Aversion:%2014.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
-------

* Therp BV

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

- ``Therp BV <https://therp.nl>``\ \_:

- 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 <https://github.com/OCA/social/tree/14.0/base_preset_param>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions base_preset_param/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
14 changes: 14 additions & 0 deletions base_preset_param/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2026 Therp BV <https://therp.nl>.
# 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,
}
3 changes: 3 additions & 0 deletions base_preset_param/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import ir_config_parameter
29 changes: 29 additions & 0 deletions base_preset_param/models/ir_config_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2026 Therp BV <https://therp.nl>.
# 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)
3 changes: 3 additions & 0 deletions base_preset_param/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Therp BV <https://therp.nl>`_:

* Ronald Portier
49 changes: 49 additions & 0 deletions base_preset_param/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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()
....
```
Binary file added base_preset_param/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading