[IMP] server_environmnet_ir_config_parameter: display in the config parameter list and form views the new field is_environment, and make the key and values readonly if checked

This commit is contained in:
Sylvain LE GAL 2020-10-16 11:32:23 +02:00 committed by Benoit Aimont
parent 786a8122f4
commit ef1f8ac22e
4 changed files with 57 additions and 2 deletions

View File

@ -10,4 +10,7 @@
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-env",
"depends": ["server_environment"],
"data": [
"views/view_ir_config_parameter.xml",
],
}

View File

@ -1,10 +1,10 @@
# 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, fields, models
from odoo.exceptions import UserError
from odoo.addons.server_environment import serv_config
from odoo.addons.server_environment.server_env import serv_config
SECTION = "ir.config_parameter"
@ -13,6 +13,18 @@ class IrConfigParameter(models.Model):
_inherit = "ir.config_parameter"
is_environment = fields.Boolean(
string="Defined by environment",
compute="_compute_is_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.",
)
def _compute_is_environment(self):
for parameter in self:
parameter.is_environment = serv_config.has_option(SECTION, parameter.key)
@api.model
def get_param(self, key, default=False):
value = super().get_param(key, default=None)

View File

@ -1,3 +1,4 @@
* Stéphane Bidoul <stephane.bidoul@acsone.eu> (https://acsone.eu)
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
* Gilles Meyomesse <gilles.meyomesse@acsone.eu> (https://acsone.eu)
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_ir_config_parameter_tree" model="ir.ui.view">
<field name="model">ir.config_parameter</field>
<field name="inherit_id" ref="base.view_ir_config_list" />
<field name="arch" type="xml">
<field name="value" position="after">
<field name="is_environment" />
</field>
</field>
</record>
<record id="view_ir_config_parameter_form" model="ir.ui.view">
<field name="model">ir.config_parameter</field>
<field name="inherit_id" ref="base.view_ir_config_form" />
<field name="arch" type="xml">
<field name="value" position="after">
<field name="is_environment" />
</field>
<field name="key" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_environment', '=', True)]}</attribute>
</field>
<field name="value" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_environment', '=', True)]}</attribute>
</field>
</field>
</record>
</odoo>