'stage_id': _read_group_stage_ids
}
+ def default_get(self, cr, uid, fields, context=None):
+ if context is None:
+ context = {}
+ res = super(hr_applicant, self).default_get(cr, uid, fields, context=context)
+ if context.get('active_id'):
+ job = self.pool.get('hr.job').browse(cr, uid, context.get('active_id'), context=context)
+ res.update({'user_id': job.user_id.id})
+ return res
+
def onchange_job(self, cr, uid, ids, job_id=False, context=None):
+ department_id = False
if job_id:
job_record = self.pool.get('hr.job').browse(cr, uid, job_id, context=context)
- if job_record and job_record.department_id:
- return {'value': {'department_id': job_record.department_id.id}}
- return {}
+ department_id = job_record and job_record.department_id and job_record.department_id.id or False
+ return {'value': {'department_id': department_id}}
def onchange_department_id(self, cr, uid, ids, department_id=False, stage_id=False, context=None):
if not stage_id:
for applicant in self.browse(cr, uid, ids, context=None):
vals['last_stage_id'] = applicant.stage_id.id
res = super(hr_applicant, self).write(cr, uid, [applicant.id], vals, context=context)
- return res
+ else:
+ res = super(hr_applicant, self).write(cr, uid, ids, vals, context=context)
+
+ if vals.get('job_id'):
+ for applicant in self.browse(cr, uid, ids, context=None):
+ name = applicant.partner_name if applicant.partner_name != False else applicant.name
+ self.pool['hr.job'].message_post(cr, uid, [vals['job_id']], body=_('New Applicant %s Created') % name, subtype="hr_recruitment.mt_applicant_new", context=context)
- return super(hr_applicant, self).write(cr, uid, ids, vals, context=context)
+ # post processing: if stage changed, post a message in the chatter
+ if vals.get('stage_id'):
+ stage = self.pool['hr.recruitment.stage'].browse(cr, uid, vals['stage_id'], context=context)
+ if stage.template_id:
+ # TDENOTE: probably factorize me in a message_post_with_template generic method FIXME
+ compose_ctx = dict(context,
+ active_ids=ids)
+ compose_id = self.pool['mail.compose.message'].create(
+ cr, uid, {
+ 'model': self._name,
+ 'composition_mode': 'mass_mail',
+ 'template_id': stage.template_id.id,
+ 'same_thread': True,
+ 'post': True,
+ 'notify': True,
+ }, context=compose_ctx)
+ self.pool['mail.compose.message'].write(
+ cr, uid, [compose_id],
+ self.pool['mail.compose.message'].onchange_template_id(
+ cr, uid, [compose_id],
+ stage.template_id.id, 'mass_mail', self._name, False,
+ context=compose_ctx)['value'],
+ context=compose_ctx)
+ self.pool['mail.compose.message'].send_mail(cr, uid, [compose_id], context=compose_ctx)
+ return res
def create_employee_from_applicant(self, cr, uid, ids, context=None):
""" Create an hr.employee from the hr.applicants """
address_id = self.pool.get('res.partner').address_get(cr, uid, [applicant.partner_id.id], ['contact'])['contact']
contact_name = self.pool.get('res.partner').name_get(cr, uid, [applicant.partner_id.id])[0][1]
if applicant.job_id and (applicant.partner_name or contact_name):
- applicant.job_id.write({'no_of_recruitment': applicant.job_id.no_of_recruitment - 1})
- emp_id = hr_employee.create(cr, uid, {'name': applicant.partner_name or contact_name,
+ applicant.job_id.write({'no_of_hired_employee': applicant.job_id.no_of_hired_employee + 1})
+ emp_id = hr_employee.create(cr,uid,{'name': applicant.partner_name or contact_name,
'job_id': applicant.job_id.id,
'address_home_id': address_id,
- 'department_id': applicant.department_id.id
+ 'department_id': applicant.department_id.id or False,
+ 'address_id': applicant.company_id and applicant.company_id.partner_id and applicant.company_id.partner_id.id or False,
+ 'work_email': applicant.department_id and applicant.department_id.company_id and applicant.department_id.company_id.email or False,
+ 'work_phone': applicant.department_id and applicant.department_id.company_id and applicant.department_id.company_id.phone or False,
})
self.write(cr, uid, [applicant.id], {'emp_id': emp_id}, context=context)
+ self.pool['hr.job'].message_post(cr, uid, [applicant.job_id.id], body=_('New Employee %s Hired') % applicant.partner_name, subtype="hr_recruitment.mt_applicant_employee", context=context)
else:
raise osv.except_osv(_('Warning!'), _('You must define an Applied Job and a Contact Name for this applicant.'))