from datetime import datetime
+from openerp import tools
from openerp import SUPERUSER_ID
from openerp.osv import fields, osv
from openerp.tools.translate import _
AVAILABLE_PRIORITIES = [
- ('0', 'Bad'),
- ('1', 'Below Average'),
- ('2', 'Average'),
- ('3', 'Good'),
- ('4', 'Excellent')
+ ('0', 'Normal'),
+ ('1', 'Good'),
+ ('2', 'Very Good'),
+ ('3', 'Excellent')
]
class hr_recruitment_source(osv.osv):
class hr_applicant(osv.Model):
_name = "hr.applicant"
_description = "Applicant"
- _order = "id desc"
+ _order = "priority desc, id desc"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_track = {
+ 'emp_id': {
+ 'hr_recruitment.mt_applicant_hired': lambda self, cr, uid, obj, ctx=None: obj.emp_id,
+ },
'stage_id': {
# 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,
return result, fold
def _compute_day(self, cr, uid, ids, fields, args, context=None):
- """
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of Openday’s IDs
- @return: difference between current date and log date
- @param context: A standard dictionary for contextual values
- """
- res = {}
+ res = dict((res_id, {}) for res_id in ids)
for issue in self.browse(cr, uid, ids, context=context):
+ values = {
+ 'day_open': 0.0,
+ 'day_close': 0.0,
+ }
+
+ if issue.date_open:
+ date_create = datetime.strptime(issue.create_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
+ date_open = datetime.strptime(issue.date_open, tools.DEFAULT_SERVER_DATETIME_FORMAT)
+ values['day_open'] = (date_open - date_create).total_seconds() / (24.0 * 3600)
+
+ if issue.date_closed:
+ date_create = datetime.strptime(issue.create_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
+ date_closed = datetime.strptime(issue.date_closed, tools.DEFAULT_SERVER_DATETIME_FORMAT)
+ values['day_close'] = (date_closed - date_create).total_seconds() / (24.0 * 3600)
+
+ # filter only required values
for field in fields:
- res[issue.id] = {}
- duration = 0
- ans = False
- hours = 0
-
- if field in ['day_open']:
- if issue.date_open:
- date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
- date_open = datetime.strptime(issue.date_open, "%Y-%m-%d %H:%M:%S")
- ans = date_open - date_create
-
- elif field in ['day_close']:
- if issue.date_closed:
- date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
- date_close = datetime.strptime(issue.date_closed, "%Y-%m-%d %H:%M:%S")
- ans = date_close - date_create
- if ans:
- duration = float(ans.days)
- res[issue.id][field] = abs(float(duration))
+ res[issue.id][field] = values[field]
return res
def _get_attachment_number(self, cr, uid, ids, fields, args, context=None):
'response_id': fields.many2one('survey.user_input', "Response", ondelete='set null', oldname="response"),
'reference': fields.char('Referred By'),
'source_id': fields.many2one('hr.recruitment.source', 'Source'),
- 'day_open': fields.function(_compute_day, string='Days to Open', \
- multi='day_open', type="float", store=True),
- 'day_close': fields.function(_compute_day, string='Days to Close', \
- multi='day_close', type="float", store=True),
+ 'day_open': fields.function(_compute_day, string='Days to Open',
+ multi='day_open', type="float",
+ store={'hr.applicant': (lambda self, cr, uid, ids, c={}: ids, ['date_open'], 10)}),
+ 'day_close': fields.function(_compute_day, string='Days to Close',
+ multi='day_close', type="float",
+ store={'hr.applicant': (lambda self, cr, uid, ids, c={}: ids, ['date_closed'], 10)}),
'color': fields.integer('Color Index'),
- 'emp_id': fields.many2one('hr.employee', string='Employee', help='Employee linked to the applicant.'),
+ 'emp_id': fields.many2one('hr.employee', string='Employee', track_visibility='onchange', help='Employee linked to the applicant.'),
'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
'attachment_number': fields.function(_get_attachment_number, string='Number of Attachments', type="integer"),
}
'department_id': lambda s, cr, uid, c: s._get_default_department_id(cr, uid, c),
'company_id': lambda s, cr, uid, c: s._get_default_company_id(cr, uid, s._get_default_department_id(cr, uid, c), c),
'color': 0,
+ 'priority': '0',
'date_last_stage_update': fields.datetime.now,
}
'email_from': addr.email})
return {'value': data}
+ def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
+ if not stage_id:
+ return {'value': {}}
+ stage = self.pool['hr.recruitment.stage'].browse(cr, uid, stage_id, context=context)
+ if stage.fold:
+ return {'value': {'date_closed': fields.datetime.now()}}
+ return {'value': {'date_closed': False}}
+
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:
if vals.get('job_id') or context.get('default_job_id'):
job_id = vals.get('job_id') or context.get('default_job_id')
vals.update(self.onchange_job(cr, uid, [], job_id, context=context)['value'])
+ if vals.get('user_id'):
+ vals['date_open'] = fields.datetime.now()
+ if 'stage_id' in vals:
+ vals.update(self.onchange_stage_id(cr, uid, None, vals.get('stage_id'), context=context)['value'])
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:
# stage_id: track last stage before update
if 'stage_id' in vals:
vals['date_last_stage_update'] = fields.datetime.now()
+ vals.update(self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)['value'])
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)
'model': self._name,
'composition_mode': 'mass_mail',
'template_id': stage.template_id.id,
- 'same_thread': True,
'post': True,
'notify': True,
}, context=compose_ctx)
'hr.applicant', self._columns['alias_id'], 'name', alias_prefix='job+', alias_defaults={'job_id': 'id'}, context=context)
def create(self, cr, uid, vals, context=None):
+ # TDE note: shouldn't it be in mail_create_nolog ?
alias_context = dict(context, alias_model_name='hr.applicant', alias_parent_model_name=self._name)
job_id = super(hr_job, self).create(cr, uid, vals, context=alias_context)
job = self.browse(cr, uid, job_id, context=context)
_columns = {
'name': fields.char('Name', required=True, translate=True),
}
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: