changeset 4625f79747ab in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=4625f79747ab
description:
        Clear cache when the links between user and group are modified

        The caches does not depend on the Group records but on the link with 
the User.

        issue9964
        review319051002
diffstat:

 trytond/res/group.py |  47 -----------------------------------------------
 trytond/res/user.py  |  46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 47 deletions(-)

diffs (117 lines):

diff -r 378de0f36b8e -r 4625f79747ab trytond/res/group.py
--- a/trytond/res/group.py      Mon Jan 11 00:04:35 2021 +0100
+++ b/trytond/res/group.py      Mon Jan 11 00:06:13 2021 +0100
@@ -2,7 +2,6 @@
 # this repository contains the full copyright notices and license terms.
 from itertools import chain
 from trytond.model import ModelView, ModelSQL, DeactivableMixin, fields, Unique
-from trytond.pool import Pool
 from trytond.tools import grouped_slice
 
 
@@ -68,49 +67,3 @@
             default['name'] = name
             new_groups.extend(super(Group, cls).copy([group], default=default))
         return new_groups
-
-    @classmethod
-    def create(cls, vlist):
-        res = super(Group, cls).create(vlist)
-        pool = Pool()
-        # Restart the cache on the domain_get method
-        pool.get('ir.rule')._domain_get_cache.clear()
-        # Restart the cache for get_groups
-        pool.get('res.user')._get_groups_cache.clear()
-        # Restart the cache for get_preferences
-        pool.get('res.user')._get_preferences_cache.clear()
-        # Restart the cache for model access and view
-        pool.get('ir.model.access')._get_access_cache.clear()
-        pool.get('ir.model.field.access')._get_access_cache.clear()
-        ModelView._fields_view_get_cache.clear()
-        return res
-
-    @classmethod
-    def write(cls, groups, values, *args):
-        super(Group, cls).write(groups, values, *args)
-        pool = Pool()
-        # Restart the cache on the domain_get method
-        pool.get('ir.rule')._domain_get_cache.clear()
-        # Restart the cache for get_groups
-        pool.get('res.user')._get_groups_cache.clear()
-        # Restart the cache for get_preferences
-        pool.get('res.user')._get_preferences_cache.clear()
-        # Restart the cache for model access and view
-        pool.get('ir.model.access')._get_access_cache.clear()
-        pool.get('ir.model.field.access')._get_access_cache.clear()
-        ModelView._fields_view_get_cache.clear()
-
-    @classmethod
-    def delete(cls, groups):
-        super(Group, cls).delete(groups)
-        pool = Pool()
-        # Restart the cache on the domain_get method
-        pool.get('ir.rule')._domain_get_cache.clear()
-        # Restart the cache for get_groups
-        pool.get('res.user')._get_groups_cache.clear()
-        # Restart the cache for get_preferences
-        pool.get('res.user')._get_preferences_cache.clear()
-        # Restart the cache for model access and view
-        pool.get('ir.model.access')._get_access_cache.clear()
-        pool.get('ir.model.field.access')._get_access_cache.clear()
-        ModelView._fields_view_get_cache.clear()
diff -r 378de0f36b8e -r 4625f79747ab trytond/res/user.py
--- a/trytond/res/user.py       Mon Jan 11 00:04:35 2021 +0100
+++ b/trytond/res/user.py       Mon Jan 11 00:06:13 2021 +0100
@@ -853,6 +853,52 @@
     group = fields.Many2One('res.group', 'Group', ondelete='CASCADE',
             select=True, required=True)
 
+    @classmethod
+    def create(cls, vlist):
+        records = super().create(vlist)
+        pool = Pool()
+        # Restart the cache on the domain_get method
+        pool.get('ir.rule')._domain_get_cache.clear()
+        # Restart the cache for get_groups
+        pool.get('res.user')._get_groups_cache.clear()
+        # Restart the cache for get_preferences
+        pool.get('res.user')._get_preferences_cache.clear()
+        # Restart the cache for model access and view
+        pool.get('ir.model.access')._get_access_cache.clear()
+        pool.get('ir.model.field.access')._get_access_cache.clear()
+        ModelView._fields_view_get_cache.clear()
+        return records
+
+    @classmethod
+    def write(cls, groups, values, *args):
+        super().write(groups, values, *args)
+        pool = Pool()
+        # Restart the cache on the domain_get method
+        pool.get('ir.rule')._domain_get_cache.clear()
+        # Restart the cache for get_groups
+        pool.get('res.user')._get_groups_cache.clear()
+        # Restart the cache for get_preferences
+        pool.get('res.user')._get_preferences_cache.clear()
+        # Restart the cache for model access and view
+        pool.get('ir.model.access')._get_access_cache.clear()
+        pool.get('ir.model.field.access')._get_access_cache.clear()
+        ModelView._fields_view_get_cache.clear()
+
+    @classmethod
+    def delete(cls, groups):
+        super().delete(groups)
+        pool = Pool()
+        # Restart the cache on the domain_get method
+        pool.get('ir.rule')._domain_get_cache.clear()
+        # Restart the cache for get_groups
+        pool.get('res.user')._get_groups_cache.clear()
+        # Restart the cache for get_preferences
+        pool.get('res.user')._get_preferences_cache.clear()
+        # Restart the cache for model access and view
+        pool.get('ir.model.access')._get_access_cache.clear()
+        pool.get('ir.model.field.access')._get_access_cache.clear()
+        ModelView._fields_view_get_cache.clear()
+
 
 class Warning_(ModelSQL, ModelView):
     'User Warning'

Reply via email to