From 455ca923d3d92cc9f4befec9817abb9d82e759f8 Mon Sep 17 00:00:00 2001 From: "Stefan Rijnhart (Opener)" Date: Wed, 12 Oct 2016 09:54:06 +0200 Subject: [PATCH] [MIG] base_technical_features -> 10.0 (#568) Using new base model inheritance --- base_technical_features/README.rst | 8 ++--- .../{__openerp__.py => __manifest__.py} | 4 +-- base_technical_features/models/__init__.py | 2 +- base_technical_features/models/base.py | 19 +++++++++++ .../models/basemodel_monkeypatch.py | 33 ------------------- base_technical_features/models/ir_ui_menu.py | 3 +- .../tests/test_base_technical_features.py | 1 - 7 files changed, 27 insertions(+), 43 deletions(-) rename base_technical_features/{__openerp__.py => __manifest__.py} (90%) create mode 100644 base_technical_features/models/base.py delete mode 100644 base_technical_features/models/basemodel_monkeypatch.py diff --git a/base_technical_features/README.rst b/base_technical_features/README.rst index a10fb8e..e5e6a80 100644 --- a/base_technical_features/README.rst +++ b/base_technical_features/README.rst @@ -6,9 +6,9 @@ Access to technical features without activating debug mode ========================================================== -In Odoo 9.0, the debug mode grants every employee user access to the technical -features. This module enables persistent access to technical features based on -user preference. +In Odoo 9.0 and later, the debug mode grants every employee user access to the +technical features. This module enables persistent access to technical features +based on user preference. Configuration ============= @@ -34,7 +34,7 @@ Usage .. 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 Bug Tracker =========== diff --git a/base_technical_features/__openerp__.py b/base_technical_features/__manifest__.py similarity index 90% rename from base_technical_features/__openerp__.py rename to base_technical_features/__manifest__.py index 14383e9..b7f8ea1 100644 --- a/base_technical_features/__openerp__.py +++ b/base_technical_features/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Technical features group", "summary": "Access to technical features without activating debug mode", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "category": "Usability", "website": "https://github.com/oca/server-tools", "author": "Opener B.V., Odoo Community Association (OCA)", @@ -14,5 +14,5 @@ 'data/res_users.xml', ], "license": "AGPL-3", - "installable": True, + 'installable': True, } diff --git a/base_technical_features/models/__init__.py b/base_technical_features/models/__init__.py index b26f7f4..a89e9f3 100644 --- a/base_technical_features/models/__init__.py +++ b/base_technical_features/models/__init__.py @@ -1,3 +1,3 @@ -from . import basemodel_monkeypatch +from . import base from . import ir_ui_menu from . import res_users diff --git a/base_technical_features/models/base.py b/base_technical_features/models/base.py new file mode 100644 index 0000000..01f18c4 --- /dev/null +++ b/base_technical_features/models/base.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 Opener B.V. () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import models + + +class Base(models.AbstractModel): + _inherit = 'base' + + def user_has_groups(self, groups): + """ Return True for users in the technical features group when + membership of the original group is checked, even if debug mode + is not enabled. + """ + if ('base.group_no_one' in groups.split(',') and + self.env.user.has_group( + 'base_technical_features.group_technical_features')): + return True + return super(Base, self).user_has_groups(groups) diff --git a/base_technical_features/models/basemodel_monkeypatch.py b/base_technical_features/models/basemodel_monkeypatch.py deleted file mode 100644 index 0652a12..0000000 --- a/base_technical_features/models/basemodel_monkeypatch.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Opener B.V. () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, api - - -class BaseModelMonkeyPatch(models.AbstractModel): - _name = 'basemodel.monkeypatch' - - def _register_hook(self, cr): - if not hasattr( - models.BaseModel, 'base_technical_features_user_has_groups'): - - models.BaseModel.base_technical_features_user_has_groups = ( - models.BaseModel.user_has_groups) - - @api.cr_uid_context - def user_has_groups(self, cr, uid, groups, context=None): - """ Return True for users in the technical features group when - membership of the original group is checked, even if debug mode - is not enabled. - """ - if ('base.group_no_one' in groups.split(',') and - self.pool['res.users'].has_group( - cr, uid, - 'base_technical_features.group_technical_features')): - return True - return self.base_technical_features_user_has_groups( - cr, uid, groups, context=context) - - models.BaseModel.user_has_groups = user_has_groups - - return super(BaseModelMonkeyPatch, self)._register_hook(cr) diff --git a/base_technical_features/models/ir_ui_menu.py b/base_technical_features/models/ir_ui_menu.py index 112fe39..1192594 100644 --- a/base_technical_features/models/ir_ui_menu.py +++ b/base_technical_features/models/ir_ui_menu.py @@ -12,7 +12,6 @@ class IrUiMenu(models.Model): """ Set debug = True, so that group_no_one is not filtered out of the user's groups """ if not debug: - debug = self.pool['res.users'].has_group( - self.env.cr, self.env.uid, + debug = self.env.user.has_group( 'base_technical_features.group_technical_features') return super(IrUiMenu, self)._visible_menu_ids(debug=debug) diff --git a/base_technical_features/tests/test_base_technical_features.py b/base_technical_features/tests/test_base_technical_features.py index 3e9ac03..9674ec7 100644 --- a/base_technical_features/tests/test_base_technical_features.py +++ b/base_technical_features/tests/test_base_technical_features.py @@ -32,7 +32,6 @@ class TestBaseTechnicalFeatures(common.TransactionCase): return xml.xpath( '//div/group/field[@name="partner_id"]')[0].get('invisible') - self.env['basemodel.monkeypatch']._register_hook() self.env.user.write({'technical_features': False}) self.assertEqual(get_partner_field_invisible(), '1') self.env.user.write({'technical_features': True})