[FIX] Several fixes into hr_evaluation models

hr_evaluation now uses the revamped surveys

bzr revid: rim@openerp.com-20140318155534-pc7m615ogqp9p30n
This commit is contained in:
Richard Mathot (OpenERP) 2014-03-18 16:55:34 +01:00
parent 39f3264e53
commit 79428ff8a9
3 changed files with 47 additions and 32 deletions

View File

@ -19,13 +19,14 @@
# #
############################################################################## ##############################################################################
from datetime import datetime from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from dateutil import parser from dateutil import parser
import time import time
from openerp.osv import fields, osv from openerp.osv import fields, osv
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT as DF
class hr_evaluation_plan(osv.Model): class hr_evaluation_plan(osv.Model):
@ -115,9 +116,7 @@ class hr_employee(osv.Model):
first_date = (now + relativedelta(months=emp.evaluation_plan_id.month_first)).strftime('%Y-%m-%d') first_date = (now + relativedelta(months=emp.evaluation_plan_id.month_first)).strftime('%Y-%m-%d')
self.write(cr, uid, [emp.id], {'evaluation_date': first_date}, context=context) self.write(cr, uid, [emp.id], {'evaluation_date': first_date}, context=context)
emp_ids = self.search(cr, uid, [ emp_ids = self.search(cr, uid, [('evaluation_plan_id', '<>', False), ('evaluation_date', '<=', time.strftime("%Y-%m-%d"))], context=context)
('evaluation_plan_id', '<>', False), ('evaluation_date', '<=', time.strftime("%Y-%m-%d")),
], context=context)
for emp in self.browse(cr, uid, emp_ids, context=context): for emp in self.browse(cr, uid, emp_ids, context=context):
next_date = (now + relativedelta(months=emp.evaluation_plan_id.month_next)).strftime('%Y-%m-%d') next_date = (now + relativedelta(months=emp.evaluation_plan_id.month_next)).strftime('%Y-%m-%d')
self.write(cr, uid, [emp.id], {'evaluation_date': next_date}, context=context) self.write(cr, uid, [emp.id], {'evaluation_date': next_date}, context=context)
@ -130,7 +129,6 @@ class hr_evaluation(osv.Model):
_name = "hr_evaluation.evaluation" _name = "hr_evaluation.evaluation"
_inherit = "mail.thread" _inherit = "mail.thread"
_description = "Employee Appraisal" _description = "Employee Appraisal"
_rec_name = 'employee_id'
_columns = { _columns = {
'date': fields.date("Appraisal Deadline", required=True, select=True), 'date': fields.date("Appraisal Deadline", required=True, select=True),
'employee_id': fields.many2one('hr.employee', "Employee", required=True), 'employee_id': fields.many2one('hr.employee', "Employee", required=True),
@ -155,7 +153,7 @@ class hr_evaluation(osv.Model):
'date_close': fields.date('Ending Date', select=True), 'date_close': fields.date('Ending Date', select=True),
} }
_defaults = { _defaults = {
'date': lambda *a: (parser.parse(datetime.now().strftime('%Y-%m-%d')) + relativedelta(months =+ 1)).strftime('%Y-%m-%d'), 'date': lambda *a: (parser.parse(datetime.now().strftime('%Y-%m-%d')) + relativedelta(months=+1)).strftime('%Y-%m-%d'),
'state': lambda *a: 'draft', 'state': lambda *a: 'draft',
} }
@ -166,7 +164,8 @@ class hr_evaluation(osv.Model):
res = [] res = []
for record in reads: for record in reads:
name = record.plan_id.name name = record.plan_id.name
res.append((record['id'], name)) employee = record.employee_id.name_related
res.append((record['id'], name + ' / ' + employee))
return res return res
def onchange_employee_id(self, cr, uid, ids, employee_id, context=None): def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
@ -198,10 +197,9 @@ class hr_evaluation(osv.Model):
int_id = hr_eval_inter_obj.create(cr, uid, { int_id = hr_eval_inter_obj.create(cr, uid, {
'evaluation_id': evaluation.id, 'evaluation_id': evaluation.id,
'survey_id': phase.survey_id.id, 'phase_id': phase.id,
'deadline': (parser.parse(datetime.now().strftime('%Y-%m-%d')) + relativedelta(months =+ 1)).strftime('%Y-%m-%d'), 'deadline': (parser.parse(datetime.now().strftime('%Y-%m-%d')) + relativedelta(months=+1)).strftime('%Y-%m-%d'),
'user_id': child.user_id.id, 'user_id': child.user_id.id,
'user_to_review_id': evaluation.employee_id.id
}, context=context) }, context=context)
if phase.wait: if phase.wait:
wait = True wait = True
@ -230,7 +228,7 @@ class hr_evaluation(osv.Model):
if evaluation.employee_id and evaluation.employee_id.parent_id and evaluation.employee_id.parent_id.user_id: if evaluation.employee_id and evaluation.employee_id.parent_id and evaluation.employee_id.parent_id.user_id:
self.message_subscribe_users(cr, uid, [evaluation.id], user_ids=[evaluation.employee_id.parent_id.user_id.id], context=context) self.message_subscribe_users(cr, uid, [evaluation.id], user_ids=[evaluation.employee_id.parent_id.user_id.id], context=context)
if len(evaluation.survey_request_ids) != len(request_obj.search(cr, uid, [('evaluation_id', '=', evaluation.id), ('state', 'in', ['done', 'cancel'])], context=context)): if len(evaluation.survey_request_ids) != len(request_obj.search(cr, uid, [('evaluation_id', '=', evaluation.id), ('state', 'in', ['done', 'cancel'])], context=context)):
raise osv.except_osv(_('Warning!'), _("You cannot change state, because some appraisal(s) are in waiting answer or draft state.")) raise osv.except_osv(_('Warning!'), _("You cannot change state, because some appraisal forms have not been completed."))
return True return True
def button_done(self, cr, uid, ids, context=None): def button_done(self, cr, uid, ids, context=None):
@ -265,8 +263,8 @@ class hr_evaluation(osv.Model):
if 'date' in vals: if 'date' in vals:
new_vals = {'deadline': vals.get('date')} new_vals = {'deadline': vals.get('date')}
obj_hr_eval_iterview = self.pool.get('hr.evaluation.interview') obj_hr_eval_iterview = self.pool.get('hr.evaluation.interview')
for evalutation in self.browse(cr, uid, ids, context=context): for evaluation in self.browse(cr, uid, ids, context=context):
for survey_req in evalutation.survey_request_ids: for survey_req in evaluation.survey_request_ids:
obj_hr_eval_iterview.write(cr, uid, [survey_req.id], new_vals, context=context) obj_hr_eval_iterview.write(cr, uid, [survey_req.id], new_vals, context=context)
return super(hr_evaluation, self).write(cr, uid, ids, vals, context=context) return super(hr_evaluation, self).write(cr, uid, ids, vals, context=context)
@ -274,33 +272,51 @@ class hr_evaluation(osv.Model):
class hr_evaluation_interview(osv.Model): class hr_evaluation_interview(osv.Model):
_name = 'hr.evaluation.interview' _name = 'hr.evaluation.interview'
_inherit = 'mail.thread' _inherit = 'mail.thread'
_rec_name = 'request_id' _rec_name = 'user_to_review_id'
_description = 'Appraisal Interview' _description = 'Appraisal Interview'
_columns = { _columns = {
'request_id': fields.many2one('survey.user_input', 'Survey Request', ondelete='cascade', required=True), 'request_id': fields.many2one('survey.user_input', 'Survey Request', ondelete='restrict', readonly=True),
'user_to_review_id': fields.many2one('hr.employee', 'Employee to Interview'), 'evaluation_id': fields.many2one('hr_evaluation.evaluation', 'Appraisal Plan', required=True),
'evaluation_id': fields.many2one('hr_evaluation.evaluation', 'Appraisal Form'), 'phase_id': fields.many2one('hr_evaluation.plan.phase', 'Appraisal Phase', required=True),
'user_id': fields.many2one('res.users', 'Interviewer'), 'user_to_review_id': fields.related('evaluation_id', 'employee_id', type="many2one", relation="hr.employee", string="Employee to evaluate"),
'user_id': fields.many2one('res.users', 'Interviewer', required=True),
'state': fields.selection([('draft', "Draft"), 'state': fields.selection([('draft', "Draft"),
('waiting_answer', "In progress"), ('waiting_answer', "In progress"),
('done', "Done"), ('done', "Done"),
('cancel', "Cancelled")], ('cancel', "Cancelled")],
string="State", required=True), string="State", required=True),
# fields from request_id # fields from request_id
'survey_id': fields.related('request_id', 'survey_id', string="Appraisal Form", type="many2one", relation="survey.survey"), 'survey_id': fields.related('phase_id', 'survey_id', string="Appraisal Form", type="many2one", relation="survey.survey"),
'deadline': fields.related('request_id', 'deadline', string="Deadline"), 'deadline': fields.related('request_id', 'deadline', type="datetime", string="Deadline"),
} }
_defaults = { _defaults = {
'state': 'draft' 'state': 'draft'
} }
def create(self, cr, uid, vals, context=None):
phase_obj = self.pool.get('hr_evaluation.plan.phase')
survey_id = phase_obj.read(cr, uid, vals.get('phase_id'), fields=['survey_id'], context=context)['survey_id'][0]
user_obj = self.pool.get('res.users')
partner_id = user_obj.read(cr, uid, vals.get('user_id'), fields=['partner_id'], context=context)['partner_id'][0]
user_input_obj = self.pool.get('survey.user_input')
if not vals.get('deadline'):
vals['deadline'] = (datetime.now() + timedelta(days=28)).strftime(DF)
ret = user_input_obj.create(cr, uid, {'survey_id': survey_id,
'deadline': vals.get('deadline'),
'type': 'link',
'partner_id': partner_id}, context=context)
vals['request_id'] = ret
return super(hr_evaluation_interview, self).create(cr, uid, vals, context=context)
def name_get(self, cr, uid, ids, context=None): def name_get(self, cr, uid, ids, context=None):
if not ids: if not ids:
return [] return []
reads = self.browse(cr, uid, ids, context=context) reads = self.browse(cr, uid, ids, context=context)
res = [] res = []
for record in reads: for record in reads:
name = record.request_id.survey_id.title name = record.survey_id.title
res.append((record['id'], name)) res.append((record['id'], name))
return res return res
@ -309,13 +325,12 @@ class hr_evaluation_interview(osv.Model):
return True return True
def survey_req_done(self, cr, uid, ids, context=None): def survey_req_done(self, cr, uid, ids, context=None):
hr_eval_obj = self.pool.get('hr_evaluation.evaluation')
for id in self.browse(cr, uid, ids, context=context): for id in self.browse(cr, uid, ids, context=context):
flag = False flag = False
wating_id = 0 wating_id = 0
if not id.evaluation_id.id: if not id.evaluation_id.id:
raise osv.except_osv(_('Warning!'), _("You cannot start evaluation without Appraisal.")) raise osv.except_osv(_('Warning!'), _("You cannot start evaluation without Appraisal."))
records = hr_eval_obj.browse(cr, uid, [id.evaluation_id.id], context=context)[0].survey_request_ids records = id.evaluation_id.survey_request_ids
for child in records: for child in records:
if child.state == "draft": if child.state == "draft":
wating_id = child.id wating_id = child.id
@ -353,6 +368,3 @@ class hr_evaluation_interview(osv.Model):
context.update({'survey_id': record.survey_id.id, 'response_id': [record.response.id], 'response_no': 0}) context.update({'survey_id': record.survey_id.id, 'response_id': [record.response.id], 'response_no': 0})
value = self.pool.get("survey").action_print_survey(cr, uid, ids, context=context) value = self.pool.get("survey").action_print_survey(cr, uid, ids, context=context)
return value return value
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:1

View File

@ -35,7 +35,7 @@
<field name="action">self</field> <field name="action">self</field>
<field eval="0" name="send_anonymous_employee"/> <field eval="0" name="send_anonymous_employee"/>
<field eval="0" name="send_answer_employee"/> <field eval="0" name="send_answer_employee"/>
<field name="survey_id" ref="appraisal_form"/> <field name="survey_id" ref="opinion_form"/>
<field eval="0" name="send_answer_manager"/> <field eval="0" name="send_answer_manager"/>
<field eval="0" name="wait"/> <field eval="0" name="wait"/>
</record> </record>

View File

@ -310,14 +310,17 @@
</div> </div>
<group> <group>
<group> <group>
<field name="survey_id" domain="[('res_model','=','hr_evaluation')]"/> <field name="evaluation_id" string="Appraisal"/>
<field name="user_to_review_id"/> <field name="phase_id"/>
<field name="user_id" string="Interviewer" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_hr_manager']}"/> <field name="user_to_review_id" readonly="1"/>
</group> </group>
<group> <group>
<field name="user_id" string="Interviewer" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_hr_manager']}"/>
<field name="deadline"/> <field name="deadline"/>
<field name="request_id" readonly="1"/> </group>
<field name="evaluation_id" string="Appraisal Plan"/> <group>
<field name="request_id"/>
<field name="survey_id" domain="[('res_model','=','hr_evaluation')]" readonly="1"/>
</group> </group>
</group> </group>
</sheet> </sheet>