Define ir module groups on res module
issue9633 review291051002
This commit is contained in:
1 parent
7f6b94610b
commit
2c461be0a0
3 files changed
+60
-23
No files matched your search
+2
-23
@@ -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())
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user