2
# -*- coding: utf-8 -*--
4
from osv import fields, osv
7
class horas_extras_parametros_turnos(osv.osv):
9
_name = 'horas.extras.parametros.turnos'
10
_description = 'parametros de horas extras'
12
'name': fields.char('Nombre', size=60),
13
'concept_id': fields.many2one('hr.concept', 'Concepto', required=True),
14
'feriado_id': fields.many2one('hr.concept', 'Concepto feriado'),
15
'hr_hours_per_day_id': fields.many2one('hr.hours.per.day', 'Turno', required=True),
16
'hour_start': fields.time('hora inicial', required=True),
17
'hour_end': fields.time('hora final', required=True),
18
'day_start': fields.selection([(1, 'Lunes'),(2, 'Martes'),
19
(3, 'Miercoles'),(4, 'Jueves'),(5, 'Viernes'),(6, 'Sabado'),(7, 'Domingo')],
20
'Dia desde', required=True),
21
'day_end': fields.selection([(1, 'Lunes'),(2, 'Martes'),
22
(3, 'Miercoles'),(4, 'Jueves'),(5, 'Viernes'),(6, 'Sabado'),(7, 'Domingo')],
23
'Dia hasta', required=True),
26
def diff(self, hr, ha):
28
r1 = datetime.datetime.strptime(hr, '%H:%M:%S')
29
r2 = datetime.datetime.strptime(ha, '%H:%M:%S')
32
time = float(ab.seconds / float(criterio))
36
def search_parameters_overtime(self,cr, uid, hr_hours_per_day_id, dia, hour_start, hour_end, feriado=None):
38
select id FROM horas_extras_parametros_turnos
39
WHERE %s BETWEEN day_start and day_end
40
and (hour_start >= '%s' and hour_end <= '%s' OR
41
(hour_start <= '%s' and hour_end >= '%s') OR
42
(hour_start <= '%s' and hour_end >= '%s'))
43
and hr_hours_per_day_id = %s
44
"""%(dia, hour_start, hour_end, hour_start, hour_start, hour_end, hour_end, hr_hours_per_day_id)
46
turnos_ids = cr.fetchall()
47
turnos_ids = [t for i in turnos_ids for t in i]
48
parametro_read = ['hour_start', 'hour_end', 'concept_id']
50
parametro_read.append('feriado_id')
51
turnos_read = self.read(cr, uid, turnos_ids, parametro_read)
54
def conditionals(self, e1, e2, p1, p2, c, val):
59
if e1 >= p1 and e1 <= p2 and e2 > p1 and e2 > p2:
61
elif e1 <= p1 and e1 <= p2 and e2 > p1 and e2 > p2:
63
elif e1 <= p1 and e1 <= p2 and e2 > p1 and e2 < p2:
69
val[c] += diff(p1, e2)
71
if e1 >= p1 and e2 <= p2:
72
val[c] += diff(e2, e1)
73
elif e1 <= p1 and e2 <= p2:
74
val[c] += diff(p1, e2)
76
val[c] += diff(e1, p2)
79
def calculte_overtime(self, cr, uid, hr_hours_per_day_id, dia, hour_start, hour_end, feriado=None):
80
parameters = self.search_parameters_overtime(cr, uid, hr_hours_per_day_id, dia, hour_start, hour_end, feriado=feriado)
85
if not i['feriado_id']:
86
val[i['concept_id'][0]] = 0.00
88
val[i['feriado_id'][0]] = 0.00
90
val[i['concept_id'][0]] = 0.00
96
c = p['feriado_id'][0] if feriado and p['feriado_id'] else p['concept_id'][0]
97
#Turno normal, 1er grupo, 2do grupo, 3er grupo, 4to grupo
98
val = self.conditionals(e1, e2, p1, p2, c, val)
101
def validate_parameters_day_hour(self, cr, day_start,day_end, hour_start,hour_end, hr_hours_per_day_id):
103
select id FROM horas_extras_parametros_turnos
104
WHERE (day_start >= %s and day_end <= %s
105
or (day_start <= %s and day_end >= %s)
106
or (day_start <= %s and day_end >= %s))
107
and (hour_start >= '%s' and hour_end <= '%s' OR
108
(hour_start <= '%s' and hour_end >= '%s') OR
109
(hour_start <= '%s' and hour_end >= '%s'))
110
and hr_hours_per_day_id = %s
111
"""%(day_start, day_end, day_start,day_start, day_end, day_end, hour_start, hour_end, hour_start, hour_start, hour_end, hour_end, hr_hours_per_day_id)
113
query = cr.fetchall()
114
query = [t for i in query for t in i]
117
def validate_ranges_hours(self, hour_start,hour_end):
118
if datetime.datetime.strptime(hour_end, '%H:%M:%S') < datetime.datetime.strptime(hour_start, '%H:%M:%S'):
119
raise osv.except_osv('ERROR', "La hora final es debe ser mayor a la inicial")
123
def create(self, cr, uid, values, context=None):
124
day_start = values['day_start']
125
day_end = values['day_end']
126
hour_start = values['hour_start']
127
hour_end = values['hour_end']
128
hr_hours_per_day_id = values['hr_hours_per_day_id']
129
self.validate_ranges_hours(hour_start,hour_end)
130
validar = self.validate_parameters_day_hour(cr, day_start, day_end, hour_start,hour_end, hr_hours_per_day_id)
132
raise osv.except_osv('ERROR', "No se puede crear un nuevo parametro si los rangos de horas y fechas coinciden con las anteriores")
134
super(horas_extras_parametros_turnos, self).create(cr, uid, values, context=None)
137
#~ def write(self, cr, uid, ids, values, context=None):
138
#~ parameters_brw = self.browse(cr, uid, ids[0])
139
#~ day_start = values['day_start']
140
#~ day_end = values['day_end']
141
#~ hour_start = values['hour_start']
142
#~ hour_end = values['hour_end']
143
#~ hr_hours_per_day_id = parameters_brw.hr_hours_per_day_id.id
144
#~ self.validate_ranges_hours(hour_start,hour_end)
145
#~ validar = self.validate_parameters_day_hour(cr, day_start, day_end, hour_start,hour_end, hr_hours_per_day_id)
147
#~ raise osv.except_osv('ERROR', "No se puede actualizar los parametros si los rangos de horas y fechas coinciden con las anteriores")
149
#~ super(horas_extras_parametros_turnos, self).create(cr, uid, values, context=None)
155
horas_extras_parametros_turnos()
157
class hr_hours_per_day(osv.osv):
159
_inherit = 'hr.hours.per.day'
160
_description = 'Horario'
163
'reglas_horas_extras_ids': fields.one2many('horas.extras.parametros.turnos', 'hr_hours_per_day_id', 'Reglas de sobretiempo del turno'),