1
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# Copyright (c) 2010 E.Samyn - info@open-shift.com
8
# This file is part of the hr_contract_extension module
10
# WARNING: This program as such is intended to be used by professional
11
# programmers who take the whole responsability of assessing all potential
12
# consequences resulting from its eventual inadequacies and bugs
13
# End users who are looking for a ready-to-use solution with commercial
14
# garantees and support are strongly adviced to contract a Free Software
17
# This program is Free Software; you can redistribute it and/or
18
# modify it under the terms of the GNU General Public License
19
# as published by the Free Software Foundation; either version 2
20
# of the License, or (at your option) any later version.
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU General Public License for more details.
27
# You should have received a copy of the GNU General Public License
28
# along with this program;
29
# If not, see <http://www.gnu.org/licenses/> or write to the Free Software
30
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
##############################################################################
34
from osv import fields, osv
35
from mx import DateTime
39
# ponctual payments (bonus, commission,...)
40
class contract_ponctual_payment(osv.osv):
41
_name = 'contract.ponctual.payment'
42
_description = 'ponctual payment object'
44
'name' : fields.char('Label', size=60, required=True),
45
'start_date' : fields.date('Period start date'),
46
'end_date' : fields.date('Period end date'),
47
'payment_date' : fields.date('Payment date'),
48
'amount' : fields.float('Amount', digits=(16,2)),
49
'contract_id' : fields.many2one('hr.contract','Contract'),
51
contract_ponctual_payment()
53
# hr_contract extension
54
class hr_contract(osv.osv):
56
_description = 'contract extension'
57
_inherit = "hr.contract"
59
'parent_id' : fields.many2one('hr.contract','Parent contract',help='For sub contracts'),
60
'working_place' : fields.char('Contract location', size=60),
61
'trial_extension_end_date' : fields.date('Trial extension end date'),
62
'work_permit_type' : fields.selection([('student','Student'),
63
('employee','Employee'),
64
('other','Other')],'Work permit type'),
65
'work_permit_validity' : fields.date('Work permit validity'),
66
'current_job_level' : fields.many2one('hr.job.level','Current job level'), # IMPROVEMENT TO DO : set fields job_id & current_job_level of the employee form readonly and create a function that updates those fields with the last contract details
67
'payments_ids': fields.one2many('contract.ponctual.payment', 'contract_id', 'Ponctual payments',help='For bonus, commissions,...'),
68
'seniority_rate' : fields.float('Seniority rate', digits=(6,2), help='To calculate internal seniority (0 to 1)'),
73
class hr_employee(osv.osv):
75
_description = "Employee seniority"
76
_inherit = "hr.employee"
78
#--- Method to calculate the total seniority
79
def _get_total_seniority(self,cr,uid,ids,field_name,arg,context):
81
employees = self.browse(cr, uid, ids)
82
for employee in employees:
83
res[employee.id] = 0.0
84
if employee.internal_seniority:
85
total = employee.external_seniority + employee.internal_seniority
86
res[employee.id] = total
88
res[employee.id] = employee.external_seniority
91
#--- Method to calculate the internal seniority
92
def get_internal_seniority(self,cr,uid,ids,*args):
93
start_date = datetime.date.today()
94
end_date = datetime.date.today() # if the last contract has no en date, en date = today
95
internal_seniority = 0.0
96
internal_year_seniority = 0.0
97
internal_month_seniority = 0.0
98
# Get contracts for employee
99
contract_pool = self.pool.get('hr.contract')
100
contract_ids = contract_pool.search(cr,uid,[('employee_id','=',ids[0])],order='date_start desc') # contracts from today to first based on start date
101
contracts = contract_pool.browse(cr, uid, contract_ids)
102
# Get seniority for each contract
103
for contract in contracts:
104
seniority_rate = 1 # default seniority
105
start_date = DateTime.strptime(contract.date_start,'%Y-%m-%d')
106
if contract.seniority_rate:
107
seniority_rate = contract.seniority_rate
108
if contract.date_end:
109
end_date = DateTime.strptime(contract.date_end,'%Y-%m-%d')
110
internal_year_seniority += (end_date.year - start_date.year)*seniority_rate*1.0 # *1.0 to get a float
111
internal_month_seniority += (end_date.month - start_date.month + 1)*seniority_rate*1.0 # +1 : a started month is counted as a full month
112
end_date = start_date # if previous contract (in time scale) has no end date, its supposed end date is the current contract start date
113
# set seniority in years
114
internal_seniority = internal_year_seniority + internal_month_seniority/12 + internal_month_seniority//12
115
# Update internal seniority field
116
self.write(cr,uid,ids,{'internal_seniority':internal_seniority})
120
'external_seniority': fields.float('External seniority', digits=(6,2), help='Seniority gained outside the compagny'),
121
'internal_seniority': fields.float('Internal seniority', digits=(6,2), help="""Seniority gained inside the compagny
122
Calculated from employee contracts in start date desc order: sum((end_date-start_date)*seniority_rate)
123
A started month is counted as full.
124
Need to refresh the form to display new value."""),
125
'total_seniority': fields.function(_get_total_seniority, method=True, string='Total seniority', type='float', help='External+internal'),
b'\\ No newline at end of file'