[ADD]: Added access rules for remaining objects in hr_evaluation and survey modules.
[odoo/odoo.git] / addons / hr_evaluation / hr_evaluation.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import time
23 from osv import fields, osv
24 from mx import DateTime as dt
25
26 class hr_evaluation_plan(osv.osv):
27     _name = "hr_evaluation.plan"
28     _description = "Evaluation Plan"
29     _columns = {
30         'name': fields.char("Evaluation Plan", size=64, required=True),
31         'company_id': fields.many2one('res.company', 'Company', required=True),
32         'phase_ids' : fields.one2many('hr_evaluation.plan.phase', 'plan_id', 'Evaluation Phases'),
33         'month_first': fields.integer('First Evaluation After'),
34         'month_next': fields.integer('Next Evaluation After'),
35         'active': fields.boolean('Active')
36     }
37     _defaults = {
38         'active' : lambda *a: True,
39     }
40 hr_evaluation_plan()
41
42 class hr_evaluation_plan_phase(osv.osv):
43     _name = "hr_evaluation.plan.phase"
44     _description = "Evaluation Plan Phase"
45     _order = "sequence"
46     _columns = {
47         'name': fields.char("Phase", size=64, required=True),
48         'sequence': fields.integer("Sequence"),
49         'company_id': fields.related('plan_id','company_id',type='many2one',relation='res.company',string='Company',store=True),
50         'plan_id': fields.many2one('hr_evaluation.plan','Evaluation Plan', required=True, ondelete='cascade'),
51         'action': fields.selection([
52             ('top-down','Top-Down Appraisal Requests'),
53             ('bottom-up','Bottom-Up Appraisal Requests'),
54             ('self','Self Appraisal Requests'),
55             ('final','Final Interview')], 'Action', required=True),
56         'survey_id': fields.many2one('survey','Appraisal Form',required=True),
57         'send_answer_manager': fields.boolean('All Answers',
58             help="Send all answers to the manager"),
59         'send_answer_employee': fields.boolean('All Answers',
60             help="Send all answers to the employee"),
61         'send_anonymous_manager': fields.boolean('Anonymous Summary',
62             help="Send an anonymous summary to the manager"),
63         'send_anonymous_employee': fields.boolean('Anonymous Summary',
64             help="Send an anonymous summary to the employee"),
65         'wait': fields.boolean('Wait Previous Phases',
66             help="Check this box if you want to wait that all preceeding phases " +
67               "are finished before launching this phase.")
68
69     }
70     _defaults = {
71         'sequence' : lambda *a: 1,
72     }
73 hr_evaluation_plan_phase()
74
75 class hr_employee(osv.osv):
76     _inherit="hr.employee"
77     _columns = {
78         'evaluation_plan_id': fields.many2one('hr_evaluation.plan', 'Evaluation Plan'),
79         'evaluation_date': fields.date('Next Evaluation', help="Date of the next evaluation",readonly=True),
80     }
81     
82     def onchange_evaluation_plan_id(self,cr,uid,ids,evaluation_plan_id,context={}):
83         evaluation_date = self.browse(cr, uid, ids)[0].evaluation_date or ''
84         evaluation_plan_obj=self.pool.get('hr_evaluation.plan')
85         if evaluation_plan_id:
86             for evaluation_plan in evaluation_plan_obj.browse(cr,uid,[evaluation_plan_id]):
87                 if not evaluation_date:
88                    evaluation_date=(dt.ISO.ParseAny(dt.now().strftime('%Y-%m-%d'))+ dt.RelativeDateTime(months=+evaluation_plan.month_first)).strftime('%Y-%m-%d')
89                 else:
90                    evaluation_date=(dt.ISO.ParseAny(evaluation_date)+ dt.RelativeDateTime(months=+evaluation_plan.month_next)).strftime('%Y-%m-%d')
91         return {'value': {'evaluation_date':evaluation_date}}
92 hr_employee()
93
94 class hr_evaluation_interview(osv.osv):
95     _name = "hr.evaluation.interview"
96     _inherit = "survey.request"
97     
98     def default_get(self, cr, uid, fields, context={}):
99         data = super(hr_evaluation_interview, self).default_get(cr, uid, fields, context)
100         if context.has_key('phase_id'):
101             data['survey_id'] =self.pool.get('hr_evaluation.plan.phase').browse(cr, uid, context['phase_id']).survey_id.id
102         return data
103
104     _columns = {
105         'user_to_review_id': fields.many2one('hr.employee', 'Employee'),
106     }
107 hr_evaluation_interview()
108
109 class hr_evaluation(osv.osv):
110     _name = "hr_evaluation.evaluation"
111     _description = "Employee Evaluation"
112     _rec_name = 'employee_id'
113     _columns = {
114         'date': fields.date("Evaluation Deadline", required=True),
115         'employee_id': fields.many2one('hr.employee', "Employee", required=True),
116         'note_summary': fields.text('Evaluation Summary'),
117         'note_action': fields.text('Action Plan',
118             help="If the evaluation does not meet the expectations, you can propose"+
119               "an action plan"),
120         'rating': fields.selection([
121             ('0','Significantly bellow expectations'),
122             ('1','Did not meet expectations'),
123             ('2','Meet expectations'),
124             ('3','Exceeds expectations'),
125             ('4','Significantly exceeds expectations'),
126         ], "Overall Rating", help="This is the overall rating on that summarize the evaluation"),
127         'survey_request_ids': fields.many2many('hr.evaluation.interview',
128             'hr_evaluation_evaluation_requests',
129             'evaluation_id',
130             'survey_id',
131             'Appraisal Forms'),
132         'plan_id': fields.many2one('hr_evaluation.plan', 'Plan', required=True),
133         'state': fields.selection([
134             ('draft','Draft'),
135             ('wait','Plan In Progress'),
136             ('progress','Final Validation'),
137             ('done','Done'),
138             ('cancel','Cancelled'),
139         ], 'State', required=True,readonly=True),
140         'date_close': fields.date('Ending Date')
141     }
142     _defaults = {
143         'date' : lambda *a: time.strftime('%Y-%m-%d'),
144         'state' : lambda *a: 'draft',
145     }
146
147     def button_plan_in_progress(self,cr, uid, ids, context):
148         self.write(cr,uid,ids,{'state':'wait'})
149         return True
150
151     def button_final_validation(self,cr, uid, ids, context):
152         self.write(cr,uid,ids,{'state':'progress'})
153         return True
154
155     def button_done(self,cr, uid, ids, context):
156         self.write(cr,uid,ids,{'state':'done', 'date_close': time.strftime('%Y-%m-%d')})
157         return True
158
159     def button_cancel(self,cr, uid, ids, context):
160         self.write(cr,uid,ids,{'state':'cancel'})
161         return True
162
163 hr_evaluation()
164