~inddiana/sisb/sisb_extratos_bancarios_campo_transpasos

« back to all changes in this revision

Viewing changes to sisb_horas_extras/wizard/calculo_horas_extras.py


[IMP] Se agrega modulo para la carga de horas extras.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import datetime
 
4
 
 
5
class sobretiempo_for_turnos():
 
6
        
 
7
    def __init__(self, turno_actual, turno_post, hora_entrada, hora_salida, dias):
 
8
        convert = self.convert_datetime 
 
9
        self.turno_entrada_act = convert(turno_actual[0],tipo='time')
 
10
        self.turno_salida_act = convert(turno_actual[1],tipo='time')
 
11
        self.turno_entrada_post = convert(turno_post[0],tipo='time')
 
12
        self.turno_salida_post = convert(turno_post[1],tipo='time')
 
13
        self.hora_entrada = convert(hora_entrada,tipo='time')
 
14
        self.hora_salida = convert(hora_salida,tipo='time')
 
15
        self.dias = dias
 
16
    
 
17
    def convert_datetime(self, value_date, tipo=None, format_inp=None):
 
18
        d = {}
 
19
        format_inp = {'time':"%H:%M:%S", 
 
20
                      'date':"%Y-%m-%d",
 
21
                       'object':"%Y-%m-%d %H:%M:%S",
 
22
                       None:"%Y-%m-%d %H:%M:%S"}
 
23
        if tipo in format_inp:
 
24
           format_inp = format_inp[tipo]
 
25
        else:
 
26
            format_inp = "%Y-%m-%d %H:%M:%S"
 
27
           
 
28
        value_date = datetime.datetime.strptime(value_date, format_inp)
 
29
        d = {'date':value_date.strftime("%Y-%m-%d"),
 
30
            'time':value_date.strftime("%H:%M:%S"), 
 
31
            'object': value_date}
 
32
        if  tipo:
 
33
            return d[tipo] 
 
34
        return d
 
35
    
 
36
    def subtract_hours(self,  hr, ha):
 
37
        criterio = 3600
 
38
        r1 =  datetime.datetime.strptime(hr, '%H:%M:%S')
 
39
        r2 =  datetime.datetime.strptime(ha, '%H:%M:%S')
 
40
        dif = r2 - r1 
 
41
        ab = abs(dif)
 
42
        time =  float(ab.seconds / float(criterio))
 
43
        time = round(time, 2)
 
44
        return time 
 
45
    
 
46
    def laborable(self, start, end):
 
47
        param = '00:00:00'
 
48
        if start == param and end == param:
 
49
           return False
 
50
        return True
 
51
    
 
52
    def validar_turno(self, turno):
 
53
        tipo = None
 
54
        if turno[1] > turno[0]:
 
55
           tipo = 'diurno'
 
56
        else:
 
57
            tipo = 'nocturno'
 
58
        return tipo
 
59
    
 
60
    def sobretiempo(self, start, end, entrada, dia=None):
 
61
        diff = self.subtract_hours
 
62
        tipo = {'diurno':0.00,'nocturno':0.00}
 
63
        if not dia:
 
64
           dia = self.dias
 
65
        diurno_start = '05:00:00'
 
66
        diurno_end = '18:59:59'
 
67
        nocturno_start = '19:00:00'
 
68
        nocturno_end = '23:59:59'
 
69
        inicio = '00:00:00'
 
70
        if dia==1:
 
71
           if start >= nocturno_start and start <= nocturno_end and end >= '00:00:00' and end <= diurno_start: #sobretiempo noche-noche de un dia a otro
 
72
              tipo['nocturno'] += diff(nocturno_end, start)
 
73
              tipo['nocturno'] += diff(inicio, end)
 
74
           
 
75
           elif start >= nocturno_start and start <= nocturno_end and end >= diurno_start and (end <= entrada or end >= entrada):#sobretiempo noche-dia de un dia a otro
 
76
              tipo['nocturno'] += diff(nocturno_end, start)
 
77
              tipo['nocturno'] += diff(inicio, diurno_start)
 
78
              if entrada > diurno_start and entrada <= diurno_end and  end >= entrada:
 
79
                 tipo['diurno'] += diff(diurno_start, entrada)
 
80
              
 
81
              elif end >= nocturno_start and end <= nocturno_end and  end >= entrada:
 
82
                  tipo['diurno'] += diff(diurno_start, diurno_end)
 
83
                  tipo['nocturno'] += diff(nocturno_start, end)
 
84
           
 
85
           
 
86
           elif start >= diurno_start and start <= diurno_end and end >= diurno_start and (end <= entrada or end >= entrada):#sobretiempo dia-noche-dia  de un dia a otro pasando su hora de entrada
 
87
              tipo['diurno'] += diff(diurno_end, start)
 
88
              tipo['nocturno'] += diff(nocturno_end, nocturno_start)
 
89
              tipo['nocturno'] += diff(diurno_start, inicio)
 
90
              if entrada > diurno_start and entrada <= diurno_end and  end >= entrada:
 
91
                 tipo['diurno'] += diff(diurno_start, entrada)
 
92
              
 
93
              elif end >= nocturno_start and end <= nocturno_end and  end >= entrada:
 
94
                   tipo['diurno'] += diff(diurno_start, diurno_end)
 
95
                   tipo['nocturno'] += diff(nocturno_start, end)
 
96
              
 
97
              elif end >= diurno_start and end <= diurno_end and  end >= entrada:
 
98
                   tipo['diurno'] += diff(diurno_start, end)
 
99
           
 
100
           
 
101
           elif start >= diurno_start and start <= diurno_end and end <= diurno_start:#sobretiempo dia-noche  de un dia a otro 
 
102
              tipo['diurno'] += diff(diurno_end, start)
 
103
              tipo['nocturno'] += diff(nocturno_end, nocturno_start)
 
104
              tipo['nocturno'] += diff('00:00:00', end)
 
105
        else:
 
106
             if start >= diurno_start and start <= diurno_end and end >= nocturno_start and end <= nocturno_end:
 
107
                tipo['diurno'] += diff(diurno_end, start) 
 
108
                tipo['nocturno'] += diff(nocturno_start, end)
 
109
             elif start >= diurno_start and start <= diurno_end and end >= diurno_start and end <= diurno_end:
 
110
                  tipo['diurno'] += diff(start,end) 
 
111
             elif start >= nocturno_start and start <= nocturno_end and end >= nocturno_start and end <= nocturno_end:
 
112
                tipo['nocturno'] += diff(start,end) 
 
113
        return tipo
 
114
        
 
115
    def intervalo_1(self, start, end, turno_1, turno_2):
 
116
        en_turno = {'hora_desde':False, 'hora_hasta':False}
 
117
        dia = self.dias
 
118
        if dia == 0:
 
119
                   if  start >= turno_1[0] and  start <= turno_1[1]:
 
120
                           en_turno['hora_desde'] = True
 
121
                   if  end >= turno_1[0] and  end <= turno_1[1]:
 
122
                           en_turno['hora_hasta'] = True
 
123
        elif dia == 1:
 
124
             if turno_1[1] > turno_1[0]:
 
125
                 if start >= turno_1[0] and  start <= turno_1[1]:
 
126
                    en_turno['hora_desde'] = True
 
127
             else:
 
128
                   if start >= turno_1[1] and  start <= turno_1[0]:
 
129
                    en_turno['hora_desde'] = True  
 
130
                    
 
131
             if turno_2[1] > turno_2[0]:    
 
132
                 if end >= turno_2[0] and  end <= turno_2[1]:
 
133
                    en_turno['hora_hasta'] = True 
 
134
             else:    
 
135
                 if end >= turno_2[1] and  end <= turno_2[0]:
 
136
                    en_turno['hora_hasta'] = True 
 
137
            
 
138
        return en_turno
 
139
    
 
140
    
 
141
    def calcular(self):
 
142
        diff = self.subtract_hours
 
143
        tipo = {'diurno':0.00,'nocturno':0.00}
 
144
        sobretiempo = self.sobretiempo
 
145
        laborable_act = self.laborable(self.turno_entrada_act, self.turno_salida_act)
 
146
        laborable_post= self.laborable(self.turno_entrada_post, self.turno_salida_post)
 
147
        tipo_turno = self.validar_turno([self.turno_entrada_post, self.turno_salida_act])
 
148
        hora_entrada = self.hora_entrada
 
149
        hora_salida = self.hora_salida 
 
150
        dia = self.dias
 
151
        turno_actual = [self.turno_entrada_act, self.turno_salida_act]
 
152
        turno_posterior = [self.turno_entrada_post, self.turno_salida_post]
 
153
        validar_intervalos = self.intervalo_1(hora_entrada, hora_salida, turno_actual, turno_posterior)  
 
154
        en_intervalo_desde = validar_intervalos['hora_desde']
 
155
        en_intervalo_hasta = validar_intervalos['hora_hasta']
 
156
        intervalos = (en_intervalo_desde and en_intervalo_hasta)
 
157
        if laborable_act and laborable_post:
 
158
            if not intervalos:
 
159
                if en_intervalo_desde and not en_intervalo_hasta:
 
160
                   tipo = sobretiempo(self.turno_salida_act, hora_salida, self.turno_entrada_post) 
 
161
                elif not en_intervalo_desde and en_intervalo_hasta:
 
162
                   tipo = sobretiempo(hora_entrada, self.turno_entrada_post, self.turno_entrada_post)
 
163
                else:
 
164
                    tipo = sobretiempo(hora_entrada, hora_salida, self.turno_entrada_post)
 
165
                    
 
166
            else:
 
167
                tipo = sobretiempo(hora_entrada, hora_salida, self.turno_entrada_post)
 
168
        else:
 
169
            tipo = sobretiempo(hora_entrada, hora_salida, self.turno_entrada_post)
 
170
        return tipo
 
171
    
 
172