[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
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
: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
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
@ -1,20 +1,15 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016-2018 ACSONE SA/NV
|
||||||
# Copyright 2016 ACSONE SA/NV
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Server Environment Ir Config Parameter',
|
'name': 'Server Environment Ir Config Parameter',
|
||||||
'summary': """
|
'summary': """
|
||||||
Override System Parameters from server environment file""",
|
Override System Parameters from server environment file""",
|
||||||
'version': '10.0.1.0.1',
|
'version': '11.0.1.0.0',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
|
||||||
'website': 'https://odoo-community.org/',
|
'website': 'https://github.com/OCA/server-env/',
|
||||||
'depends': [
|
'depends': [
|
||||||
'server_environment',
|
'server_environment',
|
||||||
],
|
],
|
||||||
'data': [
|
|
||||||
],
|
|
||||||
'demo': [
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016-2018 ACSONE SA/NV
|
||||||
# Copyright 2016 ACSONE SA/NV
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, models, _
|
from odoo import api, models, _
|
||||||
|
|
@ -16,7 +15,7 @@ class IrConfigParameter(models.Model):
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_param(self, key, default=False):
|
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):
|
if serv_config.has_option(SECTION, key):
|
||||||
cvalue = serv_config.get(SECTION, key)
|
cvalue = serv_config.get(SECTION, key)
|
||||||
if not cvalue:
|
if not cvalue:
|
||||||
|
|
@ -40,7 +39,7 @@ class IrConfigParameter(models.Model):
|
||||||
if serv_config.has_option(SECTION, key):
|
if serv_config.has_option(SECTION, key):
|
||||||
# enforce value from config file
|
# enforce value from config file
|
||||||
vals = dict(vals, value=serv_config.get(SECTION, key))
|
vals = dict(vals, value=serv_config.get(SECTION, key))
|
||||||
return super(IrConfigParameter, self).create(vals)
|
return super().create(vals)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|
@ -51,5 +50,5 @@ class IrConfigParameter(models.Model):
|
||||||
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
||||||
else:
|
else:
|
||||||
newvals = vals
|
newvals = vals
|
||||||
super(IrConfigParameter, rec).write(newvals)
|
super().write(newvals)
|
||||||
return True
|
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-2018 ACSONE SA/NV
|
||||||
# Copyright 2016 ACSONE SA/NV
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from cStringIO import StringIO
|
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tests import common
|
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):
|
class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestEnv, self).setUp()
|
super().setUp()
|
||||||
self.ICP = self.env['ir.config_parameter']
|
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):
|
def test_get_param(self):
|
||||||
""" Get system parameter from config """
|
""" Get system parameter from config """
|
||||||
# it's not in db
|
# it's not in db
|
||||||
|
|
@ -68,14 +72,9 @@ class TestEnv(common.TransactionCase):
|
||||||
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
||||||
|
|
||||||
def test_override_xmldata(self):
|
def test_override_xmldata(self):
|
||||||
xml = """<odoo>
|
self._load_xml(
|
||||||
<data>
|
'server_environment_ir_config_parameter',
|
||||||
<record model="ir.config_parameter" id="some_record_id">
|
'tests/config_param_test.xml'
|
||||||
<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))
|
|
||||||
value = self.ICP.get_param('ircp_from_config')
|
value = self.ICP.get_param('ircp_from_config')
|
||||||
self.assertEqual(value, 'config_value')
|
self.assertEqual(value, 'config_value')
|
||||||
Loading…
Reference in New Issue