[IMP] Updated code (see odo/vmt review). Also removed record_ids storage in menus, to avoid passing too much data to the client.

bzr revid: tde@openerp.com-20120418090735-e5ewk3wcf7bp0bvu
This commit is contained in:
Thibault Delavallée 2012-04-18 11:07:35 +02:00
parent 94210b26a2
commit c1a4f1f8db
3 changed files with 17 additions and 16 deletions

View File

@ -51,7 +51,7 @@ class ir_needaction_users_rel(osv.osv):
def _get_users(self, cr, uid, res_ids, res_model, context=None):
"""Given res_ids of res_model, get user_ids present in table"""
rel_ids = self.search(cr, uid, [('res_model', '=', res_model), ('res_id', 'in', res_ids)], context=context)
return map(itemgetter('res_id'), self.read(cr, uid, rel_ids, context=context))
return list(set(map(itemgetter('user_id'), self.read(cr, uid, rel_ids, ['user_id'], context=context))))
def create_users(self, cr, uid, res_ids, res_model, user_ids, context=None):
"""Given res_ids of res_model, add user_ids to the relationship table"""
@ -69,7 +69,7 @@ class ir_needaction_users_rel(osv.osv):
"""Given res_ids of res_model, update their entries in the relationship table to user_ids"""
# read current records
cur_users = self._get_users(cr, uid, res_ids, res_model, context=context)
if len(cur_users) == len(user_ids) and all([cur_user in user_ids for cur_user in cur_users]):
if len(cur_users) == len(user_ids) and all(cur_user in user_ids for cur_user in cur_users):
return True
# unlink old records
self.unlink_users(cr, uid, res_ids, res_model, context=context)
@ -157,10 +157,11 @@ class ir_needaction_mixin(osv.osv):
def needaction_get_record_ids(self, cr, uid, user_id, limit=80, context=None):
"""Given the current model and a user_id
get the number of actions it has to perform"""
return the record ids that require the user to perform an
action"""
rel_obj = self.pool.get('ir.needaction_users')
needact_table_ids = rel_obj.search(cr, uid, [('res_model', '=', self._name), ('user_id', '=', user_id)], limit=limit, context=context)
return map(itemgetter('res_id'), rel_obj.read(cr, uid, needact_table_ids, context=context))
rel_ids = rel_obj.search(cr, uid, [('res_model', '=', self._name), ('user_id', '=', user_id)], limit=limit, context=context)
return map(itemgetter('res_id'), rel_obj.read(cr, uid, rel_ids, ['res_id'], context=context))
def needaction_get_action_count(self, cr, uid, user_id, limit=80, context=None):
"""Given the current model and a user_id
@ -174,7 +175,7 @@ class ir_needaction_mixin(osv.osv):
tuples (model_name, record_id).
This method is trans-model."""
rel_obj = self.pool.get('ir.needaction_users')
needact_table_ids = rel_obj.search(cr, uid, [('user_id', '=', user_id)], offset=offset, limit=limit, order=order, context=context)
return map(itemgetter('res_model', 'id'), rel_obj.read(cr, uid, needact_table_ids, context=context))
rel_ids = rel_obj.search(cr, uid, [('user_id', '=', user_id)], offset=offset, limit=limit, order=order, context=context)
return map(itemgetter('res_model', 'res_id'), rel_obj.read(cr, uid, rel_ids, ['res_model', 'res_id'], context=context))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -258,19 +258,17 @@ class ir_ui_menu(osv.osv):
def _get_needaction(self, cr, uid, ids, field_names, args, context=None):
if context is None:
context = {}
res = dict.fromkeys(ids)
res = {}
for menu in self.browse(cr, uid, ids, context=context):
res[menu.id] = {}
if menu.action and menu.action.type == 'ir.actions.act_window' and menu.action.res_model:
menu_needaction_res = self.pool.get(menu.action.res_model).get_needaction_info(cr, uid, uid, domain=menu.action.domain, context=context)
menu_needaction_res = self.pool.get(menu.action.res_model)._get_needaction_info(cr, uid, uid, domain=menu.action.domain, context=context)
# TODO: find the addon that causes a bug on runbot, not on local
if not isinstance(menu_needaction_res[1], (int, long)): menu_needaction_res[1] = 0
else:
menu_needaction_res = [False, 0, ()]
menu_needaction_res = [False, 0]
res[menu.id]['needaction_enabled'] = menu_needaction_res[0]
res[menu.id]['needaction_counter'] = menu_needaction_res[1]
# not used currently, therefore set to a void list
res[menu.id]['needaction_record_ids'] = []
return res
_columns = {

View File

@ -4866,7 +4866,7 @@ class BaseModel(object):
get_xml_id = get_external_id
_get_xml_ids = _get_external_ids
def get_needaction_info(self, cr, uid, user_id, limit=None, order=None, domain=False, context=None):
def _get_needaction_info(self, cr, uid, user_id, limit=None, order=None, domain=False, context=None):
"""Base method for needaction mechanism
- see ir.needaction for actual implementation
- if the model uses the need action mechanism
@ -4883,16 +4883,18 @@ class BaseModel(object):
:return: [uses_needaction=True/False, needaction_uid_ctr=%d]
"""
if hasattr(self, 'needaction_get_record_ids'):
# Arbitrary limit, but still much lower thant infinity, to avoid
# getting too much data.
ids = self.needaction_get_record_ids(cr, uid, user_id, limit=8192, context=context)
if not ids:
return [True, 0, []]
return [True, 0]
if domain:
new_domain = eval(domain, locals_dict={'uid': user_id}) + [('id', 'in', ids)]
else:
new_domain = [('id', 'in', ids)]
return [True, self.search(cr, uid, new_domain, limit=limit, order=order, count=True, context=context), ids]
return [True, self.search(cr, uid, new_domain, limit=limit, order=order, count=True, context=context)]
else:
return [False, 0, []]
return [False, 0]
# Transience
def is_transient(self):