diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 06da17149d3..36f81d49844 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -69,11 +69,7 @@ class hr_recruitment_stage(osv.osv): 'name': fields.char('Name', size=64, required=True, translate=True), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of stages."), 'department_id':fields.many2one('hr.department', 'Specific to a Department', help="Stages of the recruitment process may be different per department. If this stage is common to all departments, keep tempy this field."), - 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, - help='The state is set to \'Draft\', when a case is created.\ - \nIf the case is in progress the state is set to \'Open\'.\ - \nWhen the case is over, the state is set to \'Done\'.\ - \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), + 'state': fields.selection(AVAILABLE_STATES, 'State', required=True, help="This state is related to this stage"), 'requirements': fields.text('Requirements') } _defaults = { @@ -137,6 +133,31 @@ class hr_applicant(crm.crm_case, osv.osv): duration = float(ans.days) res[issue.id][field] = abs(float(duration)) return res + + def _get_state(self, cr, uid, ids, name, arg, context=None): + res = {} + for applicant in self.browse(cr, uid, ids, context=context): + if applicant.stage_id: + res[applicant.id] = applicant.stage_id.state + return res + + def _get_stage(self, cr, uid, ids, context=None): + applicant_obj = self.pool.get('hr.applicant') + result = {} + for stage in self.browse(cr, uid, ids, context=context): + if stage.state: + applicant_ids = applicant_obj.search(cr, uid, [('state', '=', stage.state)], context=context) + for applicant in applicant_obj.browse(cr, uid, applicant_ids, context=context): + result[applicant.id] = True + return result.keys() + + def _save_state(self, cr, uid, applicant_id, field_name, field_value, arg, context=None): + stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, [('state', '=', field_value)], order='sequence', context=context) + if stage_ids: + return self.write(cr, uid, [applicant_id], {'stage_id': stage_ids[0]}, context=context) + else: + return cr.execute("""UPDATE hr_applicant SET state=%s WHERE id=%s""", (field_value, hr_applicant_id)) + _columns = { 'name': fields.char('Name', size=128, required=True), @@ -150,7 +171,14 @@ class hr_applicant(crm.crm_case, osv.osv): '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'), - 'state': fields.related('stage_id','state', type='char', selection=AVAILABLE_STATES, string="State", store=True, readonly=True), + 'state': fields.function(_get_state, fnct_inv=_save_state, type='selection', selection=AVAILABLE_STATES, string="State", readonly=True, + store = { + 'hr.applicant': (lambda self, cr, uid, ids, c={}: ids, ['stage_id'], 10), + 'hr.recruitment.stage': (_get_stage, ['state'], 10) + }, help='The state is set to \'Draft\', when a case is created.\ + \nIf the case is in progress the state is set to \'Open\'.\ + \nWhen the case is over, the state is set to \'Done\'.\ + \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), 'company_id': fields.many2one('res.company', 'Company'), 'user_id': fields.many2one('res.users', 'Responsible'), # Applicant Columns @@ -188,7 +216,7 @@ class hr_applicant(crm.crm_case, osv.osv): 'active': lambda *a: 1, 'user_id': lambda self, cr, uid, context: uid, 'email_from': crm.crm_case. _get_default_email, - 'state': lambda *a: 'draft', + 'state': 'draft', '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, diff --git a/addons/hr_recruitment/hr_recruitment_data.xml b/addons/hr_recruitment/hr_recruitment_data.xml index d6cb5952d38..ec46530d2a1 100644 --- a/addons/hr_recruitment/hr_recruitment_data.xml +++ b/addons/hr_recruitment/hr_recruitment_data.xml @@ -37,29 +37,34 @@ Doctoral Degree 4 - Initial Qualification + draft 1 First Interview + open 2 Second Interview + open 3 Contract Proposed + pending 4 Contract Signed + done 5 Refused + cancel 6 diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 5474cb11194..6a029482af9 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -62,8 +62,8 @@ -