+ _inherit = ['ir.needaction_mixin', 'mail.thread']
+ _mail_compose_message = True
+
+ def _get_default_department_id(self, cr, uid, context=None):
+ """ Gives default department by checking if present in the context """
+ return (self._resolve_department_id_from_context(cr, uid, context=context) or False)
+
+ def _get_default_stage_id(self, cr, uid, context=None):
+ """ Gives default stage_id """
+ department_id = self._get_default_department_id(cr, uid, context=context)
+ return self.stage_find(cr, uid, [], department_id, [('state', '=', 'draft')], context=context)
+
+ def _resolve_department_id_from_context(self, cr, uid, context=None):
+ """ Returns ID of department based on the value of 'default_department_id'
+ context key, or None if it cannot be resolved to a single
+ department.
+ """
+ if context is None:
+ context = {}
+ if type(context.get('default_department_id')) in (int, long):
+ return context.get('default_department_id')
+ if isinstance(context.get('default_department_id'), basestring):
+ department_name = context['default_department_id']
+ department_ids = self.pool.get('hr.department').name_search(cr, uid, name=department_name, context=context)
+ if len(department_ids) == 1:
+ return int(department_ids[0][0])
+ return None
+
+ def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
+ access_rights_uid = access_rights_uid or uid
+ stage_obj = self.pool.get('hr.recruitment.stage')
+ order = stage_obj._order
+ # lame hack to allow reverting search, should just work in the trivial case
+ if read_group_order == 'stage_id desc':
+ order = "%s desc" % order
+ # retrieve section_id from the context and write the domain
+ # - ('id', 'in', 'ids'): add columns that should be present
+ # - OR ('department_id', '=', False), ('fold', '=', False): add default columns that are not folded
+ # - OR ('department_id', 'in', department_id), ('fold', '=', False) if department_id: add department columns that are not folded
+ department_id = self._resolve_department_id_from_context(cr, uid, context=context)
+ search_domain = []
+ if department_id:
+ search_domain += ['|', '&', ('department_id', '=', department_id), ('fold', '=', False)]
+ search_domain += ['|', ('id', 'in', ids), '&', ('department_id', '=', False), ('fold', '=', False)]
+ stage_ids = stage_obj._search(cr, uid, search_domain, order=order, access_rights_uid=access_rights_uid, context=context)
+ result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
+ # restore order of the search
+ result.sort(lambda x,y: cmp(stage_ids.index(x[0]), stage_ids.index(y[0])))
+ return result