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 ##############################################################################
22 from mx import DateTime
26 from osv import fields, osv
27 from tools.translate import _
29 class hr_employee_category(osv.osv):
30 _name = "hr.employee.category"
31 _description = "Employee Category"
34 'name' : fields.char("Category", size=64, required=True),
35 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
36 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
39 def _check_recursion(self, cr, uid, ids):
42 cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(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=30, required=True),
60 'description' : fields.text('Status Description'),
62 hr_employee_marital_status()
64 class crm_job(osv.osv):
66 def _no_of_employee(self, cr, uid, ids, name,args,context=None):
68 for emp in self.browse(cr, uid, ids):
69 res[emp.id] = str(len(emp.employee_ids))
73 _description = "Job Information"
75 'name': fields.char('Name', size=128, required=True, select=True),
76 'ref': fields.char('Code', size=64),
77 'expected_employees':fields.integer('Expected Employees'),
78 'no_of_employee': fields.function(_no_of_employee, method=True, string='No of Employee', type='char'),
79 'employee_ids':fields.one2many('hr.employee', 'job_id','Employees'),
80 'description': fields.text('Job Description'),
81 'requirements':fields.text('Requirements'),
82 'department_id':fields.many2one('hr.department','Department')
86 'expected_employees': lambda *a: 1,
91 class hr_employee(osv.osv):
93 _description = "Employee"
94 _inherits = {'resource.resource':"resource_id"}
96 'country_id' : fields.many2one('res.country', 'Nationality'),
97 'birthday' : fields.date("Birthday"),
98 'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
99 'sinid': fields.char('SIN No', size=32),
100 'otherid': fields.char('Other ID', size=32),
101 'gender': fields.selection([('',''),('male','Male'),('female','Female')], 'Gender'),
102 'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
104 'partner_id' : fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
106 'address_id': fields.many2one('res.partner.address', 'Working Address'),
107 'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
108 'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone'),
109 'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail'),
110 'work_location': fields.char('Office Location', size=32),
112 'notes': fields.text('Notes'),
113 'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
114 'category_id' : fields.many2one('hr.employee.category', 'Category'),
115 'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
116 'resource_id': fields.many2one('resource.resource','Resource',ondelete='cascade'),
117 'coach_id':fields.many2one('res.users','Coach'),
118 'job_id':fields.many2one('crm.job', 'Job'),
122 'active' : lambda *a: True,
125 def _check_recursion(self, cr, uid, ids):
128 cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,))
129 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
136 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
142 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: