[CLEAN] hr_recruitment: cleaning before merging

- some code reindentation
- updated subtypes, to use parent_id feature between applicants and jobs. Another task will
improve the layout bu hiding some subtypes in applicant; currently we keep a child / parent
behavior.
- renamed open_attachments method
- some changes in create reverted
- chatter posted in job now hav ea subtype, not sure to keep those

bzr revid: tde@openerp.com-20140211105807-ay93xbwilsz3mso6
This commit is contained in:
Thibault Delavallée 2014-02-11 11:58:07 +01:00
parent 87028244f4
commit 7fd1a825a8
3 changed files with 66 additions and 40 deletions

View File

@ -19,12 +19,10 @@
#
##############################################################################
from openerp import tools
from datetime import datetime
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import html2plaintext
AVAILABLE_PRIORITIES = [
('', ''),
@ -84,7 +82,8 @@ class hr_applicant(osv.Model):
_inherit = ['mail.thread', 'ir.needaction_mixin']
_track = {
'stage_id': {
# this is only an heuristics; depending on your particular stage configuration it may not match all 'new' stages
# this is only an heuristics; depending on your particular stage configuration it may not match all 'new' stages
'hr_recruitment.mt_applicant_new': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.sequence <= 1,
'hr_recruitment.mt_applicant_stage_changed': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.sequence > 1,
},
}
@ -341,9 +340,9 @@ class hr_applicant(osv.Model):
return value
def action_get_attachment_tree_view(self, cr, uid, ids, context=None):
model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base','action_attachment')
model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'action_attachment')
action = self.pool.get(model).read(cr, uid, action_id, context=context)
action['context'] = {'default_res_model': self._name,'default_res_id': ids[0]}
action['context'] = {'default_res_model': self._name, 'default_res_id': ids[0]}
action['domain'] = str(['&', ('res_model', '=', self._name), ('res_id', 'in', ids)])
return action
@ -366,7 +365,7 @@ class hr_applicant(osv.Model):
val = msg.get('from').split('<')[0]
defaults = {
'name': msg.get('subject') or _("No Subject"),
'partner_name':val,
'partner_name': val,
'email_from': msg.get('from'),
'email_cc': msg.get('cc'),
'user_id': False,
@ -380,12 +379,17 @@ class hr_applicant(osv.Model):
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
context['mail_create_nolog'] = True
if vals.get('department_id') and not context.get('default_department_id'):
context['default_department_id'] = vals.get('department_id')
if vals.get('job_id'):
name = vals['partner_name'] if vals['partner_name'] != False else vals['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)
obj_id = super(hr_applicant, self).create(cr, uid, vals, context=context)
applicant = self.browse(cr, uid, obj_id, context=context)
if applicant.job_id:
name = applicant.partner_name if applicant.partner_name else applicant.name
self.pool['hr.job'].message_post(
cr, uid, [applicant.job_id.id],
body=_('New application from %s') % name,
subtype="hr_recruitment.mt_job_applicant_new", context=context)
return obj_id
def write(self, cr, uid, ids, vals, context=None):
@ -405,10 +409,15 @@ class hr_applicant(osv.Model):
else:
res = super(hr_applicant, self).write(cr, uid, ids, vals, context=context)
# post processing: if job changed, post a message on the job
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)
name = applicant.partner_name if applicant.partner_name else applicant.name
self.pool['hr.job'].message_post(
cr, uid, [vals['job_id']],
body=_('New application from %s') % name,
subtype="hr_recruitment.mt_job_applicant_new", 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)
@ -449,7 +458,7 @@ class hr_applicant(osv.Model):
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_hired_employee': applicant.job_id.no_of_hired_employee + 1})
applicant.job_id.write({'no_of_hired_employee': applicant.job_id.no_of_hired_employee + 1}, context=context)
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,
@ -459,7 +468,10 @@ class hr_applicant(osv.Model):
'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)
self.pool['hr.job'].message_post(
cr, uid, [applicant.job_id.id],
body=_('New Employee %s Hired') % applicant.partner_name if applicant.partner_name else applicant.name,
subtype="hr_recruitment.mt_job_applicant_hired", context=context)
else:
raise osv.except_osv(_('Warning!'), _('You must define an Applied Job and a Contact Name for this applicant.'))
@ -502,7 +514,12 @@ class hr_job(osv.osv):
attachment_obj = self.pool.get('ir.attachment')
for job_id in ids:
applicant_ids = self.pool.get('hr.applicant').search(cr, uid, [('job_id', '=', job_id)], context=context)
res[job_id] = attachment_obj.search(cr, uid, ['|', '&',('res_model', '=', 'hr.job'), ('res_id', '=', job_id), '&',('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)], context=context)
res[job_id] = attachment_obj.search(
cr, uid, [
'|',
'&', ('res_model', '=', 'hr.job'), ('res_id', '=', job_id),
'&', ('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)
], context=context)
return res
_columns = {
@ -512,7 +529,7 @@ class hr_job(osv.osv):
"create new applicants for this job position."),
'application_ids': fields.one2many('hr.applicant', 'job_id', 'Applications'),
'manager_id': fields.related('department_id', 'manager_id', type='many2one', string='Department Manager', relation='hr.employee', readonly=True, store=True),
'document_ids': fields.function(_get_attached_docs, method=True, type='one2many', relation='ir.attachment', string='Applications'),
'document_ids': fields.function(_get_attached_docs, type='one2many', relation='ir.attachment', string='Applications'),
'user_id': fields.many2one('res.users', 'Recruitment Responsible', track_visibility='onchange'),
'address_id': fields.many2one('res.partner', 'Job Location', help="Address where employees are working"),
}
@ -522,7 +539,6 @@ class hr_job(osv.osv):
return user.company_id.partner_id.id
_defaults = {
'alias_name':lambda self,cr,uid,c: self.pool.get('hr.config.settings').get_default_alias_prefix(cr,uid,uid,c)['alias_prefix'],
'address_id': _address_get
}
@ -563,13 +579,13 @@ class hr_job(osv.osv):
'nodestroy': True,
}
def open_attachments(self, cr, uid, ids, context=None):
def action_get_attachment_tree_view(self, cr, uid, ids, context=None):
#open attachments of job and related applicantions.
model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base','action_attachment')
model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'action_attachment')
action = self.pool.get(model).read(cr, uid, action_id, context=context)
applicant_ids = self.pool.get('hr.applicant').search(cr, uid, [('job_id', 'in', ids)], context=context)
action['context'] = {'default_res_model': self._name,'default_res_id': ids[0]}
action['domain'] = str(['|', '&', ('res_model', '=', 'hr.job'), ('res_id', 'in', ids), '&',('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)])
action['context'] = {'default_res_model': self._name, 'default_res_id': ids[0]}
action['domain'] = str(['|', '&', ('res_model', '=', 'hr.job'), ('res_id', 'in', ids), '&', ('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)])
return action
class applicant_category(osv.osv):

View File

@ -499,34 +499,45 @@
</record>
<!-- Applicant-related subtypes for messaging / Chatter -->
<record id="mt_applicant_new" model="mail.message.subtype">
<field name="name">New Applicant</field>
<field name="res_model">hr.applicant</field>
<field name="default" eval="False"/>
<field name="description">Applicant created</field>
</record>
<record id="mt_applicant_stage_changed" model="mail.message.subtype">
<field name="name">Stage Changed</field>
<field name="res_model">hr.applicant</field>
<field name="default" eval="False"/>
<field name="description">Stage changed</field>
</record>
<record id="mt_applicant_hired" model="mail.message.subtype">
<field name="name">Applicant Hired</field>
<field name="res_model">hr.applicant</field>
<field name="default" eval="False"/>
<field name="description">Applicant hired</field>
</record>
<!-- Job-related subtypes for messaging / Chatter -->
<record id="mt_job_applicant_stage" model="mail.message.subtype">
<field name="name">Application Stage Changed</field>
<record id="mt_job_applicant_new" model="mail.message.subtype">
<field name="name">Applicant Created</field>
<field name="res_model">hr.job</field>
<field name="default" eval="False"/>
<field name="parent_id" eval="ref('mt_applicant_new')"/>
<field name="relation_field">job_id</field>
</record>
<record id="mt_job_applicant_stage_changed" model="mail.message.subtype">
<field name="name">Applicant Stage Changed</field>
<field name="res_model">hr.job</field>
<field name="default" eval="True"/>
<field name="parent_id" eval="ref('mt_applicant_stage_changed')"/>
<field name="relation_field">job_id</field>
</record>
<record id="mt_applicant_employee" model="mail.message.subtype">
<field name="name">Applicant Assigned</field>
<record id="mt_job_applicant_hired" model="mail.message.subtype">
<field name="name">Applicant Hired</field>
<field name="res_model">hr.job</field>
<field name="default" eval="True"/>
<field name="description">Applicant Hired</field>
</record>
<record id="mt_applicant_new" model="mail.message.subtype">
<field name="name">New Applicants</field>
<field name="res_model">hr.job</field>
<field name="default" eval="False"/>
<field name="description">Applicant Created</field>
<field name="parent_id" eval="ref('mt_applicant_hired')"/>
<field name="relation_field">job_id</field>
</record>
<!-- Applicant Categories(Tag) -->

View File

@ -34,7 +34,7 @@
</record>
<!-- Jobs -->
<!-- Applicants -->
<record model="ir.ui.view" id="crm_case_tree_view_job">
<field name="name">Applicants</field>
<field name="model">hr.applicant</field>
@ -307,8 +307,6 @@
</field>
</record>
<!-- HR Job -->
<record model="ir.actions.act_window" id="action_hr_job_applications">
<field name="name">Applications</field>
<field name="res_model">hr.applicant</field>
@ -326,6 +324,7 @@
</field>
</record>
<!-- Jobs -->
<record id="view_job_filter_recruitment" model="ir.ui.view">
<field name="name">Job</field>
<field name="model">hr.job</field>
@ -370,7 +369,7 @@
</xpath>
<div name="buttons" position="inside">
<button string="Applications" name="%(action_hr_job_applications)d" context="{'default_user_id': user_id}" type="action"/>
<button name="open_attachments" string="Documents" type="object"/>
<button string="Documents" name="action_get_attachment_tree_view" type="object"/>
</div>
</field>
</record>
@ -435,7 +434,7 @@
<span t-if="record.application_ids.raw_value.length lt 2"><t t-esc="record.application_ids.raw_value.length"/> Application</span>
</a>
<br/>
<a t-if="record.document_ids.raw_value.length gt 0" name="open_attachments" type="object">
<a t-if="record.document_ids.raw_value.length gt 0" name="action_get_attachment_tree_view" type="object">
<span t-if="record.document_ids.raw_value.length gt 1"><t t-esc="record.document_ids.raw_value.length"/> Documents</span>
<span t-if="record.document_ids.raw_value.length lt 2"><t t-esc="record.document_ids.raw_value.length"/> Document</span>
</a>