diff --git a/base_user_role/README.rst b/base_user_role/README.rst index 4b38fab53..b48ec0f80 100644 --- a/base_user_role/README.rst +++ b/base_user_role/README.rst @@ -65,6 +65,7 @@ Contributors ------------ * Sébastien Alix +* Stefan Rijnhart Maintainer ---------- diff --git a/base_user_role/__init__.py b/base_user_role/__init__.py index cde864bae..787fdfd00 100644 --- a/base_user_role/__init__.py +++ b/base_user_role/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import models +from .hooks import post_init_hook diff --git a/base_user_role/__openerp__.py b/base_user_role/__openerp__.py index 59c525fc8..1482f0b53 100644 --- a/base_user_role/__openerp__.py +++ b/base_user_role/__openerp__.py @@ -4,7 +4,7 @@ { 'name': 'User roles', - 'version': '8.0.1.1.0', + 'version': '8.0.1.2.0', 'category': 'Tools', 'author': 'ABF OSIELL, Odoo Community Association (OCA)', 'license': 'AGPL-3', @@ -21,4 +21,5 @@ ], 'installable': True, 'auto_install': False, + 'post_init_hook': 'post_init_hook', } diff --git a/base_user_role/hooks.py b/base_user_role/hooks.py new file mode 100644 index 000000000..cb68cc424 --- /dev/null +++ b/base_user_role/hooks.py @@ -0,0 +1,8 @@ +# coding: utf-8 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import api, SUPERUSER_ID + + +def post_init_hook(cr, pool): + env = api.Environment(cr, SUPERUSER_ID, {}) + env['res.groups'].update_user_groups_view() diff --git a/base_user_role/migrations/8.0.1.2.0/post-migrate.py b/base_user_role/migrations/8.0.1.2.0/post-migrate.py new file mode 100644 index 000000000..91ab1aa29 --- /dev/null +++ b/base_user_role/migrations/8.0.1.2.0/post-migrate.py @@ -0,0 +1,10 @@ +# coding: utf-8 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import api, SUPERUSER_ID + + +def migrate(cr, version): + if not version: + return + env = api.Environment(cr, SUPERUSER_ID, {}) + env['res.groups'].update_user_groups_view() diff --git a/base_user_role/models/__init__.py b/base_user_role/models/__init__.py index db691145c..831ee8e89 100644 --- a/base_user_role/models/__init__.py +++ b/base_user_role/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from . import res_groups from . import role from . import user diff --git a/base_user_role/models/res_groups.py b/base_user_role/models/res_groups.py new file mode 100644 index 000000000..513061df5 --- /dev/null +++ b/base_user_role/models/res_groups.py @@ -0,0 +1,26 @@ +# coding: utf-8 +# Copyright 2014 ABF OSIELL +# Copyright 2017 Opener B.V. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from lxml import etree + +from openerp import api, models + + +class ResGroups(models.Model): + _inherit = 'res.groups' + + @api.model + def update_user_groups_view(self): + """ Make group selection and checkboxes appear readonly when there + are roles on the user """ + res = super(ResGroups, self).update_user_groups_view() + view = self.env.ref('base.user_groups_view') + xml = etree.fromstring(view.arch.encode('utf-8')) + for field in xml.findall('field'): + field.attrib['attrs'] = ( + "{'readonly': [('role_line_ids', '!=', [])]}") + xml_content = etree.tostring( + xml, pretty_print=True, xml_declaration=True, encoding="utf-8") + view.write({'arch': xml_content}) + return res