From 44248a07a561508e45e5c951fba169bf1a60093b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 23 Jun 2015 15:30:58 +0200 Subject: [PATCH] [FIX] base,share: error in_group_xx on user form res.users form contains virtual fields in_group_ID to be added in res.groups. Groups with boolean share=True (added by share module) must not be displayed in the form and should not be modifiable through the user interface. However, if a module adding/modifying a res.group is earlier in the dependency graph than 'share' (e.g. only depends from 'base'), the update of the user view is done before share is loaded and the overrride of 'get_application_groups' is never executed. As we can not guarantee that the module is share loaded, put the logic of hidding the module in base instead of share. This workaround is quite hacky but is necessary in stable version. Better fix in 9.0 at cf63d4d Fixes #6324 Fixes #5820 --- addons/share/res_users.py | 9 --------- openerp/addons/base/res/res_users.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/addons/share/res_users.py b/addons/share/res_users.py index 56a3887b52a..662150bc406 100644 --- a/addons/share/res_users.py +++ b/addons/share/res_users.py @@ -64,12 +64,3 @@ class res_groups(osv.osv): if hasattr(parent_class, 'init'): parent_class.init(cr) - def get_application_groups(self, cr, uid, domain=None, context=None): - if domain is None: - domain = [] - domain.append(('share', '=', False)) - return super(res_groups, self).get_application_groups(cr, uid, domain=domain, context=context) - - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index e5c24bb7b19..43e5a34c02b 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -784,6 +784,21 @@ class groups_view(osv.osv): return True def get_application_groups(self, cr, uid, domain=None, context=None): + """ return the list of groups available to an user to generate virtual fields """ + + # TO REMOVE IN 9.0 + # verify if share column is present on the table + # can not be done with override as can not ensure the module share is loaded + # during an upgrade of another module (e.g. if has less dependencies than share) + # use ir.model.fields as _fields may not have been populated yet + got_share = self.pool['ir.model.fields'].search_count(cr, uid, [ + ('name', '=', 'share'), ('model', '=', 'res.groups')], context=context) + if got_share: + if domain is None: + domain = [] + # remove non-shared groups in SQL as 'share' may not be in _fields + cr.execute("SELECT id FROM res_groups WHERE share IS true") + domain.append(('id', 'not in', [gid for (gid,) in cr.fetchall()])) return self.search(cr, uid, domain or []) def get_groups_by_application(self, cr, uid, context=None):