[MIG][11.0] server_environment_ir_config_parameter
This commit is contained in:
parent
f69a9e3894
commit
ed571581c6
|
|
@ -38,7 +38,7 @@ For example you can use this module in combination with web_environment_ribbon:
|
|||
|
||||
.. 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/10.0
|
||||
:target: https://runbot.odoo-community.org/runbot/149/11.0
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
|
@ -1,20 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# Copyright 2016-2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Server Environment Ir Config Parameter',
|
||||
'summary': """
|
||||
Override System Parameters from server environment file""",
|
||||
'version': '10.0.1.0.1',
|
||||
'version': '11.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
|
||||
'website': 'https://odoo-community.org/',
|
||||
'website': 'https://github.com/OCA/server-env/',
|
||||
'depends': [
|
||||
'server_environment',
|
||||
],
|
||||
'data': [
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# Copyright 2016-2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models, _
|
||||
|
|
@ -16,7 +15,7 @@ class IrConfigParameter(models.Model):
|
|||
|
||||
@api.model
|
||||
def get_param(self, key, default=False):
|
||||
value = super(IrConfigParameter, self).get_param(key, default=None)
|
||||
value = super().get_param(key, default=None)
|
||||
if serv_config.has_option(SECTION, key):
|
||||
cvalue = serv_config.get(SECTION, key)
|
||||
if not cvalue:
|
||||
|
|
@ -40,7 +39,7 @@ class IrConfigParameter(models.Model):
|
|||
if serv_config.has_option(SECTION, key):
|
||||
# enforce value from config file
|
||||
vals = dict(vals, value=serv_config.get(SECTION, key))
|
||||
return super(IrConfigParameter, self).create(vals)
|
||||
return super().create(vals)
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
|
|
@ -51,5 +50,5 @@ class IrConfigParameter(models.Model):
|
|||
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
||||
else:
|
||||
newvals = vals
|
||||
super(IrConfigParameter, rec).write(newvals)
|
||||
super().write(newvals)
|
||||
return True
|
||||
|
|
@ -0,0 +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>
|
||||
</odoo>
|
||||
|
|
@ -1,20 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# Copyright 2016-2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from cStringIO import StringIO
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import common
|
||||
from odoo.tools import convert
|
||||
from odoo.tools import convert_file
|
||||
from odoo.modules.module import get_resource_path
|
||||
|
||||
|
||||
class TestEnv(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEnv, self).setUp()
|
||||
super().setUp()
|
||||
self.ICP = self.env['ir.config_parameter']
|
||||
|
||||
def _load_xml(self, module, filepath):
|
||||
convert_file(
|
||||
self.env.cr, module,
|
||||
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
|
||||
|
|
@ -68,14 +72,9 @@ class TestEnv(common.TransactionCase):
|
|||
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
||||
|
||||
def test_override_xmldata(self):
|
||||
xml = """<odoo>
|
||||
<data>
|
||||
<record model="ir.config_parameter" id="some_record_id">
|
||||
<field name="key">ircp_from_config</field>
|
||||
<field name="value">value_from_xml</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>"""
|
||||
convert.convert_xml_import(self.env.cr, 'testmodule', StringIO(xml))
|
||||
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')
|
||||
Loading…
Reference in New Issue