1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
24 from osv import fields, osv
26 from tools.translate import _
28 class hr_employee_category(osv.osv):
29 _name = "hr.employee.category"
30 _description = "Employee Category"
32 'name': fields.char("Category", size=64, required=True),
33 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
34 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
37 def _check_recursion(self, cr, uid, ids, context=None):
42 cr.execute('select distinct parent_id from hr_employee_category where id IN %s', (tuple(ids), ))
43 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
50 (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
53 hr_employee_category()
55 class hr_employee_marital_status(osv.osv):
56 _name = "hr.employee.marital.status"
57 _description = "Employee Marital Status"
59 'name': fields.char('Marital Status', size=32, required=True),
60 'description': fields.text('Status Description'),
63 hr_employee_marital_status()
65 class hr_job(osv.osv):
67 def _no_of_employee(self, cr, uid, ids, name, args, context=None):
71 for emp in self.browse(cr, uid, ids):
72 res[emp.id] = len(emp.employee_ids or [])
76 _description = "Job Description"
78 'name': fields.char('Job Name', size=128, required=True, select=True),
79 'expected_employees': fields.integer('Expected Employees', help='Required number of Employees'),
80 'no_of_employee': fields.function(_no_of_employee, method=True, string='No of Employees', type='integer', help='Number of Employees selected'),
81 'employee_ids': fields.one2many('hr.employee', 'job_id', 'Employees'),
82 'description': fields.text('Job Description'),
83 'requirements': fields.text('Requirements'),
84 'department_id': fields.many2one('hr.department', 'Department'),
85 'company_id': fields.many2one('res.company', 'Company'),
86 'state': fields.selection([('open', 'Open'),('old', 'Old'),('recruit', 'In Recruitement')], 'State', readonly=True, required=True),
89 'expected_employees': 1,
90 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
94 def job_old(self, cr, uid, ids, *args):
95 self.write(cr, uid, ids, {'state': 'old'})
98 def job_recruitement(self, cr, uid, ids, *args):
99 self.write(cr, uid, ids, {'state': 'recruit'})
102 def job_open(self, cr, uid, ids, *args):
103 self.write(cr, uid, ids, {'state': 'open'})
108 class hr_employee(osv.osv):
109 _name = "hr.employee"
110 _description = "Employee"
111 _inherits = {'resource.resource': "resource_id"}
113 'country_id': fields.many2one('res.country', 'Nationality'),
114 'birthday': fields.date("Birthday"),
115 'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
116 'sinid': fields.char('SIN No', size=32, help="Social Insurance Number"),
117 'otherid': fields.char('Other ID', size=32),
118 'gender': fields.selection([('male', 'Male'),('female', 'Female')], 'Gender'),
119 'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
120 'bank_account': fields.char('Bank Account', size=64),
121 'partner_id': fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
122 'department_id':fields.many2one('hr.department', 'Department'),
123 'address_id': fields.many2one('res.partner.address', 'Working Address'),
124 'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
125 'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone', readonly=True),
126 'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail', readonly=True),
127 'work_location': fields.char('Office Location', size=32),
128 'notes': fields.text('Notes'),
129 'parent_id': fields.related('department_id', 'manager_id', relation='hr.employee', string='Manager', type='many2one', store=True, select=True),
130 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel','category_id','emp_id','Category'),
131 'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),
132 'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True),
133 'coach_id': fields.many2one('hr.employee', 'Coach'),
134 'job_id': fields.many2one('hr.job', 'Job'),
135 'photo': fields.binary('Photo')
138 def _get_photo(self, cr, uid, context=None):
141 return open(os.path.join(
142 tools.config['addons_path'], 'hr/image', 'photo.png'),
143 'rb') .read().encode('base64')
150 def _check_recursion(self, cr, uid, ids, context=None):
153 cr.execute('SELECT DISTINCT parent_id FROM hr_employee WHERE id IN %s AND parent_id!=id',(tuple(ids),))
154 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
161 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
166 class hr_department(osv.osv):
167 _description = "Department"
168 _inherit = 'hr.department'
170 'manager_id': fields.many2one('hr.employee', 'Manager'),
171 # 'member_ids': fields.many2many('hr.employee', 'hr_department_user_rel', 'department_id', 'user_id', 'Members'),
172 'member_ids': fields.one2many('hr.employee', 'department_id', 'Members'),
173 # finding problem to implement one2many field as "hr_departmen_user_rel" is used in another module query
178 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: