[IMP] hr_recruitment: updated methods and defaults related to stage modification. Also udpated yml tests.

bzr revid: tde@openerp.com-20120525115143-0dbj07x8bcz3q075
This commit is contained in:
Thibault Delavallée 2012-05-25 13:51:43 +02:00
parent d90f5ae2ed
commit 51bfe479b3
4 changed files with 99 additions and 51 deletions

View File

@ -92,12 +92,56 @@ class hr_recruitment_degree(osv.osv):
('name_uniq', 'unique (name)', 'The name of the Degree of Recruitment must be unique!')
]
class hr_applicant(crm.crm_case, osv.osv):
class hr_applicant(crm.crm_case, osv.Model):
_name = "hr.applicant"
_description = "Applicant"
_order = "id desc"
_inherit = ['ir.needaction_mixin', 'mail.thread']
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)
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
# get department_id from context
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
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
@param cr: the current row, from the database cursor,
@ -143,7 +187,8 @@ class hr_applicant(crm.crm_case, osv.osv):
'partner_id': fields.many2one('res.partner', 'Partner'),
'create_date': fields.datetime('Creation Date', readonly=True, select=True),
'write_date': fields.datetime('Update Date', readonly=True),
'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage'),
'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage',
domain="['|', ('department_id', '=', department_id), ('department_id', '=', False)]"),
'state': fields.related('stage_id', 'state', type="selection", store=True,
selection=AVAILABLE_STATES, string="State", readonly=True,
help='The state is set to \'Draft\', when a case is created.\
@ -186,28 +231,15 @@ class hr_applicant(crm.crm_case, osv.osv):
_defaults = {
'active': lambda *a: 1,
'user_id': lambda self, cr, uid, context: uid,
'email_from': crm.crm_case. _get_default_email,
'state': 'draft',
'user_id': lambda s, cr, uid, c: uid,
'email_from': lambda s, cr, uid, c: s._get_default_email(cr, uid, c),
'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c),
'department_id': lambda s, cr, uid, c: s._get_default_department_id(cr, uid, c),
'priority': lambda *a: '',
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
'color': 0,
}
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
if read_group_order == 'stage_id desc':
# lame hack to allow reverting search, should just work in the trivial case
order = "%s desc" % order
stage_ids = stage_obj._search(cr, uid, ['|',('id','in',ids),('department_id','=',False)], 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
_group_by_full = {
'stage_id': _read_group_stage_ids
}
@ -229,23 +261,26 @@ class hr_applicant(crm.crm_case, osv.osv):
stage_id = stage_ids and stage_ids[0] or False
return {'value': {'stage_id': stage_id}}
def stage_find(self, cr, uid, section_id, domain=[], order='sequence', context=None):
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
""" Override of the base.stage method
Parameter of the stage search taken from the lead:
- department_id: if set, stages must belong to this section or
be a default case
"""
if isinstance(cases, (int, long)):
cases = self.browse(cr, uid, cases, context=context)
domain = list(domain)
if section_id:
domain += ['|', ('department_id', '=', section_id), ('department_id', '=', False)]
for case in cases:
case_section_id = case.department_id.id if case.department_id else None
if case_section_id:
domain += ['|', ('department_id', '=', case_section_id), ('department_id', '=', False)]
stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, domain, order=order, context=context)
if stage_ids:
return stage_ids[0]
return False
def stage_set_with_state_name(self, cr, uid, cases, state_name, context=None):
""" TODO
"""
for case in cases:
department_id = case.department_id.id if case.department_id else None
stage_id = self.stage_find(cr, uid, department_id, [('state', '=', state_name)], context=context)
if stage_id:
self.stage_set(cr, uid, [case.id], stage_id, context=context)
return True
def stage_previous(self, cr, uid, ids, context=None):
""" This function computes previous stage for case from its current stage
using available stage for that case type
@ -264,11 +299,7 @@ class hr_applicant(crm.crm_case, osv.osv):
def stage_next(self, cr, uid, ids, context=None):
"""This function computes next stage for case from its current stage
using available stage for that case type
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of case IDs
@param context: A standard dictionary for contextual values"""
"""
stage_obj = self.pool.get('hr.recruitment.stage')
for case in self.browse(cr, uid, ids, context=context):
department = (case.department_id.id or False)

View File

@ -1,7 +1,9 @@
<?xml version="1.0"?>
<openerp>
<!--
<data noupdate="1">
-->
<data>
<!-- HR Recruitment Source -->
@ -66,6 +68,7 @@
<field name="name">Refused</field>
<field name="state">cancel</field>
<field name="sequence">6</field>
<field name="fold" eval="True"/>
</record>
<record id="survey_job_0" model="survey">
<field name="title">Job Survey</field>

View File

@ -76,14 +76,24 @@
<field name="arch" type="xml">
<form layout="manual">
<div class="oe_form_topbar">
<button name="%(action_hr_recruitment_hired_employee)d" string="Hire" states="open,pending" type="action"/>
<button name="case_open" string="In Progress" states="draft,pending" type="object"/>
<button name="case_pending" string="Pending" states="open" type="object"/>
<button name="case_reset" string="Reset to New" states="done,cancel" type="object"/>
<button name="case_cancel" string="Refuse" states="draft,open,pending" type="object"/>
<button name="%(action_hr_recruitment_hired_employee)d" string="Hire" type="action"
states="open,pending"/>
<button name="case_open" string="Open" type="object"
states="draft,pending"/>
<button name="case_pending" string="Pending" type="object"
states="open"/>
<button name="case_reset" string="Reset to New" type="object"
states="done,cancel"/>
<button name="case_cancel" string="Refuse" type="object"
states="draft,open,pending"/>
<button name="stage_previous" string="Previous" type="object"
states="open" icon="gtk-go-back"/>
<button name="stage_next" string="Next" type="object"
states="open" icon="gtk-go-forward"/>
<div class="oe_right">
<field name="state" nolabel="1" widget="statusbar" statusbar_visible="draft,open,done" statusbar_colors='{"pending":"blue"}'/>
<field name="stage_id" nolabel="1" widget="statusbar"/>
</div>
<div class="oe_clear"/>
</div>
<sheet string="Jobs - Recruitment Form" layout="auto">
<group colspan="4" col="4">
@ -96,11 +106,7 @@
<field name="user_id"/>
<field name="job_id" on_change="onchange_job(job_id)"/>
<field name="department_id" widget="selection" on_change="onchange_department_id(department_id)"/>
<group colspan="2" col="4">
<field name="stage_id" domain="['|',('department_id','=',department_id),('department_id','=',False)]"/>
<button name="stage_previous" string="" type="object" icon="gtk-go-back"/>
<button icon="gtk-go-forward" string="" name="stage_next" type="object"/>
</group>
<field name="state" groups="base.group_no_one"/>
<field name="date_action"/>
<group colspan="2" col="8">
<field name="title_action"/>

View File

@ -1,7 +1,7 @@
-
In Order to test process of Recruitment,
-
Applicant interested in job position. so He send resume by email.
An applicant is interested in the job position. So he sends a resume by email.
-
!python {model: mail.thread}: |
import addons
@ -9,7 +9,7 @@
request_message = request_file.read()
self.message_process(cr, uid, 'hr.applicant', request_message)
-
After getting the mail, I check details of new applicant.
After getting the mail, I check the details of the new applicant.
-
!python {model: hr.applicant}: |
applicant_ids = self.search(cr, uid, [('email_from','=', 'Mr. Richard Anderson <Richard_Anderson@yahoo.com>')])
@ -20,12 +20,20 @@
assert applicant.state == "draft", "Applicant state should be 'draft'."
assert len(resume_ids), "Resume does not attached."
-
I refuse applicant for the Recruitment.
I refuse the applicant.
-
!python {model: hr.applicant}: |
self.case_close(cr, uid, [ref("hr_case_programmer")])
-
I open applicant for the Recruitment.
I check the details of the refused applicant.
-
!python {model: crm.lead}: |
applicant_ids = self.search(cr, uid, [('email_from','=', 'Mr. Richard Anderson <Richard_Anderson@yahoo.com>')])
applicant = self.browse(cr, uid, applicant_ids[0], context=context)
assert applicant.stage_id.id == ref('hr_recruitment.stage_job6'), "Stage should be 'Refused' and is %s." % (applicant.stage_id.name)
assert applicant.state == 'cancel', "Applicant is not in 'cancel' state."
-
I reset and open the previously refused applicant.
-
!python {model: hr.applicant}: |
self.case_reset(cr, uid, [ref("hr_case_programmer")])