Browse Source

[MIG] base_technical_features -> 10.0 (#568)

[MIG] base_technical_features -> 10.0

Using new base model inheritance
pull/2/head
Stefan Rijnhart (Opener) 8 years ago
committed by Stefan Rijnhart
parent
commit
d3067b8676
  1. 8
      base_technical_features/README.rst
  2. 4
      base_technical_features/__manifest__.py
  3. 2
      base_technical_features/models/__init__.py
  4. 19
      base_technical_features/models/base.py
  5. 33
      base_technical_features/models/basemodel_monkeypatch.py
  6. 3
      base_technical_features/models/ir_ui_menu.py
  7. 1
      base_technical_features/tests/test_base_technical_features.py

8
base_technical_features/README.rst

@ -6,9 +6,9 @@
Access to technical features without activating debug mode 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 Configuration
============= =============
@ -34,7 +34,7 @@ Usage
.. 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/9.0
:target: https://runbot.odoo-community.org/runbot/149/10.0
Bug Tracker Bug Tracker
=========== ===========

4
base_technical_features/__manifest__.py

@ -4,7 +4,7 @@
{ {
"name": "Technical features group", "name": "Technical features group",
"summary": "Access to technical features without activating debug mode", "summary": "Access to technical features without activating debug mode",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Usability", "category": "Usability",
"website": "https://github.com/oca/server-tools", "website": "https://github.com/oca/server-tools",
"author": "Opener B.V., Odoo Community Association (OCA)", "author": "Opener B.V., Odoo Community Association (OCA)",
@ -14,5 +14,5 @@
'data/res_users.xml', 'data/res_users.xml',
], ],
"license": "AGPL-3", "license": "AGPL-3",
'installable': False,
'installable': True,
} }

2
base_technical_features/models/__init__.py

@ -1,3 +1,3 @@
from . import basemodel_monkeypatch
from . import base
from . import ir_ui_menu from . import ir_ui_menu
from . import res_users from . import res_users

19
base_technical_features/models/base.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 Opener B.V. (<https://opener.am>)
# 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)

33
base_technical_features/models/basemodel_monkeypatch.py

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
# © 2016 Opener B.V. (<https://opener.am>)
# 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)

3
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 """ Set debug = True, so that group_no_one is not filtered out of the
user's groups """ user's groups """
if not debug: 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') 'base_technical_features.group_technical_features')
return super(IrUiMenu, self)._visible_menu_ids(debug=debug) return super(IrUiMenu, self)._visible_menu_ids(debug=debug)

1
base_technical_features/tests/test_base_technical_features.py

@ -32,7 +32,6 @@ class TestBaseTechnicalFeatures(common.TransactionCase):
return xml.xpath( return xml.xpath(
'//div/group/field[@name="partner_id"]')[0].get('invisible') '//div/group/field[@name="partner_id"]')[0].get('invisible')
self.env['basemodel.monkeypatch']._register_hook()
self.env.user.write({'technical_features': False}) self.env.user.write({'technical_features': False})
self.assertEqual(get_partner_field_invisible(), '1') self.assertEqual(get_partner_field_invisible(), '1')
self.env.user.write({'technical_features': True}) self.env.user.write({'technical_features': True})

Loading…
Cancel
Save