Merge lp:~inddiana/sisb/sisb_reporte_pasivo_max_vacaciones into lp:sisb
- sisb_reporte_pasivo_max_vacaciones
- Merge into sisb
Proposed by
[SISB] Marvi Diaz
Status: | Merged |
---|---|
Merged at revision: | 982 |
Proposed branch: | lp:~inddiana/sisb/sisb_reporte_pasivo_max_vacaciones |
Merge into: | lp:sisb |
Diff against target: |
723 lines (+205/-196) 2 files modified
sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py (+188/-181) sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml (+17/-15) |
To merge this branch: | bzr merge lp:~inddiana/sisb/sisb_reporte_pasivo_max_vacaciones |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Industrias Diana | Pending | ||
Review via email: mp+334136@code.launchpad.net |
Commit message
Description of the change
[IMP] se modifico sisb_nomina/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py' |
2 | --- sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py 2016-11-23 11:59:11 +0000 |
3 | +++ sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py 2017-11-22 18:25:51 +0000 |
4 | @@ -1,9 +1,7 @@ |
5 | # -*- coding: utf-8 -*- |
6 | |
7 | -import time |
8 | from osv import fields, osv |
9 | from datetime import datetime |
10 | -import pooler |
11 | import calendar |
12 | import logging |
13 | import netsvc |
14 | @@ -12,9 +10,10 @@ |
15 | _name = "wizard.maximum.passive.holiday" |
16 | _logger = logging.getLogger('wizard.maximum.passive.holiday') |
17 | _columns = { |
18 | - 'type_report': fields.selection([('resumido', 'Resumido'),('detallado', 'Detallado')], 'Reporte', select=True, required=True), |
19 | + 'type_report': fields.selection([(False, ''),('detallado', 'Detallado'),('resumido', 'Resumido')], 'Reporte', select=True, required=True), |
20 | 'sede_id': fields.many2one('hr.sede', 'Sede'), |
21 | 'for_sede': fields.boolean(''), |
22 | + 'basic': fields.boolean('Incluir sueldo basico'), |
23 | 'mes': fields.many2one('hr.month', 'Mes', required=True), |
24 | } |
25 | _defaults = {'for_sede': True} |
26 | @@ -23,7 +22,7 @@ |
27 | smtp_client = self.pool.get('email.smtpclient') |
28 | smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False) |
29 | if not smtp_server: |
30 | - raise osv.except_osv(_('Acción Denegada!'), _('Debe configurar un servidor de correos para generar el reporte')) |
31 | + raise osv.except_osv(('Acción Denegada!'), ('Debe configurar un servidor de correos para generar el reporte')) |
32 | return True |
33 | |
34 | def _check_user_email_adress(self, cr, uid, ids, context=None): |
35 | @@ -35,8 +34,6 @@ |
36 | def _calcular_regla(self, cr, uid, rule, localdict, employee, context): |
37 | obj_rule = self.pool.get('hr.salary.rule') |
38 | amount, qty, rate = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context) |
39 | - previous_amount = rule.code in localdict and localdict[rule.code] or 0.0 |
40 | - tot_rule = amount * qty * rate / 100.0 |
41 | return { |
42 | 'salary_rule_id': rule.id, |
43 | 'name': rule.name, |
44 | @@ -128,7 +125,24 @@ |
45 | return float(salario[-1][-1]) |
46 | return '' |
47 | |
48 | - def get_payslip_lines(self, cr, uid, structure_brw, employee, list_concept_codes, fecha_creada): |
49 | + |
50 | + def remuneracion(self, cr, uid, employee_id, date_from): |
51 | + |
52 | + monto = 0.0 |
53 | + payslip = self.pool.get('hr.payslip') |
54 | + payslip_line = self.pool.get('hr.payslip.line') |
55 | + payslip_id = payslip.search(cr, uid, [('employee_id', '=', employee_id), ('type_process', '=', 'nomina'), ('state', '=', 'done'),('date_from','<=',date_from)], limit=1) |
56 | + if payslip_id: |
57 | + payslip_line_id = payslip_line.search(cr, uid, [('slip_id', '=', payslip_id), ('code', '=', 'SD')] ) |
58 | + if not payslip_line_id: |
59 | + payslip_id = payslip.search(cr, uid, [('employee_id', '=', employee_id), ('type_process', '=', 'nomina'), ('state', '=', 'done'), ('line_ids.code','=','SD')], limit=1) |
60 | + payslip_line_id = payslip_line.search(cr, uid, [('slip_id', '=', payslip_id), ('code', '=', 'SD')] ) |
61 | + payslip_line_brw = payslip_line.browse(cr, uid, payslip_line_id[0]) |
62 | + monto = payslip_line_brw.amount |
63 | + return monto |
64 | + |
65 | + |
66 | + def get_payslip_lines(self, cr, uid, structure_brw, employee, list_concept_codes, fecha_creada, context): |
67 | |
68 | obj_rule = self.pool.get('hr.salary.rule') |
69 | obj_line_liq = self.pool.get('hr.linea.liquidacion') |
70 | @@ -137,14 +151,14 @@ |
71 | fecha_liquidacion = datetime.strptime(fecha_creada,"%Y-%m-%d") |
72 | |
73 | period = self.pool.get('hr.period').search(cr, uid, [ |
74 | - ('date_start','<=', fecha_liquidacion), |
75 | - ('date_end','>=', fecha_liquidacion), |
76 | + ('date_start','<=', fecha_liquidacion),('date_end','>=', fecha_liquidacion), |
77 | ('type','=',employee.hr_payroll_id.hr_payment_calendar_id.type)]) |
78 | |
79 | period = self.pool.get('hr.period').browse(cr, uid, period[0]) |
80 | |
81 | #se obtienen los conceptos de la estructura salarial |
82 | rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, [structure_brw.id], employee, period.id, context=None) |
83 | + |
84 | sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] |
85 | |
86 | # vac_vencidas: Lista de tuplas. Cada tupla tiene la forma (vac_vencida, num_dias_adicionales) |
87 | @@ -154,34 +168,28 @@ |
88 | employee_hol_brw = False |
89 | |
90 | if employee_hol_ids: |
91 | + |
92 | employee_hol_brw = self.pool.get('hr.employee.holidays').browse(cr, uid, employee_hol_ids[0], context=None) |
93 | employee_hol_date = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d") |
94 | + |
95 | #Se cancelan 1 dia adicional por año a partir del 2º año |
96 | - dias_adicionales = employee_hol_date.year-start_rel_lab.year-1 if \ |
97 | - employee_hol_date.year-start_rel_lab.year > 1 else 0 |
98 | - dias_adicionales = dias_adicionales if dias_adicionales < 15 \ |
99 | - else 15 |
100 | - num_vac_vencidas = (fecha_liquidacion.year - employee_hol_date.year) if \ |
101 | - fecha_liquidacion.month >= employee_hol_date.month else \ |
102 | - (fecha_liquidacion.year - employee_hol_date.year - 1) |
103 | + dias_adicionales = employee_hol_date.year-start_rel_lab.year-1 if employee_hol_date.year-start_rel_lab.year > 1 else 0 |
104 | + dias_adicionales = dias_adicionales if dias_adicionales < 15 else 15 |
105 | + num_vac_vencidas = (fecha_liquidacion.year - employee_hol_date.year) if fecha_liquidacion.month >= employee_hol_date.month else (fecha_liquidacion.year - employee_hol_date.year - 1) |
106 | + |
107 | for x in range(num_vac_vencidas): |
108 | - vac_vencidas.append((employee_hol_date.year+x, dias_adicionales + \ |
109 | - 1 if dias_adicionales < 15 else 15)) |
110 | + dias_adicionales = dias_adicionales + 1 if dias_adicionales < 15 else 15 |
111 | + vac_vencidas.append((employee_hol_date.year + x, dias_adicionales)) |
112 | else: |
113 | new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day) |
114 | - num_vac_vencidas = (fecha_liquidacion.year - new_date.year) if \ |
115 | - fecha_liquidacion.month > new_date.month else \ |
116 | - (fecha_liquidacion.year - new_date.year - 1) |
117 | + num_vac_vencidas = (fecha_liquidacion.year - new_date.year) if fecha_liquidacion.month > new_date.month else (fecha_liquidacion.year - new_date.year - 1) |
118 | |
119 | for x in range(num_vac_vencidas): |
120 | dias_adicionales = x |
121 | - vac_vencidas.append((new_date.year + x, dias_adicionales \ |
122 | - if dias_adicionales < 15 else 15)) |
123 | + vac_vencidas.append((new_date.year + x, dias_adicionales if dias_adicionales < 15 else 15)) |
124 | |
125 | new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day) |
126 | - |
127 | - ultimo_anio_pagado = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d") \ |
128 | - if employee_hol_brw else new_date |
129 | + ultimo_anio_pagado = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d") if employee_hol_brw else new_date |
130 | |
131 | reg_vac_no_disf = obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee) |
132 | |
133 | @@ -216,7 +224,6 @@ |
134 | } |
135 | |
136 | localdict.update({'empleado': employee,}) |
137 | - param_fp_id = parameter_obj.search(cr, uid, [('type', '=', 'fecha_prest')]) |
138 | |
139 | parameters_dict = {} |
140 | for parameter in employee.hr_payroll_id.parameters_ids: |
141 | @@ -224,39 +231,41 @@ |
142 | |
143 | localdict.update({'parametros': parameters_dict,}) |
144 | localdict['periodo'] = period |
145 | - rules_dict = {} |
146 | - rules_dict['SUELDO'] = self._sueldo(employee.id, fecha_creada, cr, uid) |
147 | - localdict['concepto'] = rules_dict |
148 | - |
149 | + |
150 | categories_concept_dict={} |
151 | blacklist = {} |
152 | result_dict = {} |
153 | |
154 | for rule in obj_rule.browse(cr, uid, sorted_rule_ids, context=None): |
155 | + |
156 | key = rule.code |
157 | if key in list_concept_codes: |
158 | + rules_dict = {} |
159 | + |
160 | + if key == 'VND': |
161 | + rules_dict['SUELDO'] = self._sueldo(employee.id, fecha_creada, cr, uid) |
162 | + elif key == 'DAV190' or key == 'V190': |
163 | + rules_dict['SD'] = self.remuneracion(cr, uid, employee.id, fecha_liquidacion) |
164 | + |
165 | + localdict['concepto'] = rules_dict |
166 | localdict['result'] = None |
167 | localdict['result_qty'] = localdict['cantidad'] = 1.0 |
168 | - |
169 | + inicial_dict = self._calcular_regla(cr, uid, rule, localdict, employee, context=None) |
170 | + amount = inicial_dict['amount'] |
171 | + qty = localdict['cantidad'] = inicial_dict['quantity'] |
172 | + |
173 | if obj_rule.satisfy_condition(cr, uid, rule.id, localdict, context=None) and rule.id not in blacklist: |
174 | - inicial_dict = self._calcular_regla(cr, uid, rule, localdict, employee, context=None) |
175 | - amount = inicial_dict['amount'] |
176 | - qty = localdict['cantidad'] = inicial_dict['quantity'] |
177 | |
178 | - if rule.code == concept_vac_ven_brw.code or rule.code == \ |
179 | - concept_dias_vac_ven_brw.code: |
180 | - |
181 | - qty_concept = parameters_dict['vacaciones'] \ |
182 | - if rule.code == concept_vac_ven_brw.code else 15 |
183 | - |
184 | + if rule.code == concept_vac_ven_brw.code or rule.code == concept_dias_vac_ven_brw.code: |
185 | + |
186 | + qty_concept = parameters_dict['vacaciones'] if rule.code == concept_vac_ven_brw.code else 15 |
187 | desde = datetime.strptime(employee.start_rel_lab,"%Y-%m-%d") |
188 | - |
189 | - num_vac = len(vac_vencidas) if (desde.month == fecha_liquidacion.month and |
190 | - desde.day == fecha_liquidacion.day) else len(vac_vencidas) + 1 |
191 | + num_vac = len(vac_vencidas) if (desde.month == fecha_liquidacion.month and desde.day == fecha_liquidacion.day) else len(vac_vencidas) + 1 |
192 | |
193 | for c in range(num_vac): |
194 | - |
195 | + |
196 | if fecha_liquidacion.year > desde.year: |
197 | + |
198 | if fecha_liquidacion.month == desde.month: |
199 | if fecha_liquidacion.day < desde.day: |
200 | meses = 12 - desde.month + fecha_liquidacion.month - 1 |
201 | @@ -267,50 +276,44 @@ |
202 | meses = 12 |
203 | |
204 | elif fecha_liquidacion.month < desde.month: |
205 | + |
206 | if fecha_liquidacion.day < desde.day: |
207 | meses = 12 - desde.month + fecha_liquidacion.month - 1 |
208 | else: |
209 | meses = 12 - desde.month + fecha_liquidacion.month |
210 | else: |
211 | + |
212 | meses = fecha_liquidacion.month - desde.month |
213 | if fecha_liquidacion.day < desde.day: |
214 | meses = fecha_liquidacion.month - desde.month - 1 |
215 | else: |
216 | meses = fecha_liquidacion.month - desde.month |
217 | else: |
218 | + |
219 | meses = fecha_liquidacion.month - desde.month |
220 | + |
221 | if fecha_liquidacion.day < desde.day: |
222 | meses = fecha_liquidacion.month - desde.month - 1 |
223 | else: |
224 | meses = fecha_liquidacion.month - desde.month |
225 | |
226 | - qty = qty_concept if ((ultimo_anio_pagado.year+c < fecha_liquidacion.year-1) or \ |
227 | - (ultimo_anio_pagado.year+c == fecha_liquidacion.year-1 and \ |
228 | - fecha_liquidacion.month > ultimo_anio_pagado.month)) \ |
229 | - else float(qty_concept)/12*meses |
230 | + qty = qty_concept if ((ultimo_anio_pagado.year+c < fecha_liquidacion.year-1) or (ultimo_anio_pagado.year+c == fecha_liquidacion.year-1 and fecha_liquidacion.month > ultimo_anio_pagado.month)) else float(qty_concept)/12*meses |
231 | |
232 | key_ = key + '-' + str(ultimo_anio_pagado.year+c) |
233 | + |
234 | result_dict[key_] = inicial_dict.copy() |
235 | + |
236 | result_dict[key_].update({ |
237 | 'name': rule.name, |
238 | - 'periodo': 'Periodo ' + str(ultimo_anio_pagado.year+c) \ |
239 | - + '-' + str(ultimo_anio_pagado.year+1+c)\ |
240 | - if qty == qty_concept \ |
241 | - else 'Fraccion periodo ' + \ |
242 | - str(fecha_liquidacion.year) \ |
243 | - + '-' + str(fecha_liquidacion.year+1) if \ |
244 | - fecha_liquidacion.month > ultimo_anio_pagado.month else |
245 | - 'Fraccion periodo ' + \ |
246 | - str(fecha_liquidacion.year-1) \ |
247 | - + '-' + str(fecha_liquidacion.year), |
248 | - 'quantity': qty, |
249 | + 'periodo': 'Periodo ' + str(ultimo_anio_pagado.year+c) + '-' + str(ultimo_anio_pagado.year+1+c) if qty == qty_concept else 'Fraccion periodo ' + str(fecha_liquidacion.year) + '-' + str(fecha_liquidacion.year+1) if fecha_liquidacion.month > ultimo_anio_pagado.month else 'Fraccion periodo ' + str(fecha_liquidacion.year-1) + '-' + str(fecha_liquidacion.year), 'quantity': qty, |
250 | }) |
251 | rules_dict[key_] = amount * qty or 0.0 |
252 | localdict['concepto'] = rules_dict |
253 | |
254 | elif rule.code == concept_dias_adic_vac_ven_brw.code: |
255 | - |
256 | + |
257 | for c in range(len(vac_vencidas)): |
258 | + |
259 | qty = vac_vencidas[c][1] |
260 | key_ = key + '-' + str(ultimo_anio_pagado.year+c) |
261 | result_dict[key_] = inicial_dict.copy() |
262 | @@ -334,79 +337,56 @@ |
263 | localdict['concepto'] = rules_dict |
264 | |
265 | elif rule.code == concept_vac_no_disf_brw.code: |
266 | + |
267 | for _vac in reg_vac_no_disf: |
268 | + |
269 | anio = datetime.strptime(_vac.employee_holidays_add_id.corresp_to_end,"%Y-%m-%d").year |
270 | - tipo = _vac.name[_vac.name.find('/')+13:] |
271 | qty = reg_vac_no_disf[_vac] |
272 | - key_ = key + '-' + str(_vac.name[_vac.name.find('/')+2:]) |
273 | + key_ = key + '-' + str(_vac.name[_vac.name.find('/') + 2:]) |
274 | result_dict[key_] = inicial_dict.copy() |
275 | + |
276 | result_dict[key_].update({ |
277 | + |
278 | 'name': rule.name, |
279 | 'periodo': 'Periodo ' + str(anio-1) + ' - ' + str(anio), |
280 | 'quantity': qty, |
281 | }) |
282 | - rules_dict[key_] = amount*qty or 0.0 |
283 | + |
284 | + rules_dict[key_] = amount * qty or 0.0 |
285 | localdict['concepto'] = rules_dict |
286 | - |
287 | - else: |
288 | - result_dict[key] = inicial_dict.copy() |
289 | - |
290 | - if rule.code == concept_util_liq_brw.code: |
291 | - qty = parameters_dict['utilidades'] |
292 | - result_dict[key]['quantity'] = qty |
293 | - |
294 | - elif rule.code == concept_prest_liq_brw.code: |
295 | - qty = 5 |
296 | - result_dict[key]['quantity'] = qty |
297 | - |
298 | - elif rule.code == concept_util_frac_liq_brw.code: |
299 | - contract_date_start = datetime.strptime(employee.start_rel_lab,"%Y-%m-%d") |
300 | - fraccion_mes = fecha_liquidacion.day / \ |
301 | - calendar.monthrange(fecha_liquidacion.year,fecha_liquidacion.month)[1] |
302 | - if contract_date_start.year < fecha_liquidacion.year: |
303 | - qty = parameters_dict['utilidades']/12*(fecha_liquidacion.month \ |
304 | - - 1 + fraccion_mes) |
305 | - result_dict[key]['quantity'] = qty |
306 | - elif contract_date_start.year == fecha_liquidacion.year: |
307 | - qty = parameters_dict['utilidades']/12*(fecha_liquidacion.month - \ |
308 | - contract_date_start.month+fraccion_mes) |
309 | - result_dict[key]['quantity'] = qty |
310 | - |
311 | - rules_dict[key] = amount*qty or 0.0 |
312 | - localdict['concepto'] = rules_dict |
313 | |
314 | if rule.concept_id.category_id.code not in categories_concept_dict: |
315 | - categories_concept_dict[rule.concept_id.category_id.code] = \ |
316 | - amount or 0.0 |
317 | + |
318 | + categories_concept_dict[rule.concept_id.category_id.code] = amount or 0.0 |
319 | else: |
320 | - categories_concept_dict[rule.concept_id.category_id.code] = \ |
321 | - categories_concept_dict[rule.concept_id.category_id.code] \ |
322 | - + amount |
323 | + categories_concept_dict[rule.concept_id.category_id.code] = categories_concept_dict[rule.concept_id.category_id.code] + amount |
324 | + |
325 | localdict['categoria_concepto'] = categories_concept_dict |
326 | + |
327 | else: |
328 | - blacklist += [id for id, seq in |
329 | - self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, |
330 | - uid, [rule], context=context)] |
331 | + |
332 | + blacklist += [id for id, seq in self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, uid, [rule], context=context)] |
333 | |
334 | result = [value for code, value in result_dict.items()] |
335 | |
336 | return result |
337 | |
338 | - |
339 | + |
340 | def _send_report_by_email(self, cr, uid, parameters, context=None): |
341 | |
342 | subject = parameters['subject'] |
343 | message = parameters['message'] |
344 | data = parameters['data'] |
345 | + title = parameters['data']['titulo'] |
346 | file_name = parameters['file_name'] |
347 | fecha_creada = parameters['data']['fecha_creada'] |
348 | - |
349 | + type_report = parameters['data']['type_report'] |
350 | + basic = parameters['data']['sueldo_basico'] |
351 | + |
352 | smtp_client = self.pool.get('email.smtpclient') |
353 | smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False) |
354 | |
355 | parameter_obj = self.pool.get('hr.parameters') |
356 | - payroll_obj = self.pool.get('hr.payroll') |
357 | - payroll_structure_obj = self.pool.get('hr.payroll.structure') |
358 | obj_line_liq = self.pool.get('hr.linea.liquidacion') |
359 | |
360 | param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')]) |
361 | @@ -416,71 +396,102 @@ |
362 | |
363 | if data['for_sede']: |
364 | employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo']),('start_rel_lab','<=', fecha_creada)]) |
365 | - title = "Todas las sedes" |
366 | else: |
367 | - brw_sede = self.pool.get('hr.sede').browse(cr, uid, data['sede']) |
368 | employee_ids = self.pool.get('hr.employee').search(cr, uid, [('hr_sede_id','=',data['sede']),('state','in',['vacaciones','activo','reposo']),('start_rel_lab','<=', fecha_creada)]) |
369 | - title = brw_sede.name |
370 | - |
371 | - list_val = [] |
372 | - value = [] |
373 | - |
374 | + |
375 | + list_concept_codes = self.query_concept(cr) |
376 | dicc_department = {} |
377 | |
378 | - for i in employee_ids: |
379 | - employee = self.pool.get('hr.employee').browse(cr, uid, [i]) |
380 | - if employee[0].start_rel_lab <= fecha_creada: |
381 | - dicc_department[employee[0].department_id.id] = [] |
382 | - |
383 | - |
384 | - for i in employee_ids: |
385 | - employee = self.pool.get('hr.employee').browse(cr, uid, [i]) |
386 | - if employee[0].start_rel_lab <= fecha_creada: |
387 | - struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id] |
388 | - lines = self.get_payslip_lines(cr, uid, struct_brw[0], employee[0], list_concept_codes, fecha_creada) |
389 | - val= [] |
390 | - l=[] |
391 | + if employee_ids: |
392 | + c = 0 |
393 | + for i in employee_ids: |
394 | + c = c + 1 |
395 | + #~ print str(c) + " de " + str(len(employee_ids)) |
396 | + val= [] |
397 | + l=[] |
398 | + |
399 | + employee = self.pool.get('hr.employee').browse(cr, uid, [i]) |
400 | + |
401 | + if employee[0].start_rel_lab <= fecha_creada: |
402 | + |
403 | + struct_list = parameter_obj.browse(cr, uid, param_struct_id)[0].estruc_liq_ids |
404 | + struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id] |
405 | + if struct_brw: |
406 | + obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0]) |
407 | + else: |
408 | + raise osv.except_osv(('ERROR!'), ('La %s no esta incluida en los parametros de la estructura para liquidacion'%(employee[0].hr_payroll_id.name))) |
409 | + |
410 | + struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id] |
411 | + lines = self.get_payslip_lines(cr, uid, struct_brw[0], employee[0], list_concept_codes, fecha_creada, context) |
412 | + |
413 | [l.append(key) for key in lines if key not in l] |
414 | + |
415 | + sd = self.remuneracion(cr, uid, employee[0].id, fecha_creada) |
416 | + |
417 | for line in l: |
418 | if line['amount'] > 0.0 and line['quantity'] > 0.0: |
419 | amount = line['amount'] * line['quantity'] |
420 | - val.append({'n':line['name'] + " " + line['periodo'], 'a':amount, 'q':line['quantity'], 'p':line['periodo']}) |
421 | + basico = sd * line['quantity'] |
422 | + val.append({'sd':basico,'n':line['name'] + " " + line['periodo'], 'a':amount, 'q':line['quantity'], 'p':line['periodo']}) |
423 | + |
424 | if val: |
425 | + |
426 | + if not employee[0].department_id.id in dicc_department: |
427 | + dicc_department[employee[0].department_id.id]=[] |
428 | dicc_department[employee[0].department_id.id].append((employee[0].cod_number, employee[0].name, sorted(val))) |
429 | - |
430 | + |
431 | total_departamento={} |
432 | + total_departamento_basico={} |
433 | + |
434 | for c in dicc_department: |
435 | total_departamento[c] = 0.0 |
436 | + total_departamento_basico[c] = 0.0 |
437 | |
438 | for c in dicc_department: |
439 | amount = 0.0 |
440 | + basico = 0.0 |
441 | for i in dicc_department[c]: |
442 | + |
443 | for x in i[2]: |
444 | amount += x['a'] |
445 | + basico += x['sd'] |
446 | + |
447 | total_departamento[c] = amount |
448 | + total_departamento_basico[c] = basico |
449 | |
450 | total_resumen = [] |
451 | + total_resumen_basico = [] |
452 | for c in total_departamento: |
453 | total_resumen.append(total_departamento[c]) |
454 | + total_resumen_basico.append(total_departamento_basico[c]) |
455 | + |
456 | total_resumen = sum(total_resumen) |
457 | + total_resumen_basico = sum(total_resumen_basico) |
458 | |
459 | total_empleado = {} |
460 | + total_empleado_basico = {} |
461 | for c in dicc_department: |
462 | for i in dicc_department[c]: |
463 | total_empleado[i[0]] = 0.0 |
464 | + total_empleado_basico[i[0]] = 0.0 |
465 | |
466 | for c in dicc_department: |
467 | for i in dicc_department[c]: |
468 | for x in i[2]: |
469 | total_empleado[i[0]] += x['a'] |
470 | + total_empleado_basico[i[0]] += x['sd'] |
471 | |
472 | new = datetime.strptime(fecha_creada, '%Y-%m-%d') |
473 | - |
474 | + |
475 | data['form'] = dicc_department |
476 | data['total_resumen'] = total_resumen |
477 | + data['total_resumen_basico'] = total_resumen_basico |
478 | data['total_empleado'] = total_empleado |
479 | + data['total_empleado_basico'] = total_empleado_basico |
480 | data['sede'] = title |
481 | - data['al'] = str(new.strftime('%d-%m-%Y')) |
482 | + data['sueldo_basico'] = basic |
483 | + data['type_report'] = type_report |
484 | + data['al'] = str(new.strftime('%d/%m/%Y')) |
485 | |
486 | report = self._create_report(cr, uid, data['ids'], data['model'], file_name, data) |
487 | attachments = report[0] and [report[1]] or [] |
488 | @@ -502,17 +513,13 @@ |
489 | 'from': uid, |
490 | 'attachments': attachments |
491 | } |
492 | - |
493 | smtp_client.send_email(cr, uid, smtp_server_id, email['to'], email['name'], email['body'], email['attachments']) |
494 | finally: |
495 | cron = self.pool.get('ir.cron') |
496 | accion_planificada = cron.search(cr, uid, [('name','=', subject)]) |
497 | cron.unlink(cr, uid, accion_planificada) |
498 | - |
499 | + |
500 | def _send_request(self, cr, uid, ids, subject, message, context=None): |
501 | - """ |
502 | - Metodo que envia una notificacion interna de OpenERP |
503 | - """ |
504 | notificaciones = { |
505 | 'name': (subject), |
506 | 'act_to': uid, |
507 | @@ -535,40 +542,36 @@ |
508 | fp.write(result); |
509 | fp.close(); |
510 | except Exception,e: |
511 | - print 'Exception in create report:',e |
512 | + #~ print 'Exception in create report:',e |
513 | return (False, str(e)) |
514 | return (True, ret_file_name) |
515 | |
516 | - def getObtenerDia(self, mes, dia="primer"): |
517 | - meses = {'ENERO':'01', 'FEBRERO':'02', 'MARZO':'03', 'ABRIL':'04', 'MAYO':'05', 'JUNIO':'06', |
518 | - 'JULIO':'07', 'AGOSTO':'08', 'SEPTIEMBRE':'09', 'OCTUBRE':'10', 'NOVIEMBRE':'11', 'DICIEMBRE':'12'} |
519 | - mes = mes.split(" ") |
520 | - anio = mes[1] |
521 | - mes = meses[mes[0].upper()] |
522 | - calendario = calendar.monthrange(int(anio),int(mes)) |
523 | - if dia == "ultimo": |
524 | - fecha_creada = str(anio)+"-"+ str(mes)+ "-" + str(calendario[1]) |
525 | - return fecha_creada |
526 | - return str(anio)+"-"+ str(mes)+ "-" + "-01" |
527 | + def getObtenerDia(self, mes, anio): |
528 | + calendario = calendar.monthrange(anio, mes) |
529 | + return '%s-%s-%s'%(anio, '0'+ str(mes) if len(str(mes)) < 2 else mes, calendario[1]) |
530 | |
531 | def print_report_buton(self, cr, uid, ids, context=None): |
532 | |
533 | - brw = self.browse(cr, uid, ids)[0] |
534 | - mes = brw.mes.name |
535 | - month_id = brw.mes.id |
536 | - fecha_creada = self.getObtenerDia(mes, 'ultimo') |
537 | - for_sede = brw.for_sede |
538 | - type_report = brw.type_report |
539 | - |
540 | + if context is None:context = {} |
541 | + context['procesar'] = True |
542 | + |
543 | self._check_email_server(cr, uid, ids, context) |
544 | email = self._check_user_email_adress(cr, uid, ids, context) |
545 | |
546 | + if not email: |
547 | + raise osv.except_osv(('ERROR!'), ('No hay un correo electronico asociado al usuario.')) |
548 | + |
549 | parameter_obj = self.pool.get('hr.parameters') |
550 | payroll_obj = self.pool.get('hr.payroll') |
551 | payroll_structure_obj = self.pool.get('hr.payroll.structure') |
552 | - obj_line_liq = self.pool.get('hr.linea.liquidacion') |
553 | obj_process = self.pool.get('hr.process') |
554 | obj_period = self.pool.get('hr.period') |
555 | + obj_line_liq = self.pool.get('hr.linea.liquidacion') |
556 | + |
557 | + brw = self.browse(cr, uid, ids)[0] |
558 | + mes_brw = brw.mes |
559 | + sede_id = brw.sede_id |
560 | + fecha_creada = self.getObtenerDia(mes_brw.month_year, mes_brw.hr_year_id.year) |
561 | |
562 | param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')]) |
563 | if not param_struct_id: |
564 | @@ -611,7 +614,8 @@ |
565 | la pestaña Configuracion -> Configuraciones de nomina -> \ |
566 | Parametros de nomina y registrar un parametro de tipo \ |
567 | Conceptos Vacaciones no disfrutadas')) |
568 | - |
569 | + |
570 | + |
571 | nomina_ids = payroll_obj.search(cr, uid, []) |
572 | nomina_browse = payroll_obj.browse(cr, uid, nomina_ids) |
573 | |
574 | @@ -621,6 +625,7 @@ |
575 | raise osv.except_osv(('ERROR!'), ('No hay una Estructuras de Liquidaciones para la nomina %s')%(i.name)) |
576 | |
577 | for i in nomina_browse: |
578 | + |
579 | param_concept_salary_id = parameter_obj.search(cr, uid, [('type', '=', 'concepto_sueldo'), |
580 | ('payroll_id', '=', i.id)]) |
581 | |
582 | @@ -635,54 +640,58 @@ |
583 | Parametros de nomina y registrar un parametro de tipo \ |
584 | Concepto Salario')%(i.name)) |
585 | |
586 | - fecha_liquidacion = datetime.strptime(fecha_creada,"%Y-%m-%d") |
587 | - |
588 | - period_id = obj_period.search(cr, uid, [('hr_month_id', '=', month_id), ('state', '=', 'close')]) |
589 | + period_id = obj_period.search(cr, uid, [('hr_month_id', '=', mes_brw.id), ('state', '=', 'close')]) |
590 | |
591 | if not period_id: |
592 | - raise osv.except_osv(('ERROR!'), ('No hay un periodo asociado a la fecha %s para la %s')%(today, i.name)) |
593 | - |
594 | + raise osv.except_osv(('ERROR!'), ('No hay un periodo asociado al mes seleccionado. para la %s')%(i.name)) |
595 | + |
596 | otros_procesos_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), |
597 | - ('type', 'not in', ('prestaciones','bono_alimentacion','guarderias')), |
598 | - ('hr_period_ids', 'in', period_id), ('state', '=', 'done')]) |
599 | + ('type', 'not in', ('prestaciones','bono_alimentacion','guarderias')), |
600 | + ('hr_period_ids', 'in', period_id), ('state', '=', 'done')]) |
601 | |
602 | if otros_procesos_id: |
603 | - |
604 | - proceso_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), ('type', '=', 'prestaciones'), |
605 | - ('hr_period_ids', 'in', period_id), ('state', '=', 'done')]) |
606 | + |
607 | + proceso_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), |
608 | + ('type', '=', 'prestaciones'), |
609 | + ('hr_period_ids', 'in', period_id), |
610 | + ('state', '=', 'done')]) |
611 | |
612 | if not proceso_id: |
613 | - raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no \ |
614 | - posee proceso de Prestaciones Sociales aprobado'%(i.name, mes))) |
615 | + raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no posee proceso de Prestaciones Sociales aprobado'%(i.name, mes_brw.name))) |
616 | |
617 | - proceso_nomina_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), ('type', '=', 'nomina'), |
618 | - ('hr_period_ids', 'in', period_id), ('state', '=', 'done')]) |
619 | + proceso_nomina_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), |
620 | + ('type', '=', 'nomina'), |
621 | + ('hr_period_ids', 'in', period_id), |
622 | + ('state', '=', 'done')]) |
623 | |
624 | if not proceso_nomina_id: |
625 | - raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no \ |
626 | - posee proceso de Nomina aprobado'%(i.name, mes))) |
627 | + raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no posee proceso de Nomina aprobado'%(i.name, mes_brw.name))) |
628 | |
629 | - if for_sede: |
630 | + if brw.for_sede: |
631 | employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo'])]) |
632 | - title = "TODAS LAS SEDES" |
633 | else: |
634 | - employee_ids = self.pool.get('hr.employee').search(cr, uid, [('hr_sede_id','=',brw.sede_id.id),('state','in',['vacaciones','activo','reposo'])]) |
635 | - title = brw.sede_id.name |
636 | - |
637 | + employee_ids = self.pool.get('hr.employee').search(cr, uid, [('hr_sede_id','=',sede_id.id),('state','in',['vacaciones','activo','reposo'])]) |
638 | + |
639 | + title = sede_id.name if not brw.for_sede else 'TODAS LAS SEDES' |
640 | |
641 | if employee_ids: |
642 | + |
643 | for i in employee_ids: |
644 | + |
645 | employee = self.pool.get('hr.employee').browse(cr, uid, [i]) |
646 | if employee[0].start_rel_lab <= fecha_creada: |
647 | struct_list = parameter_obj.browse(cr, uid, param_struct_id)[0].estruc_liq_ids |
648 | struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id] |
649 | if struct_brw: |
650 | - reg_vac_no_disf = obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0]) |
651 | + obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0]) |
652 | else: |
653 | raise osv.except_osv(('ERROR!'), ('La %s no esta incluida en los parametros de la estructura para liquidacion'%(employee[0].hr_payroll_id.name))) |
654 | + |
655 | data = {} |
656 | data['form'] = {} |
657 | data['ids'] = [1] |
658 | + data['titulo'] = title |
659 | + data['sueldo_basico'] = brw.basic |
660 | data['model'] = "wizard.maximum.passive.holiday" |
661 | data['sede'] = brw.sede_id.id |
662 | data['type_report'] = brw.type_report |
663 | @@ -715,11 +724,9 @@ |
664 | self.pool.get('ir.cron').create(cr, uid, vals, context) |
665 | self._send_request(cr, uid, ids, subject, request_message, context) |
666 | return {'type':'ir.actions.act_window_close'} |
667 | - else: |
668 | - raise osv.except_osv(('Accion Denegada!'), ('No existen datos disponibles para generar el reporte')) |
669 | - else: |
670 | - raise osv.except_osv(('Accion Denegada!'), ('%s no cuenta con trabajadores para poder generar este reporte')%(title)) |
671 | - |
672 | - |
673 | + |
674 | + raise osv.except_osv(('Accion Denegada!'), ('No existen datos disponibles para generar el reporte')) |
675 | + |
676 | + raise osv.except_osv(('Accion Denegada!'), ('%s no cuenta con trabajadores para poder generar este reporte')%(title)) |
677 | |
678 | wizard_maximum_passive_holiday() |
679 | |
680 | === modified file 'sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml' |
681 | --- sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml 2016-11-22 14:39:04 +0000 |
682 | +++ sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml 2017-11-22 18:25:51 +0000 |
683 | @@ -7,23 +7,25 @@ |
684 | <field name="type">form</field> |
685 | <field name="arch" type="xml"> |
686 | <form string="maximum passive holiday"> |
687 | - <group col="4" colspan="4" > |
688 | - |
689 | - </group> |
690 | - <group colspan="4" col="8"> |
691 | - <field name="type_report" colspan="1"/> |
692 | - <field name="sede_id" colspan="2" attrs= "{'readonly':[('for_sede','=','True')], 'required':[('for_sede','!=','True')] }"/> |
693 | - <field name="for_sede" colspan="2" /> |
694 | - |
695 | - <newline/> |
696 | - |
697 | - <field name="mes" colspan="2" /> |
698 | - </group> |
699 | - <newline/> |
700 | - <newline/> |
701 | + |
702 | + <group colspan="2" col="6"> |
703 | + <field name="type_report"/> |
704 | + <field name="sede_id" attrs= "{'readonly':[('for_sede','=','True')], 'required':[('for_sede','!=','True')] }"/> |
705 | + <field name="for_sede" /> |
706 | + <field name="mes" /> |
707 | + <field name="basic" /> |
708 | + </group> |
709 | + |
710 | + |
711 | + <newline/> |
712 | + |
713 | <group> |
714 | - <button name="print_report_buton" string="Print Report" type="object" icon="mail- " confirm="Antes de iniciar la generacion del reporte se validaran ciertos datos. Al finalizar se enviara a su direccion de correo" /> |
715 | + |
716 | + <button name="print_report_buton" string="Generar Reporte" type="object" icon="mail- " confirm="Antes de iniciar la generacion del reporte se validaran ciertos datos. Al finalizar se enviara a su direccion de correo" /> |
717 | + |
718 | </group> |
719 | + |
720 | + |
721 | </form> |
722 | </field> |
723 | </record> |