[IMP] server_environment_ir_config_parameter: black, isort

This commit is contained in:
Akim Juillerat 2020-01-28 16:32:00 +01:00 committed by Marcos Oitaben
parent f02e50dd0b
commit 193f88ddac
17 changed files with 119 additions and 98 deletions

View File

@ -14,13 +14,13 @@ Server Environment Ir Config Parameter
: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--env-lightgray.png?logo=github
:target: https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter
:target: https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter
:alt: OCA/server-env
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-env-12-0/server-env-12-0-server_environment_ir_config_parameter
:target: https://translation.odoo-community.org/projects/server-env-13-0/server-env-13-0-server_environment_ir_config_parameter
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/254/12.0
:target: https://runbot.odoo-community.org/runbot/254/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -73,7 +73,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/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 <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2013.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.
@ -111,6 +111,6 @@ 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/server-env <https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter>`_ project on GitHub.
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -2,14 +2,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Server Environment Ir Config Parameter',
'summary': """
"name": "Server Environment Ir Config Parameter",
"summary": """
Override System Parameters from server environment file""",
'version': '13.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/server-env/',
'depends': [
'server_environment',
],
"version": "13.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-env/",
"depends": ["server_environment"],
}

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr ""

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr ""

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr ""

View File

@ -20,7 +20,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr "sleutel %s is leeg in server_environment_file"

View File

@ -20,7 +20,7 @@ msgstr ""
"2:1));\n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr ""

View File

@ -1,12 +1,12 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * server_environment_ir_config_parameter
# * server_environment_ir_config_parameter
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -14,7 +14,7 @@ msgstr ""
"Plural-Forms: \n"
#. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format
msgid "Key %s is empty in server_environment_file"
msgstr ""
@ -23,4 +23,3 @@ msgstr ""
#: model:ir.model,name:server_environment_ir_config_parameter.model_ir_config_parameter
msgid "System Parameter"
msgstr ""

View File

@ -1,17 +1,17 @@
# Copyright 2016-2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, _
from odoo import _, api, models
from odoo.exceptions import UserError
from odoo.addons.server_environment import serv_config
SECTION = 'ir.config_parameter'
SECTION = "ir.config_parameter"
class IrConfigParameter(models.Model):
_inherit = 'ir.config_parameter'
_inherit = "ir.config_parameter"
@api.model
def get_param(self, key, default=False):
@ -19,9 +19,9 @@ class IrConfigParameter(models.Model):
if serv_config.has_option(SECTION, key):
cvalue = serv_config.get(SECTION, key)
if not cvalue:
raise UserError(_("Key %s is empty in "
"server_environment_file") %
(key, ))
raise UserError(
_("Key %s is empty in " "server_environment_file") % (key,)
)
if cvalue != value:
# we write in db on first access;
# should we have preloaded values in database at,
@ -35,7 +35,7 @@ class IrConfigParameter(models.Model):
@api.model
def create(self, vals):
key = vals.get('key')
key = vals.get("key")
if serv_config.has_option(SECTION, key):
# enforce value from config file
vals = dict(vals, value=serv_config.get(SECTION, key))
@ -43,7 +43,7 @@ class IrConfigParameter(models.Model):
def write(self, vals):
for rec in self:
key = vals.get('key') or rec.key
key = vals.get("key") or rec.key
if serv_config.has_option(SECTION, key):
# enforce value from config file
newvals = dict(vals, value=serv_config.get(SECTION, key))

View File

@ -14,4 +14,4 @@ For example you can use this module in combination with web_environment_ribbon:
.. code::
[ir.config_parameter]
ribbon.name=DEV
ribbon.name=DEV

View File

@ -1,2 +1,2 @@
This module is maintained by:
* Odoo Community Association
* Odoo Community Association

View File

@ -1 +1 @@
Override System Parameters from server environment file.
Override System Parameters from server environment file.

View File

@ -1,4 +1,4 @@
When the user modifies System Parameters that are defined in the config
file, the changes are ignored. It would be nice to display which system
parameters come from the config file and possibly make their key and value
readonly in the user interface.
readonly in the user interface.

View File

@ -1,2 +1,2 @@
Before using this module, you must be familiar with the
server_environment module.
server_environment module.

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-env-12-0/server-env-12-0-server_environment_ir_config_parameter"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/254/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-env-13-0/server-env-13-0-server_environment_ir_config_parameter"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/254/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Override System Parameters from server environment file.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
@ -418,7 +418,7 @@ readonly in the user interface.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -449,7 +449,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter">OCA/server-env</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter">OCA/server-env</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -1,6 +1,6 @@
<odoo>
<record model="ir.config_parameter" id="some_record_id">
<field name="key">ircp_from_config</field>
<field name="value">value_from_xml</field>
</record>
<record model="ir.config_parameter" id="some_record_id">
<field name="key">ircp_from_config</field>
<field name="value">value_from_xml</field>
</record>
</odoo>

View File

@ -2,79 +2,103 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests import common
from odoo.tools import convert_file
from odoo.modules.module import get_resource_path
from odoo.tools import convert_file
from odoo.addons.server_environment.tests.common import ServerEnvironmentCase
from ..models import ir_config_parameter
class TestEnv(common.TransactionCase):
class TestEnv(ServerEnvironmentCase):
def setUp(self):
super().setUp()
self.ICP = self.env['ir.config_parameter']
self.ICP = self.env["ir.config_parameter"]
self.env_config = (
"[ir.config_parameter]\n" "ircp_from_config=config_value\n" "ircp_empty=\n"
)
def _load_xml(self, module, filepath):
convert_file(
self.env.cr, module,
self.env.cr,
module,
get_resource_path(module, filepath),
{}, mode='init', noupdate=False, kind='test')
{},
mode="init",
noupdate=False,
kind="test",
)
def test_get_param(self):
""" Get system parameter from config """
# it's not in db
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertFalse(res)
# read so it's created in db
value = self.ICP.get_param('ircp_from_config')
self.assertEqual(value, 'config_value')
# now it's in db
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertEqual(len(res), 1)
self.assertEqual(res.value, 'config_value')
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
# it's not in db
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertFalse(res)
# read so it's created in db
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")
# now it's in db
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 1)
self.assertEqual(res.value, "config_value")
def test_set_param_1(self):
""" We can't set parameters that are in config file """
# when creating, the value is overridden by config file
self.ICP.set_param('ircp_from_config', 'new_value')
value = self.ICP.get_param('ircp_from_config')
self.assertEqual(value, 'config_value')
# when writing, the value is overridden by config file
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertEqual(len(res), 1)
res.write({'value': 'new_value'})
value = self.ICP.get_param('ircp_from_config')
self.assertEqual(value, 'config_value')
# unlink works normally...
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertEqual(len(res), 1)
res.unlink()
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertEqual(len(res), 0)
# but the value is recreated when getting param again
value = self.ICP.get_param('ircp_from_config')
self.assertEqual(value, 'config_value')
res = self.ICP.search([('key', '=', 'ircp_from_config')])
self.assertEqual(len(res), 1)
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
# when creating, the value is overridden by config file
self.ICP.set_param("ircp_from_config", "new_value")
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")
# when writing, the value is overridden by config file
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 1)
res.write({"value": "new_value"})
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")
# unlink works normally...
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 1)
res.unlink()
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 0)
# but the value is recreated when getting param again
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 1)
def test_set_param_2(self):
""" We can set parameters that are not in config file """
self.ICP.set_param('some.param', 'new_value')
self.assertEqual(self.ICP.get_param('some.param'), 'new_value')
res = self.ICP.search([('key', '=', 'some.param')])
res.unlink()
res = self.ICP.search([('key', '=', 'some.param')])
self.assertFalse(res)
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
self.ICP.set_param("some.param", "new_value")
self.assertEqual(self.ICP.get_param("some.param"), "new_value")
res = self.ICP.search([("key", "=", "some.param")])
res.unlink()
res = self.ICP.search([("key", "=", "some.param")])
self.assertFalse(res)
def test_empty(self):
""" Empty config values cause error """
with self.assertRaises(UserError):
self.ICP.get_param('ircp_empty')
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
with self.assertRaises(UserError):
self.ICP.get_param("ircp_empty")
self.assertEqual(self.ICP.get_param("ircp_nonexistant"), False)
def test_override_xmldata(self):
self._load_xml(
'server_environment_ir_config_parameter',
'tests/config_param_test.xml'
)
value = self.ICP.get_param('ircp_from_config')
self.assertEqual(value, 'config_value')
with self.load_config(
public=self.env_config, serv_config_class=ir_config_parameter
):
self._load_xml(
"server_environment_ir_config_parameter", "tests/config_param_test.xml"
)
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")