Set fields readonly, improve readme and __manifest__

This commit is contained in:
Akim Juillerat 2017-12-12 12:06:27 +01:00
parent 19dfe602d4
commit 11d4bcfdf3
3 changed files with 35 additions and 9 deletions

View File

@ -26,39 +26,42 @@ Moreover, you have to add a dependency on server_environment_files module, to
the module where the field is defined. the module where the field is defined.
When the wizard is called, fields will be automatically filled with the value When the wizard is called, fields will be automatically filled with the value
defined in server_environment_files. defined in server_environment_files, and will be set as read only.
For example you want to change `auth_oauth_google_client_id` defined in For example you want to use google authentification so you define following
*auth_oauth* module: fields in server_environment_files:
.. code:: .. code::
[res.config.settings] [res.config.settings]
module_auth_oauth=True
auth_oauth_google_enabled=True
auth_oauth_google_client_id=dummy_key_for_google_oauth auth_oauth_google_client_id=dummy_key_for_google_oauth
Then you should add in __manifest__.py: Then, as some of these fields are defined in auth_oath modules, you should
add it to server_environment_files/__manifest__.py:
.. code:: .. code::
'depends': ['base', *'auth_oauth'*] 'depends': ['base',
'auth_oauth']
.. 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/11.0 :target: https://runbot.odoo-community.org/runbot/143/11.0
Known issues / Roadmap Known issues / Roadmap
====================== ======================
* Admin user has to execute the wizard for the values to be stored in the database. * Admin user has to execute the wizard for the values to be stored in the database.
* Not tested for group_* and module_* fields
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please <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, 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. help us smashing it by providing a detailed and welcomed feedback.

View File

@ -12,4 +12,6 @@
'depends': [ 'depends': [
'server_environment', 'server_environment',
], ],
'auto_install': False,
'installable': True
} }

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA # Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import json
from lxml import etree
from odoo import models, api, _ from odoo import models, api, _
from odoo.exceptions import UserError from odoo.exceptions import UserError
@ -18,7 +20,6 @@ class ResConfigSettings(models.TransientModel):
res = super(ResConfigSettings, self).get_values() res = super(ResConfigSettings, self).get_values()
if serv_config.has_section(SECTION): if serv_config.has_section(SECTION):
for option in serv_config.options(SECTION): for option in serv_config.options(SECTION):
import pdb; pdb.set_trace()
value = res.get(option) value = res.get(option)
conf_value = serv_config.get(SECTION, option) conf_value = serv_config.get(SECTION, option)
if not conf_value: if not conf_value:
@ -28,3 +29,23 @@ class ResConfigSettings(models.TransientModel):
if conf_value != value: if conf_value != value:
res[option] = conf_value res[option] = conf_value
return res return res
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
res = super(ResConfigSettings, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
if serv_config.has_section(SECTION):
doc = etree.XML(res['arch'])
for option in serv_config.options(SECTION):
for node in doc.xpath("//field[@name='%s']" % option):
node.set('readonly', '1')
modifiers = json.loads(node.get("modifiers"))
modifiers['readonly'] = True
node.set("modifiers", json.dumps(modifiers))
node.set('help', _('This field is managed through server '
'environment'))
res['arch'] = etree.tostring(doc, encoding='unicode')
return res