From 19dfe602d4d413976aba0073b5db07990c3e5cfe Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 11 Dec 2017 15:50:04 +0100 Subject: [PATCH] Create module server_environment_config_settings --- server_environment_config_settings/README.rst | 91 +++++++++++++++++++ .../__init__.py | 1 + .../__manifest__.py | 15 +++ .../models/__init__.py | 1 + .../models/res_config_settings.py | 30 ++++++ 5 files changed, 138 insertions(+) create mode 100644 server_environment_config_settings/README.rst create mode 100644 server_environment_config_settings/__init__.py create mode 100644 server_environment_config_settings/__manifest__.py create mode 100644 server_environment_config_settings/models/__init__.py create mode 100644 server_environment_config_settings/models/res_config_settings.py diff --git a/server_environment_config_settings/README.rst b/server_environment_config_settings/README.rst new file mode 100644 index 0000000..6dedf5a --- /dev/null +++ b/server_environment_config_settings/README.rst @@ -0,0 +1,91 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================== +Server Environment Config Settings +================================== + +Override res.config.settings from server environment file. +Before using this module, you must be familiar with the +server_environment module. + +Installation +============ + +There is no specific installation instruction for this module. + +Configuration +============= + +To configure this module, you need to add a section ``[res.config.settings]`` to +you server_environment_files configurations, where the key should match the field +definition on `res.config.settings` model. + +Moreover, you have to add a dependency on server_environment_files module, to +the module where the field is defined. + +When the wizard is called, fields will be automatically filled with the value +defined in server_environment_files. + +For example you want to change `auth_oauth_google_client_id` defined in +*auth_oauth* module: + +.. code:: + + [res.config.settings] + auth_oauth_google_client_id=dummy_key_for_google_oauth + + +Then you should add in __manifest__.py: + +.. code:: + + 'depends': ['base', *'auth_oauth'*] + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/11.0 + +Known issues / Roadmap +====================== + +* Admin user has to execute the wizard for the values to be stored in the database. +* Not tested for group_* and module_* fields + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Akim Juillerat + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/server_environment_config_settings/__init__.py b/server_environment_config_settings/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/server_environment_config_settings/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/server_environment_config_settings/__manifest__.py b/server_environment_config_settings/__manifest__.py new file mode 100644 index 0000000..38e49e6 --- /dev/null +++ b/server_environment_config_settings/__manifest__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + 'name': 'Server Environment Config Settings', + 'summary': """ + Override config settings from server environment file""", + 'version': '11.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Camptocamp SA,Odoo Community Association (OCA)', + 'website': 'https://odoo-community.org/', + 'depends': [ + 'server_environment', + ], +} diff --git a/server_environment_config_settings/models/__init__.py b/server_environment_config_settings/models/__init__.py new file mode 100644 index 0000000..0deb68c --- /dev/null +++ b/server_environment_config_settings/models/__init__.py @@ -0,0 +1 @@ +from . import res_config_settings diff --git a/server_environment_config_settings/models/res_config_settings.py b/server_environment_config_settings/models/res_config_settings.py new file mode 100644 index 0000000..04bf2e4 --- /dev/null +++ b/server_environment_config_settings/models/res_config_settings.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _ +from odoo.exceptions import UserError +from odoo.addons.server_environment import serv_config + + +SECTION = 'res.config.settings' + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + if serv_config.has_section(SECTION): + for option in serv_config.options(SECTION): + import pdb; pdb.set_trace() + value = res.get(option) + conf_value = serv_config.get(SECTION, option) + if not conf_value: + raise UserError( + _('Option %s is empty in server_environment_file') + % option) + if conf_value != value: + res[option] = conf_value + return res