1
# -*- encoding: utf-8 -*-
2
##############################################################################
5
# Copyright (C) 2010 Micronaet srl (<http://www.micronaet.it>)
7
# Italian OpenERP Community (<http://www.openerp-italia.com>)
9
#############################################################################
11
# OpenERP, Open Source Management Solution
12
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
15
# This program is free software: you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation, either version 3 of the License, or
18
# (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program. If not, see <http://www.gnu.org/licenses/>.
28
##############################################################################
30
from osv import osv, fields
32
from tools.translate import _
34
week_days = [('mo','Monday'), # python represent weekday starting from 0 = Monday
42
class contract_employee_timesheet_tipology(osv.osv):
43
''' Contract tipology: contains a list of "day of a week" elements and the
44
total amount of hour to be worked that day
47
_name = 'contract.employee.timesheet.tipology'
48
_description = 'Timesheet tipology'
51
'name':fields.char('Description', size=64, required=False, readonly=False),
53
contract_employee_timesheet_tipology()
55
class contract_employee_timesheet_tipology_line(osv.osv):
56
''' Sub element of contract tipology: contains dow and tot. hours
59
_name = 'contract.employee.timesheet.tipology.line'
60
_description = 'Timesheet tipology line'
63
'name': fields.float('Tot. hours', required=True, digits=(4, 2)),
64
'week_day':fields.selection(week_days,'Week day', select=True, readonly=False),
65
'contract_tipology_id':fields.many2one('contract.employee.timesheet.tipology', 'Contract tipology', required=True, ondelete='cascade'),
67
contract_employee_timesheet_tipology_line()
69
class contract_employee_timesheet_tipology(osv.osv):
70
''' Contract tipology: add relation 2many fields
73
_name = 'contract.employee.timesheet.tipology'
74
_inherit = 'contract.employee.timesheet.tipology'
77
'line_ids':fields.one2many('contract.employee.timesheet.tipology.line', 'contract_tipology_id', 'Lines', required=False),
79
contract_employee_timesheet_tipology()
81
class contract_employee_festivity(osv.osv):
83
manage static festivity (also with from-to period)
84
manage dynamic list of festivity (ex. Easter monday)
87
_name = 'contract.employee.festivity'
88
_description = 'Contract festivity'
91
# TODO: function for compute festivity
92
# TODO: function for validate:
93
# static date (max day for day-month)
94
# from to period evaluation (no interference)
95
# no double comment in dynamic date (2 Easter monday for ex. in the same year)
97
def is_festivity(self, cr, uid, date, context=None):
98
''' Test if datetime element date is in festifity rules
100
# Static festivity (periodic):
101
date_ids = self.search(cr, uid, [('static','=',True),
102
('periodic','=',True),
103
('day','=',date.day),
104
('month','=',date.month),
105
('periodic_from','>=',date.year),
106
('periodic_to','<=',date.year),
111
# Static festivity not periodic:
112
date_ids = self.search(cr, uid, [('static','=',True),
113
('periodic','=',False),
114
('day','=',date.day),
115
('month','=',date.month),
121
date_ids = self.search(cr, uid, [('static','=',False),
122
('dynamic_date','=',date.strftime("%Y-%m-%d")),
130
'name':fields.char('Description', size=64, required=False, readonly=False),
133
'static':fields.boolean('Static festivity', help="It means that every year this festivity is the same day (ex. Christmas = 25 of dec.), if not it's dynamic (ex. Easter monday)"),
134
'day': fields.integer('Static day'),
135
'month': fields.integer('Static month'),
136
# static but periodic:
137
'periodic':fields.boolean('Periodic festivity', help="Festivity is only for a from-to period (ex.: Patronal festivity but for a period because of changing city)"),
138
'periodic_from': fields.integer('From year'),
139
'periodic_to': fields.integer('To year'),
141
# dinamic festivity (no periodic is allowed):
142
'dynamic_date': fields.date('Dynamic Date'),
146
'periodic_from': lambda *a: time.strftime('%Y'),
147
'periodic_to': lambda *a: time.strftime('%Y'),
149
contract_employee_festivity()
151
class hr_employee_extra(osv.osv):
152
""" Employee extra fields for manage contract and working hours
153
TODO: create a list of working hour contract (for history of elements)
155
_inherit = 'hr.employee'
156
_name = 'hr.employee'
158
def check_consistency_employee_user_department(self, cr, uid, context=None):
159
''' Procedure for xml-rpc call for check consistency of DB
160
1. check if employee has user linked
164
user_pool = self.pool.get("res.users")
165
employee_proxy=self.browse(cr, uid, self.search(cr, uid, [], context=context))
167
for employee in employee_proxy:
168
if employee.user_id and employee.department_id:
169
update=user_pool.write(cr, uid, employee.user_id.id, {'context_department_id': employee.department_id.id})
174
'contract_tipology_id':fields.many2one('contract.employee.timesheet.tipology', 'Work time', required=False, help="Working time for this employee, tipically a contract tipology, like: full time, part time etc. (for manage hour and presence)"),
178
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: