diff --git a/trytond/ir/action.py b/trytond/ir/action.py index d708d08e72..ec8d3c375f 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -57,8 +57,6 @@ class Action(DeactivableMixin, ModelSQL, ModelView): 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 @@ class ActionKeyword(ModelSQL, ModelView): 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 @@ class ActionKeyword(ModelSQL, ModelView): 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 @@ class ActionMixin(ModelSQL): @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) @@ -408,18 +399,6 @@ class ActionMixin(ModelSQL): default=default)) 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()) diff --git a/trytond/res/__init__.py b/trytond/res/__init__.py index cb4fd486aa..bdaaf40352 100644 --- a/trytond/res/__init__.py +++ b/trytond/res/__init__.py @@ -22,6 +22,12 @@ def register(): 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 --git a/trytond/res/ir.py b/trytond/res/ir.py index 1ac53279b0..93afe9fad0 100644 --- a/trytond/res/ir.py +++ b/trytond/res/ir.py @@ -74,6 +74,58 @@ class ActionGroup(ModelSQL): 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'