changeset f79c2d67df48 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=f79c2d67df48
description:
        Define ir module groups on res module

        issue9633
        review291051002
diffstat:

 trytond/ir/action.py    |  25 +---------------------
 trytond/res/__init__.py |   6 +++++
 trytond/res/ir.py       |  52 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 23 deletions(-)

diffs (142 lines):

diff -r 74ee9775bca8 -r f79c2d67df48 trytond/ir/action.py
--- a/trytond/ir/action.py      Thu Oct 08 21:34:15 2020 +0200
+++ b/trytond/ir/action.py      Fri Oct 09 13:06:42 2020 +0200
@@ -57,8 +57,6 @@
     usage = fields.Char('Usage')
     keywords = fields.One2Many('ir.action.keyword', 'action',
             'Keywords')
-    groups = fields.Many2Many('ir.action-res.group', 'action', 'group',
-            'Groups')
     icon = fields.Many2One('ir.ui.icon', 'Icon')
 
     @classmethod
@@ -138,8 +136,6 @@
     model = fields.Reference('Model', selection='models_get')
     action = fields.Many2One('ir.action', 'Action',
         ondelete='CASCADE', select=True)
-    groups = fields.Function(fields.One2Many('res.group', None, 'Groups'),
-        'get_groups', searcher='search_groups')
     _get_keyword_cache = Cache('ir_action_keyword.get_keyword')
 
     @classmethod
@@ -156,13 +152,6 @@
         table = cls.__table_handler__(module_name)
         table.index_action(['keyword', 'model'], 'add')
 
-    def get_groups(self, name):
-        return [g.id for g in self.action.groups]
-
-    @classmethod
-    def search_groups(cls, name, clause):
-        return [('action.' + clause[0],) + tuple(clause[1:])]
-
     @classmethod
     def validate(cls, actions):
         super(ActionKeyword, cls).validate(actions)
@@ -274,7 +263,9 @@
 
     @classmethod
     def __setup__(cls):
+        pool = Pool()
         super(ActionMixin, cls).__setup__()
+        Action = pool.get('ir.action')
         for name in dir(Action):
             field = getattr(Action, name)
             if (isinstance(field, fields.Field)
@@ -409,18 +400,6 @@
         return new_records
 
     @classmethod
-    def get_groups(cls, name, action_id=None):
-        # TODO add cache
-        domain = [
-            (cls._action_name, '=', name),
-            ]
-        if action_id:
-            domain.append(('id', '=', action_id))
-        actions = cls.search(domain)
-        groups = {g.id for a in actions for g in a.groups}
-        return groups
-
-    @classmethod
     def fetch_action(cls, action_id):
         fields = list(cls._fields.keys())
         return cls.search_read(
diff -r 74ee9775bca8 -r f79c2d67df48 trytond/res/__init__.py
--- a/trytond/res/__init__.py   Thu Oct 08 21:34:15 2020 +0200
+++ b/trytond/res/__init__.py   Fri Oct 09 13:06:42 2020 +0200
@@ -22,6 +22,12 @@
         user.UserConfigStart,
         ir.UIMenuGroup,
         ir.ActionGroup,
+        ir.Action,
+        ir.ActionReport,
+        ir.ActionActWindow,
+        ir.ActionWizard,
+        ir.ActionURL,
+        ir.ActionKeyword,
         ir.ModelButtonGroup,
         ir.ModelButtonRule,
         ir.ModelButtonClick,
diff -r 74ee9775bca8 -r f79c2d67df48 trytond/res/ir.py
--- a/trytond/res/ir.py Thu Oct 08 21:34:15 2020 +0200
+++ b/trytond/res/ir.py Fri Oct 09 13:06:42 2020 +0200
@@ -74,6 +74,58 @@
         Pool().get('ir.rule')._domain_get_cache.clear()
 
 
+class Action(metaclass=PoolMeta):
+    __name__ = 'ir.action'
+
+    groups = fields.Many2Many(
+        'ir.action-res.group', 'action', 'group', "Groups")
+
+
+class ActionMixin(metaclass=PoolMeta):
+
+    @classmethod
+    def get_groups(cls, name, action_id=None):
+        # TODO add cache
+        domain = [
+            (cls._action_name, '=', name),
+            ]
+        if action_id:
+            domain.append(('id', '=', action_id))
+        actions = cls.search(domain)
+        groups = {g.id for a in actions for g in a.groups}
+        return groups
+
+
+class ActionReport(ActionMixin):
+    __name__ = 'ir.action.report'
+
+
+class ActionActWindow(ActionMixin):
+    __name__ = 'ir.action.act_window'
+
+
+class ActionWizard(ActionMixin):
+    __name__ = 'ir.action.wizard'
+
+
+class ActionURL(ActionMixin):
+    __name__ = 'ir.action.url'
+
+
+class ActionKeyword(metaclass=PoolMeta):
+    __name__ = 'ir.action.keyword'
+
+    groups = fields.Function(fields.One2Many('res.group', None, 'Groups'),
+        'get_groups', searcher='search_groups')
+
+    def get_groups(self, name):
+        return [g.id for g in self.action.groups]
+
+    @classmethod
+    def search_groups(cls, name, clause):
+        return [('action.' + clause[0],) + tuple(clause[1:])]
+
+
 class ModelButtonGroup(DeactivableMixin, ModelSQL):
     "Model Button - Group"
     __name__ = 'ir.model.button-res.group'

Reply via email to