From c4e86d99c33c34dd229763a1b4743927d5501ef5 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 21 Jun 2013 19:01:25 +0200 Subject: [PATCH 1/2] [ADD] view_groups_id --- view_groups_id/__init__.py | 22 +++++++++++++ view_groups_id/__openerp__.py | 53 ++++++++++++++++++++++++++++++ view_groups_id/model/__init__.py | 22 +++++++++++++ view_groups_id/model/ir_ui_view.py | 50 ++++++++++++++++++++++++++++ view_groups_id/view/ir_ui_view.xml | 18 ++++++++++ 5 files changed, 165 insertions(+) create mode 100644 view_groups_id/__init__.py create mode 100644 view_groups_id/__openerp__.py create mode 100644 view_groups_id/model/__init__.py create mode 100644 view_groups_id/model/ir_ui_view.py create mode 100644 view_groups_id/view/ir_ui_view.xml diff --git a/view_groups_id/__init__.py b/view_groups_id/__init__.py new file mode 100644 index 000000000..1483b2269 --- /dev/null +++ b/view_groups_id/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import model diff --git a/view_groups_id/__openerp__.py b/view_groups_id/__openerp__.py new file mode 100644 index 000000000..e83a01076 --- /dev/null +++ b/view_groups_id/__openerp__.py @@ -0,0 +1,53 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'group_ids for ir.ui.view', + 'version': '1.0', + 'description': """This addon is a backport of OpenERP 7.0's groups_id for + views. + + The greatness lies in the fact that with that, you can have specific + inherited views for specific groups, so you can radically change a view + for some groups without having to redefine any of the window actions + involved. + + Using it for 6.1 modules instead of fields_view_get hacks and the like + also lowers the effort it takes to port the module in question to 7.0 + """, + 'author': 'Therp BV', + 'website': 'http://www.therp.nl', + "category": "Dependency", + "depends": [ + 'base', + ], + 'css': [ + ], + 'data': [ + 'view/ir_ui_view.xml', + ], + 'js': [ + ], + 'installable': True, + 'active': False, + 'certificate': '', +} diff --git a/view_groups_id/model/__init__.py b/view_groups_id/model/__init__.py new file mode 100644 index 000000000..c950c9172 --- /dev/null +++ b/view_groups_id/model/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import ir_ui_view diff --git a/view_groups_id/model/ir_ui_view.py b/view_groups_id/model/ir_ui_view.py new file mode 100644 index 000000000..619dc2a82 --- /dev/null +++ b/view_groups_id/model/ir_ui_view.py @@ -0,0 +1,50 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv.orm import Model +from openerp.osv import fields +from openerp import SUPERUSER_ID + + +class ir_ui_view(Model): + _inherit = 'ir.ui.view' + + _columns = { + 'groups_id': fields.many2many( + 'res.groups', 'ir_ui_view_group_rel', 'view_id', 'group_id', + string='Groups', help="If this field is empty, the view " + "applies to all users. Otherwise, the view applies to the " + "users of those groups only."), + } + + def get_inheriting_views_arch(self, cr, uid, view_id, model, context=None): + user_groups = frozenset(self.pool.get('res.users').browse( + cr, SUPERUSER_ID, uid, context).groups_id) + + view_ids = [v[1] for v in + super(ir_ui_view, self).get_inheriting_views_arch( + cr, uid, view_id, model, context=context)] + + # filter views based on user groups + return [(view.arch, view.id) + for view in self.browse(cr, SUPERUSER_ID, view_ids, context) + if not (view.groups_id and + user_groups.isdisjoint(view.groups_id))] diff --git a/view_groups_id/view/ir_ui_view.xml b/view_groups_id/view/ir_ui_view.xml new file mode 100644 index 000000000..b8aa3de9b --- /dev/null +++ b/view_groups_id/view/ir_ui_view.xml @@ -0,0 +1,18 @@ + + + + + ir.ui.view + + + + + + + + + + + + + From dc31a985a7fe2fc2dc728660be6d0d72879640fb Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sat, 22 Jun 2013 10:53:54 +0200 Subject: [PATCH 2/2] [FIX] Attribute OpenERP SA for the backported code --- view_groups_id/__openerp__.py | 2 +- view_groups_id/model/ir_ui_view.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/view_groups_id/__openerp__.py b/view_groups_id/__openerp__.py index e83a01076..0ebec9eca 100644 --- a/view_groups_id/__openerp__.py +++ b/view_groups_id/__openerp__.py @@ -34,7 +34,7 @@ Using it for 6.1 modules instead of fields_view_get hacks and the like also lowers the effort it takes to port the module in question to 7.0 """, - 'author': 'Therp BV', + 'author': ['Therp BV', 'OpenERP SA'], 'website': 'http://www.therp.nl', "category": "Dependency", "depends": [ diff --git a/view_groups_id/model/ir_ui_view.py b/view_groups_id/model/ir_ui_view.py index 619dc2a82..3121c9e6f 100644 --- a/view_groups_id/model/ir_ui_view.py +++ b/view_groups_id/model/ir_ui_view.py @@ -3,6 +3,11 @@ # # OpenERP, Open Source Management Solution # This module copyright (C) 2013 Therp BV () +# +# Code snippets from openobject-server 7.0 +# (C) 2004-2012 OpenERP S.A. () +# +# # All Rights Reserved # # This program is free software: you can redistribute it and/or modify