diff --git a/server_environment_files_sample/default/base.conf b/server_environment_files_sample/default/base.conf index bf92248..6c89d11 100644 --- a/server_environment_files_sample/default/base.conf +++ b/server_environment_files_sample/default/base.conf @@ -8,3 +8,5 @@ ged_folder = /my_mounting_point/ged/ [wkhtml2pdf] lib_path = /xxx/xxx/lib/wkhtmltopdf-linux-i386-0-9-9 +[ir.config_parameter] +ircp_from_config=default_config_value diff --git a/server_environment_files_sample/test/base.conf b/server_environment_files_sample/test/base.conf index 036aea7..badd8b7 100644 --- a/server_environment_files_sample/test/base.conf +++ b/server_environment_files_sample/test/base.conf @@ -8,5 +8,5 @@ ged_folder = /tmp/ged/ lib_path = /myHome/lib/wkhtmltopdf-linux-i386-0-9-9 [ir.config_parameter] -ircp_from_config=config_value +ircp_from_config=test_config_value ircp_empty= diff --git a/server_environment_ir_config_parameter/__manifest__.py b/server_environment_ir_config_parameter/__manifest__.py index ccbc546..d4fcb0c 100644 --- a/server_environment_ir_config_parameter/__manifest__.py +++ b/server_environment_ir_config_parameter/__manifest__.py @@ -7,7 +7,7 @@ Override System Parameters from server environment file""", 'version': '12.0.1.0.0', 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'author': 'ACSONE SA/NV, GRAP, Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/server-env/', 'depends': [ 'server_environment', diff --git a/server_environment_ir_config_parameter/models/ir_config_parameter.py b/server_environment_ir_config_parameter/models/ir_config_parameter.py index 3097d77..4e52329 100644 --- a/server_environment_ir_config_parameter/models/ir_config_parameter.py +++ b/server_environment_ir_config_parameter/models/ir_config_parameter.py @@ -15,53 +15,36 @@ class IrConfigParameter(models.Model): is_environment = fields.Boolean( string="Defined by environment", - compute="_compute_is_environment", + compute="_compute_environment", help="If check, the value in the database will be ignored" " and alternatively, the system will use the key defined" " in your odoo.cfg environment file.") + value = fields.Text(string="Database Value") + + environment_value = fields.Text( + string="Environment Value", + compute="_compute_environment", + help="Alternative value, set in your odoo.cfg environment file.") + @api.multi - def _compute_is_environment(self): + def _compute_environment(self): for parameter in self: parameter.is_environment = serv_config.has_option( SECTION, parameter.key) + if parameter.is_environment: + parameter.environment_value = serv_config.get( + SECTION, parameter.key) + else: + parameter.environment_value = False @api.model def get_param(self, key, default=False): - value = super().get_param(key, default=None) 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, )) - if cvalue != value: - # we write in db on first access; - # should we have preloaded values in database at, - # server startup, modules loading their parameters - # from data files would break on unique key error. - self.sudo().set_param(key, cvalue) - value = cvalue - if value is None: - return default - return value - - @api.model - def create(self, vals): - 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)) - return super().create(vals) - - @api.multi - def write(self, vals): - for rec in self: - 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)) - else: - newvals = vals - super().write(newvals) - return True + return cvalue + return super().get_param(key, default=default) diff --git a/server_environment_ir_config_parameter/readme/DESCRIPTION.rst b/server_environment_ir_config_parameter/readme/DESCRIPTION.rst index 141459e..36d8734 100644 --- a/server_environment_ir_config_parameter/readme/DESCRIPTION.rst +++ b/server_environment_ir_config_parameter/readme/DESCRIPTION.rst @@ -1 +1,6 @@ -Override System Parameters from server environment file. \ No newline at end of file +Override System Parameters from server environment file. + +Displays both columns in the ``ir.config_parameter`` form and tree views, +the "Database Value" and the "Environment Value", if set. + +.. figure:: ../static/description/ir_config_parameter_tree.png diff --git a/server_environment_ir_config_parameter/static/description/ir_config_parameter_tree.png b/server_environment_ir_config_parameter/static/description/ir_config_parameter_tree.png new file mode 100644 index 0000000..66618c5 Binary files /dev/null and b/server_environment_ir_config_parameter/static/description/ir_config_parameter_tree.png differ diff --git a/server_environment_ir_config_parameter/tests/config_param_test.xml b/server_environment_ir_config_parameter/tests/config_param_test.xml index 61303a8..bed8a67 100644 --- a/server_environment_ir_config_parameter/tests/config_param_test.xml +++ b/server_environment_ir_config_parameter/tests/config_param_test.xml @@ -1,6 +1,12 @@ - - ircp_from_config - value_from_xml + + ircp_from_xml + value_1_from_xml + + + ircp_from_config + value_2_from_xml + + diff --git a/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py b/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py index 8843f79..7196ee1 100644 --- a/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py +++ b/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py @@ -19,62 +19,28 @@ class TestEnv(common.TransactionCase): get_resource_path(module, filepath), {}, 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') - - 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) - - 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) - 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) + def test_regular_case(self): + """ if a parameter is set only in the ir_config_parameter it should + be returned""" + self._load_xml( + 'server_environment_ir_config_parameter', + 'tests/config_param_test.xml' + ) + value = self.ICP.get_param('ircp_from_xml') + self.assertEqual(value, 'value_1_from_xml') + def test_override_xmldata(self): + """ if a parameter is in ir_config_parameter table AND + in the odoo.cfg file, the file value should be used.""" 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') + self.assertEqual(value, 'test_config_value') diff --git a/server_environment_ir_config_parameter/views/view_ir_config_parameter.xml b/server_environment_ir_config_parameter/views/view_ir_config_parameter.xml index 71e3550..78016f2 100644 --- a/server_environment_ir_config_parameter/views/view_ir_config_parameter.xml +++ b/server_environment_ir_config_parameter/views/view_ir_config_parameter.xml @@ -11,7 +11,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - + + + + + {'invisible': [('is_environment', '=', True)]} @@ -21,13 +25,14 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + {'readonly': [('is_environment', '=', True)]} - {'readonly': [('is_environment', '=', True)]} + {'invisible': [('is_environment', '=', True)]}