kernel, base: fix update of groups in menuitem
- only add groups and don't remove previous - add "-" to remove a specific group bzr revid: ced-4f80132bae401eb18f3b828178f54b53220f3fc4
This commit is contained in:
parent
7ebb0508bc
commit
10eed82dff
|
@ -64,6 +64,7 @@
|
|||
<field name="users" colspan="4"/>
|
||||
</page>
|
||||
<page string="Security">
|
||||
<field name="menu_access" colspan="4"/>
|
||||
<field name="model_access" colspan="4">
|
||||
<form string="Access Controls">
|
||||
<field name="name" select="1" colspan="4"/>
|
||||
|
|
|
@ -65,6 +65,20 @@ icons = map(lambda x: (x,x), ['STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_
|
|||
'terp-administration', 'terp-hr', 'terp-partner', 'terp-project', 'terp-report', 'terp-stock'
|
||||
])
|
||||
|
||||
class many2many_unique(fields.many2many):
|
||||
def set(self, cr, obj, id, name, values, user=None, context=None):
|
||||
if not values:
|
||||
return
|
||||
val = values[:]
|
||||
for act in values:
|
||||
if act[0]==4:
|
||||
cr.execute('SELECT * FROM '+self._rel+' \
|
||||
WHERE '+self._id1+'=%d AND '+self._id2+'=%d', (id, act[1]))
|
||||
if cr.fetchall():
|
||||
val.remove(act)
|
||||
return super(many2many_unique, self).set(cr, obj, id, name, val, user=user,
|
||||
context=context)
|
||||
|
||||
|
||||
class ir_ui_menu(osv.osv):
|
||||
_name = 'ir.ui.menu'
|
||||
|
@ -109,7 +123,7 @@ class ir_ui_menu(osv.osv):
|
|||
'sequence': fields.integer('Sequence'),
|
||||
'child_id' : fields.one2many('ir.ui.menu', 'parent_id','Child ids'),
|
||||
'parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', select=True),
|
||||
'groups_id': fields.many2many('res.groups', 'ir_ui_menu_group_rel', 'menu_id', 'gid', 'Groups'),
|
||||
'groups_id': many2many_unique('res.groups', 'ir_ui_menu_group_rel', 'menu_id', 'gid', 'Groups'),
|
||||
'complete_name': fields.function(_get_full_name, method=True, string='Complete Name', type='char', size=128),
|
||||
'icon': fields.selection(lambda *a: icons, 'Icon', size=64)
|
||||
}
|
||||
|
|
|
@ -34,13 +34,31 @@ class groups(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Group Name', size=64, required=True),
|
||||
'model_access': fields.one2many('ir.model.access', 'group_id', 'Access Controls'),
|
||||
'rule_groups': fields.many2many('ir.rule.group', 'group_rule_group_rel', 'group_id', 'rule_group_id', 'Rules', domain="[('global', '<>', True)]"),
|
||||
'rule_groups': fields.many2many('ir.rule.group', 'group_rule_group_rel',
|
||||
'group_id', 'rule_group_id', 'Rules', domain="[('global', '<>', True)]"),
|
||||
'menu_access': fields.many2many('ir.ui.menu', 'ir_ui_menu_group_rel', 'gid', 'menu_id', 'Access Menu'),
|
||||
}
|
||||
def write(self, cr, uid, *args, **argv):
|
||||
res = super(groups, self).write(cr, uid, *args, **argv)
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'unique (name)', 'The name of the group must be unique !')
|
||||
]
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if 'name' in vals:
|
||||
if vals['name'].startswith('-'):
|
||||
raise osv.except_osv('Error',
|
||||
'The name of the group can not start with "-"')
|
||||
res = super(groups, self).write(cr, uid, ids, vals, context=context)
|
||||
# Restart the cache on the company_get method
|
||||
self.pool.get('ir.rule').domain_get()
|
||||
return res
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if 'name' in vals:
|
||||
if vals['name'].startswith('-'):
|
||||
raise osv.except_osv('Error',
|
||||
'The name of the group can not start with "-"')
|
||||
return super(groups, self).create(cr, uid, vals, context=context)
|
||||
|
||||
groups()
|
||||
|
||||
|
||||
|
|
|
@ -291,10 +291,18 @@ class xml_import(object):
|
|||
values['icon'] = str(rec.getAttribute('icon'))
|
||||
if rec.hasAttribute('groups'):
|
||||
g_names = rec.getAttribute('groups').split(',')
|
||||
g_ids = []
|
||||
groups_value = []
|
||||
groups_obj = self.pool.get('res.groups')
|
||||
for group in g_names:
|
||||
g_ids.extend(self.pool.get('res.groups').search(cr, self.uid, [('name', '=', group)]))
|
||||
values['groups_id'] = [(6, 0, g_ids)]
|
||||
if group.startswith('-'):
|
||||
id = groups_obj.search(cr, self.uid,
|
||||
[('name', '=', group[1:])])[0]
|
||||
groups_value.append((3, id))
|
||||
else:
|
||||
id = groups_obj.search(cr, self.uid,
|
||||
[('name', '=', group)])[0]
|
||||
groups_value.append((4, id))
|
||||
values['groups_id'] = groups_value
|
||||
xml_id = rec.getAttribute('id').encode('utf8')
|
||||
self._test_xml_id(xml_id)
|
||||
pid = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.ui.menu', self.module, values, xml_id, idx==len(m_l)-1, mode=self.mode, res_id=res and res[0] or False)
|
||||
|
|
Loading…
Reference in New Issue