[IMP] ir.ui.menu more cleanups
- remove deprecated tree_but_open ir.values - remove magic ir_ui_menu delete at loading - remove unused icon and web_icon_hover
This commit is contained in:
@@ -1603,7 +1603,7 @@ class MailThread(models.AbstractModel):
|
||||
user_ids = [self._uid]
|
||||
result = self.message_subscribe(self.env['res.users'].browse(user_ids).mapped('partner_id').ids, subtype_ids=subtype_ids)
|
||||
if user_ids and result:
|
||||
self.pool['ir.ui.menu'].clear_cache()
|
||||
self.pool['ir.ui.menu'].clear_caches()
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@@ -1669,7 +1669,7 @@ class MailThread(models.AbstractModel):
|
||||
partner_ids = [user.partner_id.id for user in self.env['res.users'].browse(user_ids)]
|
||||
result = self.message_unsubscribe(partner_ids)
|
||||
if partner_ids and result:
|
||||
self.pool['ir.ui.menu'].clear_cache()
|
||||
self.pool['ir.ui.menu'].clear_caches()
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -85,7 +85,6 @@
|
||||
|
||||
<record id="menu_website" model="ir.ui.menu">
|
||||
<field name="name">Website</field>
|
||||
<field name="icon">fa-home</field>
|
||||
<field name="sequence" eval="200"/>
|
||||
<field name="web_icon">website,static/description/icon.png</field>
|
||||
<field name="action" ref="action_website"/>
|
||||
|
||||
@@ -22,10 +22,6 @@ class ir_ui_menu(osv.osv):
|
||||
super(ir_ui_menu, self).__init__(*args, **kwargs)
|
||||
self.pool['ir.model.access'].register_cache_clearing_method(self._name, 'clear_caches')
|
||||
|
||||
def clear_cache(self):
|
||||
""" Deprecated, use `clear_caches` instead. """
|
||||
self.clear_caches()
|
||||
|
||||
@api.model
|
||||
@tools.ormcache('frozenset(self.env.user.groups_id.ids)')
|
||||
def _visible_menu_ids(self):
|
||||
@@ -152,7 +148,6 @@ class ir_ui_menu(osv.osv):
|
||||
return result
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
res = super(ir_ui_menu, self).copy(cr, uid, id, default=default, context=context)
|
||||
datas=self.read(cr,uid,[res],['name'])[0]
|
||||
rex=re.compile('\([0-9]+\)')
|
||||
@@ -163,56 +158,8 @@ class ir_ui_menu(osv.osv):
|
||||
else:
|
||||
datas['name'] += '(1)'
|
||||
self.write(cr,uid,[res],{'name':datas['name']})
|
||||
ids = ir_values_obj.search(cr, uid, [
|
||||
('model', '=', 'ir.ui.menu'),
|
||||
('res_id', '=', id),
|
||||
])
|
||||
for iv in ir_values_obj.browse(cr, uid, ids):
|
||||
ir_values_obj.copy(cr, uid, iv.id, default={'res_id': res},
|
||||
context=context)
|
||||
return res
|
||||
|
||||
def _action(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
value_ids = ir_values_obj.search(cursor, user, [
|
||||
('model', '=', self._name), ('key', '=', 'action'),
|
||||
('key2', '=', 'tree_but_open'), ('res_id', 'in', ids)],
|
||||
context=context)
|
||||
values_action = {}
|
||||
for value in ir_values_obj.browse(cursor, user, value_ids, context=context):
|
||||
values_action[value.res_id] = value.value
|
||||
for menu_id in ids:
|
||||
res[menu_id] = values_action.get(menu_id, False)
|
||||
return res
|
||||
|
||||
def _action_inv(self, cursor, user, menu_id, name, value, arg, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
ctx = context.copy()
|
||||
if self.CONCURRENCY_CHECK_FIELD in ctx:
|
||||
del ctx[self.CONCURRENCY_CHECK_FIELD]
|
||||
ir_values_obj = self.pool.get('ir.values')
|
||||
values_ids = ir_values_obj.search(cursor, user, [
|
||||
('model', '=', self._name), ('key', '=', 'action'),
|
||||
('key2', '=', 'tree_but_open'), ('res_id', '=', menu_id)],
|
||||
context=context)
|
||||
if value and values_ids:
|
||||
ir_values_obj.write(cursor, user, values_ids, {'value': value}, context=ctx)
|
||||
elif value:
|
||||
# no values_ids, create binding
|
||||
ir_values_obj.create(cursor, user, {
|
||||
'name': 'Menuitem',
|
||||
'model': self._name,
|
||||
'value': value,
|
||||
'key': 'action',
|
||||
'key2': 'tree_but_open',
|
||||
'res_id': menu_id,
|
||||
}, context=ctx)
|
||||
elif values_ids:
|
||||
# value is False, remove existing binding
|
||||
ir_values_obj.unlink(cursor, user, values_ids, context=ctx)
|
||||
|
||||
def read_image(self, path):
|
||||
if not path:
|
||||
return False
|
||||
@@ -234,7 +181,6 @@ class ir_ui_menu(osv.osv):
|
||||
for fn in names:
|
||||
fn_src = fn[:-5] # remove _data
|
||||
r[fn] = self.read_image(menu[fn_src])
|
||||
|
||||
return res
|
||||
|
||||
def _get_needaction_enabled(self, cr, uid, ids, field_names, args, context=None):
|
||||
@@ -313,7 +259,7 @@ class ir_ui_menu(osv.osv):
|
||||
@api.cr_uid_context
|
||||
@tools.ormcache_context('uid', keys=('lang',))
|
||||
def load_menus_root(self, cr, uid, context=None):
|
||||
fields = ['name', 'sequence', 'parent_id', 'action', 'icon']
|
||||
fields = ['name', 'sequence', 'parent_id', 'action']
|
||||
menu_root_ids = self.get_user_roots(cr, uid, context=context)
|
||||
menu_roots = self.read(cr, uid, menu_root_ids, fields, context=context) if menu_root_ids else []
|
||||
return {
|
||||
@@ -324,7 +270,6 @@ class ir_ui_menu(osv.osv):
|
||||
'all_menu_ids': menu_root_ids,
|
||||
}
|
||||
|
||||
|
||||
@api.cr_uid_context
|
||||
@tools.ormcache_context('uid', keys=('lang',))
|
||||
def load_menus(self, cr, uid, context=None):
|
||||
@@ -333,7 +278,7 @@ class ir_ui_menu(osv.osv):
|
||||
:return: the menu root
|
||||
:rtype: dict('children': menu_nodes)
|
||||
"""
|
||||
fields = ['name', 'sequence', 'parent_id', 'action', 'icon', 'web_icon_data']
|
||||
fields = ['name', 'sequence', 'parent_id', 'action', 'web_icon_data']
|
||||
menu_root_ids = self.get_user_roots(cr, uid, context=context)
|
||||
menu_roots = self.read(cr, uid, menu_root_ids, fields, context=context) if menu_root_ids else []
|
||||
menu_root = {
|
||||
@@ -385,35 +330,26 @@ class ir_ui_menu(osv.osv):
|
||||
'groups_id': fields.many2many('res.groups', 'ir_ui_menu_group_rel',
|
||||
'menu_id', 'gid', 'Groups', help="If you have groups, the visibility of this menu will be based on these groups. "\
|
||||
"If this field is empty, Odoo will compute visibility based on the related object's read access."),
|
||||
'complete_name': fields.function(_get_full_name,
|
||||
string='Full Path', type='char', size=128),
|
||||
'icon': fields.char('Icon', size=64),
|
||||
'complete_name': fields.function(_get_full_name, string='Full Path', type='char'),
|
||||
'web_icon': fields.char('Web Icon File'),
|
||||
'web_icon_hover': fields.char('Web Icon File (hover)'),
|
||||
'web_icon_data': fields.function(_get_image_icon, string='Web Icon Image', type='binary', readonly=True, store=True, multi='icon'),
|
||||
'web_icon_hover_data': fields.function(_get_image_icon, string='Web Icon Image (hover)', type='binary', readonly=True, store=True, multi='icon'),
|
||||
'needaction_enabled': fields.function(_get_needaction_enabled,
|
||||
type='boolean',
|
||||
store=True,
|
||||
string='Target model uses the need action mechanism',
|
||||
help='If the menu entry action is an act_window action, and if this action is related to a model that uses the need_action mechanism, this field is set to true. Otherwise, it is false.'),
|
||||
'action': fields.function(_action, fnct_inv=_action_inv,
|
||||
type='reference', string='Action', size=21,
|
||||
selection=[
|
||||
'action': fields.reference('Action', selection=[
|
||||
('ir.actions.report.xml', 'ir.actions.report.xml'),
|
||||
('ir.actions.act_window', 'ir.actions.act_window'),
|
||||
('ir.actions.wizard', 'ir.actions.wizard'),
|
||||
('ir.actions.act_url', 'ir.actions.act_url'),
|
||||
('ir.actions.server', 'ir.actions.server'),
|
||||
('ir.actions.client', 'ir.actions.client'),
|
||||
]),
|
||||
]),
|
||||
}
|
||||
|
||||
def _rec_message(self, cr, uid, ids, context=None):
|
||||
return _('Error ! You can not create recursive Menu.')
|
||||
|
||||
_constraints = [
|
||||
(osv.osv._check_recursion, _rec_message, ['parent_id'])
|
||||
(osv.osv._check_recursion, 'Error ! You can not create recursive Menu.', ['parent_id'])
|
||||
]
|
||||
_defaults = {
|
||||
'sequence': 10,
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Menu">
|
||||
<sheet>
|
||||
<field name="web_icon_data" widget="image"/>
|
||||
<group>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
@@ -17,7 +16,6 @@
|
||||
<group>
|
||||
<field name="complete_name"/>
|
||||
<field name="action"/>
|
||||
<field name="icon"/>
|
||||
<field name="web_icon"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
@@ -366,27 +366,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
||||
|
||||
cr.commit()
|
||||
|
||||
# STEP 5: Cleanup menus
|
||||
# Remove menu items that are not referenced by any of other
|
||||
# (child) menu item, ir_values, or ir_model_data.
|
||||
# TODO: This code could be a method of ir_ui_menu. Remove menu without actions of children
|
||||
if update_module:
|
||||
while True:
|
||||
cr.execute('''delete from
|
||||
ir_ui_menu
|
||||
where
|
||||
(id not IN (select parent_id from ir_ui_menu where parent_id is not null))
|
||||
and
|
||||
(id not IN (select res_id from ir_values where model='ir.ui.menu'))
|
||||
and
|
||||
(id not IN (select res_id from ir_model_data where model='ir.ui.menu'))''')
|
||||
cr.commit()
|
||||
if not cr.rowcount:
|
||||
break
|
||||
else:
|
||||
_logger.info('removed %d unused menus', cr.rowcount)
|
||||
|
||||
# STEP 6: Uninstall modules to remove
|
||||
# STEP 5: Uninstall modules to remove
|
||||
if update_module:
|
||||
# Remove records referenced from ir_model_data for modules to be
|
||||
# removed (and removed the references from ir_model_data).
|
||||
@@ -408,7 +388,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
||||
openerp.api.Environment.reset()
|
||||
return openerp.modules.registry.RegistryManager.new(cr.dbname, force_demo, status, update_module)
|
||||
|
||||
# STEP 7: verify custom views on every model
|
||||
# STEP 6: verify custom views on every model
|
||||
if update_module:
|
||||
Views = registry['ir.ui.view']
|
||||
custom_view_test = True
|
||||
|
||||
@@ -520,6 +520,7 @@ form: module.record_id""" % (xml_id,)
|
||||
# determine the type of action
|
||||
action_type, action_id = self.model_id_get(cr, a_action)
|
||||
action_type = action_type.split('.')[-1] # keep only type part
|
||||
values['action'] = "ir.actions.%s,%d" % (action_type, action_id)
|
||||
|
||||
if not values.get('name') and action_type in ('act_window', 'wizard', 'url', 'client', 'server'):
|
||||
a_table = 'ir_act_%s' % action_type.replace('act_', '')
|
||||
@@ -548,28 +549,14 @@ form: module.record_id""" % (xml_id,)
|
||||
values['groups_id'] = groups_value
|
||||
|
||||
if not values.get('parent_id'):
|
||||
if rec.get('icon'):
|
||||
values['icon'] = rec.get('icon')
|
||||
else:
|
||||
default_icon = 'fa-cube' # default icon if not specified any for top-level menu
|
||||
try:
|
||||
values['icon'] = self.pool.get('ir.ui.menu').read(cr,self.uid,res,['icon'])[0].get('icon')
|
||||
except:
|
||||
values['icon'] = default_icon
|
||||
|
||||
if rec.get('web_icon'):
|
||||
values['web_icon'] = rec.get('web_icon')
|
||||
if rec.get('web_icon_hover'):
|
||||
values['web_icon_hover'] = rec.get('web_icon_hover')
|
||||
|
||||
pid = self.pool['ir.model.data']._update(cr, self.uid, 'ir.ui.menu', self.module, values, rec_id, noupdate=self.isnoupdate(data_node), mode=self.mode, res_id=res and res[0] or False)
|
||||
|
||||
if rec_id and pid:
|
||||
self.idref[rec_id] = int(pid)
|
||||
|
||||
if rec.get('action') and pid:
|
||||
action = "ir.actions.%s,%d" % (action_type, action_id)
|
||||
self.pool['ir.model.data'].ir_set(cr, self.uid, 'action', 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(pid))], action, True, True, xml_id=rec_id)
|
||||
return 'ir.ui.menu', pid
|
||||
|
||||
def _assert_equals(self, f1, f2, prec=4):
|
||||
|
||||
Reference in New Issue
Block a user