From 9b58d8c18d2c764b4d9c3c3c285d2fb202c2909d Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Mon, 7 Nov 2016 15:46:42 +0100 Subject: [PATCH] Migration of server_environment to 10.0 --- server_environment/README.rst | 8 +- server_environment/__manifest__.py | 5 +- server_environment/serv_config.py | 93 ++++++++++--------- server_environment/serv_config.xml | 28 +++--- server_environment/system_info.py | 6 +- .../tests/test_server_environment.py | 4 +- 6 files changed, 72 insertions(+), 72 deletions(-) diff --git a/server_environment/README.rst b/server_environment/README.rst index 49fe4b5..fdf8816 100644 --- a/server_environment/README.rst +++ b/server_environment/README.rst @@ -68,7 +68,7 @@ To use this module, in your code, you can follow this example:: .. 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/9.0 + :target: https://runbot.odoo-community.org/runbot/149/10.0 Known issues / Roadmap @@ -85,11 +85,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please 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. Credits ======= diff --git a/server_environment/__manifest__.py b/server_environment/__manifest__.py index 9f33298..33cc3a9 100644 --- a/server_environment/__manifest__.py +++ b/server_environment/__manifest__.py @@ -21,7 +21,7 @@ { "name": "server configuration environment files", - "version": "9.0.1.2.0", + "version": "10.0.1.2.0", "depends": ["base", "server_environment_files"], "author": "Camptocamp,Odoo Community Association (OCA)", "summary": "move some configurations out of the database", @@ -31,6 +31,5 @@ "data": [ 'serv_config.xml', ], - 'installable': False, - "active": False, + 'installable': True, } diff --git a/server_environment/serv_config.py b/server_environment/serv_config.py index bb52e9f..ec49f99 100644 --- a/server_environment/serv_config.py +++ b/server_environment/serv_config.py @@ -24,12 +24,12 @@ import ConfigParser from lxml import etree from itertools import chain -from openerp import models, fields -from openerp.tools.config import config as system_base_config +from odoo import api, fields, models +from odoo.tools.config import config as system_base_config from .system_info import get_server_environment -from openerp.addons import server_environment_files +from odoo.addons import server_environment_files _dir = os.path.dirname(server_environment_files.__file__) # Same dict as RawConfigParser._boolean_states @@ -103,6 +103,7 @@ def _load_config(): return config_p + serv_config = _load_config() @@ -120,63 +121,71 @@ class ServerConfiguration(models.TransientModel): _name = 'server.config' _conf_defaults = _Defaults() - def __init__(self, pool, cr): + @classmethod + def _build_model(cls, pool, cr): """Add columns to model dynamically and init some properties """ - self._add_columns() - super(ServerConfiguration, self).__init__(pool, cr) - self.running_env = system_base_config['running_env'] + ModelClass = super(ServerConfiguration, cls)._build_model(pool, cr) + ModelClass._add_columns() + ModelClass.running_env = system_base_config['running_env'] # Only show passwords in development - self.show_passwords = self.running_env in ('dev',) - self._arch = None - self._build_osv() + ModelClass.show_passwords = ModelClass.running_env in ('dev',) + ModelClass._arch = None + ModelClass._build_osv() + return ModelClass - def _format_key(self, section, key): + @classmethod + def _format_key(cls, section, key): return '%s | %s' % (section, key) - def _add_columns(self): + @classmethod + def _add_columns(cls): """Add columns to model dynamically""" cols = chain( - self._get_base_cols().items(), - self._get_env_cols().items(), - self._get_system_cols().items() + cls._get_base_cols().items(), + cls._get_env_cols().items(), + cls._get_system_cols().items() ) for col, value in cols: col_name = col.replace('.', '_') setattr(ServerConfiguration, col_name, fields.Char(string=col, readonly=True)) - self._conf_defaults[col_name] = value + cls._conf_defaults[col_name] = value - def _get_base_cols(self): + @classmethod + def _get_base_cols(cls): """ Compute base fields""" res = {} for col, item in system_base_config.options.items(): - key = self._format_key('openerp', col) + key = cls._format_key('odoo', col) res[key] = item return res - def _get_env_cols(self, sections=None): + @classmethod + def _get_env_cols(cls, sections=None): """ Compute base fields""" res = {} sections = sections if sections else serv_config.sections() for section in sections: for col, item in serv_config.items(section): - key = self._format_key(section, col) + key = cls._format_key(section, col) res[key] = item return res - def _get_system_cols(self): + @classmethod + def _get_system_cols(cls): """ Compute system fields""" res = {} for col, item in get_server_environment(): - key = self._format_key('system', col) + key = cls._format_key('system', col) res[key] = item return res - def _group(self, items): + @classmethod + def _group(cls, items): """Return an XML chunk which represents a group of fields.""" names = [] @@ -187,55 +196,55 @@ class ServerConfiguration(models.TransientModel): _escape(name) for name in names]) + '') - def _build_osv(self): + @classmethod + def _build_osv(cls): """Build the view for the current configuration.""" arch = ('' '
' '') - # OpenERP server configuration + # Odoo server configuration rcfile = system_base_config.rcfile - items = self._get_base_cols() - arch += '' + items = cls._get_base_cols() + arch += '' arch += '' % _escape(rcfile) - arch += self._group(items) + arch += cls._group(items) arch += '' arch += '' for section in sorted(serv_config.sections()): - items = self._get_env_cols(sections=[section]) + items = cls._get_env_cols(sections=[section]) arch += '' % _escape(section) - arch += self._group(items) + arch += cls._group(items) arch += '' # System information arch += '' arch += '' - arch += self._group(self._get_system_cols()) + arch += cls._group(cls._get_system_cols()) arch += '' arch += '
' - self._arch = etree.fromstring(arch) + cls._arch = etree.fromstring(arch) - def fields_view_get(self, cr, uid, view_id=None, view_type='form', - context=None, toolbar=False, submenu=False): + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, + submenu=False): """Overwrite the default method to render the custom view.""" - res = super(ServerConfiguration, self).fields_view_get(cr, uid, - view_id, + res = super(ServerConfiguration, self).fields_view_get(view_id, view_type, - context, toolbar) + View = self.env['ir.ui.view'] if view_type == 'form': arch_node = self._arch - xarch, xfields = self._view_look_dom_arch(cr, uid, - arch_node, - view_id, - context=context) + xarch, xfields = View.postprocess_and_fields( + self._name, arch_node, view_id) res['arch'] = xarch res['fields'] = xfields return res - def default_get(self, cr, uid, fields_list, context=None): + @api.model + def default_get(self, fields_list): res = {} for key in self._conf_defaults: if 'passw' in key and not self.show_passwords: diff --git a/server_environment/serv_config.xml b/server_environment/serv_config.xml index ac9f91f..6109ef5 100644 --- a/server_environment/serv_config.xml +++ b/server_environment/serv_config.xml @@ -1,19 +1,15 @@ - - + + - + - - - - + diff --git a/server_environment/system_info.py b/server_environment/system_info.py index ecac728..42362fb 100644 --- a/server_environment/system_info.py +++ b/server_environment/system_info.py @@ -24,8 +24,8 @@ import os import platform import subprocess -from openerp import release -from openerp.tools.config import config +from odoo import release +from odoo.tools.config import config def _get_output(cmd): @@ -61,6 +61,6 @@ def get_server_environment(): ('architecture', platform.architecture()[0]), ('locale', os_lang), ('python', platform.python_version()), - ('openerp', release.version), + ('odoo', release.version), ('revision', rev_id), ) diff --git a/server_environment/tests/test_server_environment.py b/server_environment/tests/test_server_environment.py index a80d9f7..52eec34 100644 --- a/server_environment/tests/test_server_environment.py +++ b/server_environment/tests/test_server_environment.py @@ -18,8 +18,8 @@ # along with this program. If not, see . # ############################################################################## -from openerp.tests import common -from openerp.addons.server_environment import serv_config +from odoo.tests import common +from odoo.addons.server_environment import serv_config class TestEnv(common.TransactionCase):