Merge lp:~inddiana/sisb/sisb_reporte_pasivo_max_vacaciones into lp: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
Reviewer Review Type Date Requested Status
Industrias Diana Pending
Review via email: mp+334136@code.launchpad.net

Description of the change

[IMP] se modifico sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py, sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml reporte vacaciones por pagar

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
=== modified file 'sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py'
--- sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py 2016-11-23 11:59:11 +0000
+++ sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.py 2017-11-22 18:25:51 +0000
@@ -1,9 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22
3import time
4from osv import fields, osv3from osv import fields, osv
5from datetime import datetime4from datetime import datetime
6import pooler
7import calendar5import calendar
8import logging6import logging
9import netsvc7import netsvc
@@ -12,9 +10,10 @@
12 _name = "wizard.maximum.passive.holiday"10 _name = "wizard.maximum.passive.holiday"
13 _logger = logging.getLogger('wizard.maximum.passive.holiday')11 _logger = logging.getLogger('wizard.maximum.passive.holiday')
14 _columns = {12 _columns = {
15 'type_report': fields.selection([('resumido', 'Resumido'),('detallado', 'Detallado')], 'Reporte', select=True, required=True),13 'type_report': fields.selection([(False, ''),('detallado', 'Detallado'),('resumido', 'Resumido')], 'Reporte', select=True, required=True),
16 'sede_id': fields.many2one('hr.sede', 'Sede'),14 'sede_id': fields.many2one('hr.sede', 'Sede'),
17 'for_sede': fields.boolean(''),15 'for_sede': fields.boolean(''),
16 'basic': fields.boolean('Incluir sueldo basico'),
18 'mes': fields.many2one('hr.month', 'Mes', required=True),17 'mes': fields.many2one('hr.month', 'Mes', required=True),
19 }18 }
20 _defaults = {'for_sede': True}19 _defaults = {'for_sede': True}
@@ -23,7 +22,7 @@
23 smtp_client = self.pool.get('email.smtpclient')22 smtp_client = self.pool.get('email.smtpclient')
24 smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False)23 smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False)
25 if not smtp_server:24 if not smtp_server:
26 raise osv.except_osv(_('Acción Denegada!'), _('Debe configurar un servidor de correos para generar el reporte'))25 raise osv.except_osv(('Acción Denegada!'), ('Debe configurar un servidor de correos para generar el reporte'))
27 return True26 return True
28 27
29 def _check_user_email_adress(self, cr, uid, ids, context=None):28 def _check_user_email_adress(self, cr, uid, ids, context=None):
@@ -35,8 +34,6 @@
35 def _calcular_regla(self, cr, uid, rule, localdict, employee, context):34 def _calcular_regla(self, cr, uid, rule, localdict, employee, context):
36 obj_rule = self.pool.get('hr.salary.rule')35 obj_rule = self.pool.get('hr.salary.rule')
37 amount, qty, rate = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context)36 amount, qty, rate = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context)
38 previous_amount = rule.code in localdict and localdict[rule.code] or 0.0
39 tot_rule = amount * qty * rate / 100.0
40 return {37 return {
41 'salary_rule_id': rule.id,38 'salary_rule_id': rule.id,
42 'name': rule.name,39 'name': rule.name,
@@ -128,7 +125,24 @@
128 return float(salario[-1][-1])125 return float(salario[-1][-1])
129 return ''126 return ''
130 127
131 def get_payslip_lines(self, cr, uid, structure_brw, employee, list_concept_codes, fecha_creada):128
129 def remuneracion(self, cr, uid, employee_id, date_from):
130
131 monto = 0.0
132 payslip = self.pool.get('hr.payslip')
133 payslip_line = self.pool.get('hr.payslip.line')
134 payslip_id = payslip.search(cr, uid, [('employee_id', '=', employee_id), ('type_process', '=', 'nomina'), ('state', '=', 'done'),('date_from','<=',date_from)], limit=1)
135 if payslip_id:
136 payslip_line_id = payslip_line.search(cr, uid, [('slip_id', '=', payslip_id), ('code', '=', 'SD')] )
137 if not payslip_line_id:
138 payslip_id = payslip.search(cr, uid, [('employee_id', '=', employee_id), ('type_process', '=', 'nomina'), ('state', '=', 'done'), ('line_ids.code','=','SD')], limit=1)
139 payslip_line_id = payslip_line.search(cr, uid, [('slip_id', '=', payslip_id), ('code', '=', 'SD')] )
140 payslip_line_brw = payslip_line.browse(cr, uid, payslip_line_id[0])
141 monto = payslip_line_brw.amount
142 return monto
143
144
145 def get_payslip_lines(self, cr, uid, structure_brw, employee, list_concept_codes, fecha_creada, context):
132 146
133 obj_rule = self.pool.get('hr.salary.rule')147 obj_rule = self.pool.get('hr.salary.rule')
134 obj_line_liq = self.pool.get('hr.linea.liquidacion')148 obj_line_liq = self.pool.get('hr.linea.liquidacion')
@@ -137,14 +151,14 @@
137 fecha_liquidacion = datetime.strptime(fecha_creada,"%Y-%m-%d")151 fecha_liquidacion = datetime.strptime(fecha_creada,"%Y-%m-%d")
138 152
139 period = self.pool.get('hr.period').search(cr, uid, [153 period = self.pool.get('hr.period').search(cr, uid, [
140 ('date_start','<=', fecha_liquidacion), 154 ('date_start','<=', fecha_liquidacion),('date_end','>=', fecha_liquidacion),
141 ('date_end','>=', fecha_liquidacion),
142 ('type','=',employee.hr_payroll_id.hr_payment_calendar_id.type)])155 ('type','=',employee.hr_payroll_id.hr_payment_calendar_id.type)])
143 156
144 period = self.pool.get('hr.period').browse(cr, uid, period[0])157 period = self.pool.get('hr.period').browse(cr, uid, period[0])
145 158
146 #se obtienen los conceptos de la estructura salarial159 #se obtienen los conceptos de la estructura salarial
147 rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, [structure_brw.id], employee, period.id, context=None)160 rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, [structure_brw.id], employee, period.id, context=None)
161
148 sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])]162 sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])]
149 163
150 # vac_vencidas: Lista de tuplas. Cada tupla tiene la forma (vac_vencida, num_dias_adicionales)164 # vac_vencidas: Lista de tuplas. Cada tupla tiene la forma (vac_vencida, num_dias_adicionales)
@@ -154,34 +168,28 @@
154 employee_hol_brw = False168 employee_hol_brw = False
155 169
156 if employee_hol_ids:170 if employee_hol_ids:
171
157 employee_hol_brw = self.pool.get('hr.employee.holidays').browse(cr, uid, employee_hol_ids[0], context=None)172 employee_hol_brw = self.pool.get('hr.employee.holidays').browse(cr, uid, employee_hol_ids[0], context=None)
158 employee_hol_date = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d")173 employee_hol_date = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d")
174
159 #Se cancelan 1 dia adicional por año a partir del 2º año175 #Se cancelan 1 dia adicional por año a partir del 2º año
160 dias_adicionales = employee_hol_date.year-start_rel_lab.year-1 if \176 dias_adicionales = employee_hol_date.year-start_rel_lab.year-1 if employee_hol_date.year-start_rel_lab.year > 1 else 0
161 employee_hol_date.year-start_rel_lab.year > 1 else 0177 dias_adicionales = dias_adicionales if dias_adicionales < 15 else 15
162 dias_adicionales = dias_adicionales if dias_adicionales < 15 \178 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)
163 else 15179
164 num_vac_vencidas = (fecha_liquidacion.year - employee_hol_date.year) if \
165 fecha_liquidacion.month >= employee_hol_date.month else \
166 (fecha_liquidacion.year - employee_hol_date.year - 1)
167 for x in range(num_vac_vencidas):180 for x in range(num_vac_vencidas):
168 vac_vencidas.append((employee_hol_date.year+x, dias_adicionales + \181 dias_adicionales = dias_adicionales + 1 if dias_adicionales < 15 else 15
169 1 if dias_adicionales < 15 else 15))182 vac_vencidas.append((employee_hol_date.year + x, dias_adicionales))
170 else:183 else:
171 new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day)184 new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day)
172 num_vac_vencidas = (fecha_liquidacion.year - new_date.year) if \185 num_vac_vencidas = (fecha_liquidacion.year - new_date.year) if fecha_liquidacion.month > new_date.month else (fecha_liquidacion.year - new_date.year - 1)
173 fecha_liquidacion.month > new_date.month else \
174 (fecha_liquidacion.year - new_date.year - 1)
175 186
176 for x in range(num_vac_vencidas):187 for x in range(num_vac_vencidas):
177 dias_adicionales = x188 dias_adicionales = x
178 vac_vencidas.append((new_date.year + x, dias_adicionales \189 vac_vencidas.append((new_date.year + x, dias_adicionales if dias_adicionales < 15 else 15))
179 if dias_adicionales < 15 else 15))
180 190
181 new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day)191 new_date = datetime(start_rel_lab.year, start_rel_lab.month, start_rel_lab.day)
182 192 ultimo_anio_pagado = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d") if employee_hol_brw else new_date
183 ultimo_anio_pagado = datetime.strptime(employee_hol_brw.corresp_to_end,"%Y-%m-%d") \
184 if employee_hol_brw else new_date
185 193
186 reg_vac_no_disf = obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee)194 reg_vac_no_disf = obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee)
187 195
@@ -216,7 +224,6 @@
216 }224 }
217 225
218 localdict.update({'empleado': employee,})226 localdict.update({'empleado': employee,})
219 param_fp_id = parameter_obj.search(cr, uid, [('type', '=', 'fecha_prest')])
220227
221 parameters_dict = {}228 parameters_dict = {}
222 for parameter in employee.hr_payroll_id.parameters_ids:229 for parameter in employee.hr_payroll_id.parameters_ids:
@@ -224,39 +231,41 @@
224 231
225 localdict.update({'parametros': parameters_dict,})232 localdict.update({'parametros': parameters_dict,})
226 localdict['periodo'] = period233 localdict['periodo'] = period
227 rules_dict = {}234
228 rules_dict['SUELDO'] = self._sueldo(employee.id, fecha_creada, cr, uid)
229 localdict['concepto'] = rules_dict
230
231 categories_concept_dict={}235 categories_concept_dict={}
232 blacklist = {}236 blacklist = {}
233 result_dict = {}237 result_dict = {}
234 238
235 for rule in obj_rule.browse(cr, uid, sorted_rule_ids, context=None):239 for rule in obj_rule.browse(cr, uid, sorted_rule_ids, context=None):
240
236 key = rule.code241 key = rule.code
237 if key in list_concept_codes:242 if key in list_concept_codes:
243 rules_dict = {}
244
245 if key == 'VND':
246 rules_dict['SUELDO'] = self._sueldo(employee.id, fecha_creada, cr, uid)
247 elif key == 'DAV190' or key == 'V190':
248 rules_dict['SD'] = self.remuneracion(cr, uid, employee.id, fecha_liquidacion)
249
250 localdict['concepto'] = rules_dict
238 localdict['result'] = None251 localdict['result'] = None
239 localdict['result_qty'] = localdict['cantidad'] = 1.0252 localdict['result_qty'] = localdict['cantidad'] = 1.0
240 253 inicial_dict = self._calcular_regla(cr, uid, rule, localdict, employee, context=None)
254 amount = inicial_dict['amount']
255 qty = localdict['cantidad'] = inicial_dict['quantity']
256
241 if obj_rule.satisfy_condition(cr, uid, rule.id, localdict, context=None) and rule.id not in blacklist:257 if obj_rule.satisfy_condition(cr, uid, rule.id, localdict, context=None) and rule.id not in blacklist:
242 inicial_dict = self._calcular_regla(cr, uid, rule, localdict, employee, context=None)
243 amount = inicial_dict['amount']
244 qty = localdict['cantidad'] = inicial_dict['quantity']
245 258
246 if rule.code == concept_vac_ven_brw.code or rule.code == \259 if rule.code == concept_vac_ven_brw.code or rule.code == concept_dias_vac_ven_brw.code:
247 concept_dias_vac_ven_brw.code:260
248261 qty_concept = parameters_dict['vacaciones'] if rule.code == concept_vac_ven_brw.code else 15
249 qty_concept = parameters_dict['vacaciones'] \
250 if rule.code == concept_vac_ven_brw.code else 15
251
252 desde = datetime.strptime(employee.start_rel_lab,"%Y-%m-%d")262 desde = datetime.strptime(employee.start_rel_lab,"%Y-%m-%d")
253 263 num_vac = len(vac_vencidas) if (desde.month == fecha_liquidacion.month and desde.day == fecha_liquidacion.day) else len(vac_vencidas) + 1
254 num_vac = len(vac_vencidas) if (desde.month == fecha_liquidacion.month and
255 desde.day == fecha_liquidacion.day) else len(vac_vencidas) + 1
256 264
257 for c in range(num_vac):265 for c in range(num_vac):
258266
259 if fecha_liquidacion.year > desde.year:267 if fecha_liquidacion.year > desde.year:
268
260 if fecha_liquidacion.month == desde.month:269 if fecha_liquidacion.month == desde.month:
261 if fecha_liquidacion.day < desde.day:270 if fecha_liquidacion.day < desde.day:
262 meses = 12 - desde.month + fecha_liquidacion.month - 1271 meses = 12 - desde.month + fecha_liquidacion.month - 1
@@ -267,50 +276,44 @@
267 meses = 12276 meses = 12
268 277
269 elif fecha_liquidacion.month < desde.month:278 elif fecha_liquidacion.month < desde.month:
279
270 if fecha_liquidacion.day < desde.day:280 if fecha_liquidacion.day < desde.day:
271 meses = 12 - desde.month + fecha_liquidacion.month - 1281 meses = 12 - desde.month + fecha_liquidacion.month - 1
272 else:282 else:
273 meses = 12 - desde.month + fecha_liquidacion.month283 meses = 12 - desde.month + fecha_liquidacion.month
274 else:284 else:
285
275 meses = fecha_liquidacion.month - desde.month286 meses = fecha_liquidacion.month - desde.month
276 if fecha_liquidacion.day < desde.day:287 if fecha_liquidacion.day < desde.day:
277 meses = fecha_liquidacion.month - desde.month - 1288 meses = fecha_liquidacion.month - desde.month - 1
278 else:289 else:
279 meses = fecha_liquidacion.month - desde.month290 meses = fecha_liquidacion.month - desde.month
280 else:291 else:
292
281 meses = fecha_liquidacion.month - desde.month293 meses = fecha_liquidacion.month - desde.month
294
282 if fecha_liquidacion.day < desde.day:295 if fecha_liquidacion.day < desde.day:
283 meses = fecha_liquidacion.month - desde.month - 1296 meses = fecha_liquidacion.month - desde.month - 1
284 else:297 else:
285 meses = fecha_liquidacion.month - desde.month298 meses = fecha_liquidacion.month - desde.month
286 299
287 qty = qty_concept if ((ultimo_anio_pagado.year+c < fecha_liquidacion.year-1) or \300 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
288 (ultimo_anio_pagado.year+c == fecha_liquidacion.year-1 and \
289 fecha_liquidacion.month > ultimo_anio_pagado.month)) \
290 else float(qty_concept)/12*meses
291 301
292 key_ = key + '-' + str(ultimo_anio_pagado.year+c)302 key_ = key + '-' + str(ultimo_anio_pagado.year+c)
303
293 result_dict[key_] = inicial_dict.copy()304 result_dict[key_] = inicial_dict.copy()
305
294 result_dict[key_].update({306 result_dict[key_].update({
295 'name': rule.name,307 'name': rule.name,
296 'periodo': 'Periodo ' + str(ultimo_anio_pagado.year+c) \308 '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,
297 + '-' + str(ultimo_anio_pagado.year+1+c)\
298 if qty == qty_concept \
299 else 'Fraccion periodo ' + \
300 str(fecha_liquidacion.year) \
301 + '-' + str(fecha_liquidacion.year+1) if \
302 fecha_liquidacion.month > ultimo_anio_pagado.month else
303 'Fraccion periodo ' + \
304 str(fecha_liquidacion.year-1) \
305 + '-' + str(fecha_liquidacion.year),
306 'quantity': qty,
307 })309 })
308 rules_dict[key_] = amount * qty or 0.0310 rules_dict[key_] = amount * qty or 0.0
309 localdict['concepto'] = rules_dict311 localdict['concepto'] = rules_dict
310 312
311 elif rule.code == concept_dias_adic_vac_ven_brw.code:313 elif rule.code == concept_dias_adic_vac_ven_brw.code:
312314
313 for c in range(len(vac_vencidas)):315 for c in range(len(vac_vencidas)):
316
314 qty = vac_vencidas[c][1]317 qty = vac_vencidas[c][1]
315 key_ = key + '-' + str(ultimo_anio_pagado.year+c)318 key_ = key + '-' + str(ultimo_anio_pagado.year+c)
316 result_dict[key_] = inicial_dict.copy()319 result_dict[key_] = inicial_dict.copy()
@@ -334,79 +337,56 @@
334 localdict['concepto'] = rules_dict337 localdict['concepto'] = rules_dict
335 338
336 elif rule.code == concept_vac_no_disf_brw.code:339 elif rule.code == concept_vac_no_disf_brw.code:
340
337 for _vac in reg_vac_no_disf:341 for _vac in reg_vac_no_disf:
342
338 anio = datetime.strptime(_vac.employee_holidays_add_id.corresp_to_end,"%Y-%m-%d").year343 anio = datetime.strptime(_vac.employee_holidays_add_id.corresp_to_end,"%Y-%m-%d").year
339 tipo = _vac.name[_vac.name.find('/')+13:]
340 qty = reg_vac_no_disf[_vac]344 qty = reg_vac_no_disf[_vac]
341 key_ = key + '-' + str(_vac.name[_vac.name.find('/')+2:])345 key_ = key + '-' + str(_vac.name[_vac.name.find('/') + 2:])
342 result_dict[key_] = inicial_dict.copy()346 result_dict[key_] = inicial_dict.copy()
347
343 result_dict[key_].update({348 result_dict[key_].update({
349
344 'name': rule.name,350 'name': rule.name,
345 'periodo': 'Periodo ' + str(anio-1) + ' - ' + str(anio),351 'periodo': 'Periodo ' + str(anio-1) + ' - ' + str(anio),
346 'quantity': qty,352 'quantity': qty,
347 })353 })
348 rules_dict[key_] = amount*qty or 0.0354
355 rules_dict[key_] = amount * qty or 0.0
349 localdict['concepto'] = rules_dict356 localdict['concepto'] = rules_dict
350
351 else:
352 result_dict[key] = inicial_dict.copy()
353
354 if rule.code == concept_util_liq_brw.code:
355 qty = parameters_dict['utilidades']
356 result_dict[key]['quantity'] = qty
357
358 elif rule.code == concept_prest_liq_brw.code:
359 qty = 5
360 result_dict[key]['quantity'] = qty
361
362 elif rule.code == concept_util_frac_liq_brw.code:
363 contract_date_start = datetime.strptime(employee.start_rel_lab,"%Y-%m-%d")
364 fraccion_mes = fecha_liquidacion.day / \
365 calendar.monthrange(fecha_liquidacion.year,fecha_liquidacion.month)[1]
366 if contract_date_start.year < fecha_liquidacion.year:
367 qty = parameters_dict['utilidades']/12*(fecha_liquidacion.month \
368 - 1 + fraccion_mes)
369 result_dict[key]['quantity'] = qty
370 elif contract_date_start.year == fecha_liquidacion.year:
371 qty = parameters_dict['utilidades']/12*(fecha_liquidacion.month - \
372 contract_date_start.month+fraccion_mes)
373 result_dict[key]['quantity'] = qty
374
375 rules_dict[key] = amount*qty or 0.0
376 localdict['concepto'] = rules_dict
377 357
378 if rule.concept_id.category_id.code not in categories_concept_dict:358 if rule.concept_id.category_id.code not in categories_concept_dict:
379 categories_concept_dict[rule.concept_id.category_id.code] = \359
380 amount or 0.0360 categories_concept_dict[rule.concept_id.category_id.code] = amount or 0.0
381 else:361 else:
382 categories_concept_dict[rule.concept_id.category_id.code] = \362 categories_concept_dict[rule.concept_id.category_id.code] = categories_concept_dict[rule.concept_id.category_id.code] + amount
383 categories_concept_dict[rule.concept_id.category_id.code] \363
384 + amount
385 localdict['categoria_concepto'] = categories_concept_dict364 localdict['categoria_concepto'] = categories_concept_dict
365
386 else:366 else:
387 blacklist += [id for id, seq in 367
388 self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, 368 blacklist += [id for id, seq in self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, uid, [rule], context=context)]
389 uid, [rule], context=context)]
390 369
391 result = [value for code, value in result_dict.items()]370 result = [value for code, value in result_dict.items()]
392 371
393 return result372 return result
394 373
395 374
396 def _send_report_by_email(self, cr, uid, parameters, context=None):375 def _send_report_by_email(self, cr, uid, parameters, context=None):
397 376
398 subject = parameters['subject']377 subject = parameters['subject']
399 message = parameters['message']378 message = parameters['message']
400 data = parameters['data']379 data = parameters['data']
380 title = parameters['data']['titulo']
401 file_name = parameters['file_name']381 file_name = parameters['file_name']
402 fecha_creada = parameters['data']['fecha_creada']382 fecha_creada = parameters['data']['fecha_creada']
403383 type_report = parameters['data']['type_report']
384 basic = parameters['data']['sueldo_basico']
385
404 smtp_client = self.pool.get('email.smtpclient')386 smtp_client = self.pool.get('email.smtpclient')
405 smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False)387 smtp_server = smtp_client.search(cr, uid, [('active','=',True),('state','=','confirm')], context=False)
406 388
407 parameter_obj = self.pool.get('hr.parameters')389 parameter_obj = self.pool.get('hr.parameters')
408 payroll_obj = self.pool.get('hr.payroll')
409 payroll_structure_obj = self.pool.get('hr.payroll.structure')
410 obj_line_liq = self.pool.get('hr.linea.liquidacion')390 obj_line_liq = self.pool.get('hr.linea.liquidacion')
411 391
412 param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')])392 param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')])
@@ -416,71 +396,102 @@
416 396
417 if data['for_sede']:397 if data['for_sede']:
418 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo']),('start_rel_lab','<=', fecha_creada)])398 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo']),('start_rel_lab','<=', fecha_creada)])
419 title = "Todas las sedes"
420 else:399 else:
421 brw_sede = self.pool.get('hr.sede').browse(cr, uid, data['sede'])
422 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)])400 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)])
423 title = brw_sede.name401
424 402 list_concept_codes = self.query_concept(cr)
425 list_val = []
426 value = []
427
428 dicc_department = {}403 dicc_department = {}
429 404
430 for i in employee_ids:405 if employee_ids:
431 employee = self.pool.get('hr.employee').browse(cr, uid, [i])406 c = 0
432 if employee[0].start_rel_lab <= fecha_creada:407 for i in employee_ids:
433 dicc_department[employee[0].department_id.id] = []408 c = c + 1
434 409 #~ print str(c) + " de " + str(len(employee_ids))
435 410 val= []
436 for i in employee_ids:411 l=[]
437 employee = self.pool.get('hr.employee').browse(cr, uid, [i])412
438 if employee[0].start_rel_lab <= fecha_creada:413 employee = self.pool.get('hr.employee').browse(cr, uid, [i])
439 struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id]414
440 lines = self.get_payslip_lines(cr, uid, struct_brw[0], employee[0], list_concept_codes, fecha_creada)415 if employee[0].start_rel_lab <= fecha_creada:
441 val= []416
442 l=[]417 struct_list = parameter_obj.browse(cr, uid, param_struct_id)[0].estruc_liq_ids
418 struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id]
419 if struct_brw:
420 obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0])
421 else:
422 raise osv.except_osv(('ERROR!'), ('La %s no esta incluida en los parametros de la estructura para liquidacion'%(employee[0].hr_payroll_id.name)))
423
424 struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id]
425 lines = self.get_payslip_lines(cr, uid, struct_brw[0], employee[0], list_concept_codes, fecha_creada, context)
426
443 [l.append(key) for key in lines if key not in l]427 [l.append(key) for key in lines if key not in l]
428
429 sd = self.remuneracion(cr, uid, employee[0].id, fecha_creada)
430
444 for line in l:431 for line in l:
445 if line['amount'] > 0.0 and line['quantity'] > 0.0:432 if line['amount'] > 0.0 and line['quantity'] > 0.0:
446 amount = line['amount'] * line['quantity']433 amount = line['amount'] * line['quantity']
447 val.append({'n':line['name'] + " " + line['periodo'], 'a':amount, 'q':line['quantity'], 'p':line['periodo']})434 basico = sd * line['quantity']
435 val.append({'sd':basico,'n':line['name'] + " " + line['periodo'], 'a':amount, 'q':line['quantity'], 'p':line['periodo']})
436
448 if val:437 if val:
438
439 if not employee[0].department_id.id in dicc_department:
440 dicc_department[employee[0].department_id.id]=[]
449 dicc_department[employee[0].department_id.id].append((employee[0].cod_number, employee[0].name, sorted(val)))441 dicc_department[employee[0].department_id.id].append((employee[0].cod_number, employee[0].name, sorted(val)))
450 442
451 total_departamento={}443 total_departamento={}
444 total_departamento_basico={}
445
452 for c in dicc_department:446 for c in dicc_department:
453 total_departamento[c] = 0.0447 total_departamento[c] = 0.0
448 total_departamento_basico[c] = 0.0
454 449
455 for c in dicc_department:450 for c in dicc_department:
456 amount = 0.0451 amount = 0.0
452 basico = 0.0
457 for i in dicc_department[c]:453 for i in dicc_department[c]:
454
458 for x in i[2]:455 for x in i[2]:
459 amount += x['a']456 amount += x['a']
457 basico += x['sd']
458
460 total_departamento[c] = amount459 total_departamento[c] = amount
460 total_departamento_basico[c] = basico
461 461
462 total_resumen = []462 total_resumen = []
463 total_resumen_basico = []
463 for c in total_departamento:464 for c in total_departamento:
464 total_resumen.append(total_departamento[c])465 total_resumen.append(total_departamento[c])
466 total_resumen_basico.append(total_departamento_basico[c])
467
465 total_resumen = sum(total_resumen)468 total_resumen = sum(total_resumen)
469 total_resumen_basico = sum(total_resumen_basico)
466 470
467 total_empleado = {}471 total_empleado = {}
472 total_empleado_basico = {}
468 for c in dicc_department:473 for c in dicc_department:
469 for i in dicc_department[c]:474 for i in dicc_department[c]:
470 total_empleado[i[0]] = 0.0475 total_empleado[i[0]] = 0.0
476 total_empleado_basico[i[0]] = 0.0
471 477
472 for c in dicc_department:478 for c in dicc_department:
473 for i in dicc_department[c]:479 for i in dicc_department[c]:
474 for x in i[2]:480 for x in i[2]:
475 total_empleado[i[0]] += x['a']481 total_empleado[i[0]] += x['a']
482 total_empleado_basico[i[0]] += x['sd']
476 483
477 new = datetime.strptime(fecha_creada, '%Y-%m-%d')484 new = datetime.strptime(fecha_creada, '%Y-%m-%d')
478 485
479 data['form'] = dicc_department486 data['form'] = dicc_department
480 data['total_resumen'] = total_resumen487 data['total_resumen'] = total_resumen
488 data['total_resumen_basico'] = total_resumen_basico
481 data['total_empleado'] = total_empleado489 data['total_empleado'] = total_empleado
490 data['total_empleado_basico'] = total_empleado_basico
482 data['sede'] = title491 data['sede'] = title
483 data['al'] = str(new.strftime('%d-%m-%Y'))492 data['sueldo_basico'] = basic
493 data['type_report'] = type_report
494 data['al'] = str(new.strftime('%d/%m/%Y'))
484 495
485 report = self._create_report(cr, uid, data['ids'], data['model'], file_name, data)496 report = self._create_report(cr, uid, data['ids'], data['model'], file_name, data)
486 attachments = report[0] and [report[1]] or []497 attachments = report[0] and [report[1]] or []
@@ -502,17 +513,13 @@
502 'from': uid,513 'from': uid,
503 'attachments': attachments514 'attachments': attachments
504 }515 }
505
506 smtp_client.send_email(cr, uid, smtp_server_id, email['to'], email['name'], email['body'], email['attachments'])516 smtp_client.send_email(cr, uid, smtp_server_id, email['to'], email['name'], email['body'], email['attachments'])
507 finally:517 finally:
508 cron = self.pool.get('ir.cron')518 cron = self.pool.get('ir.cron')
509 accion_planificada = cron.search(cr, uid, [('name','=', subject)])519 accion_planificada = cron.search(cr, uid, [('name','=', subject)])
510 cron.unlink(cr, uid, accion_planificada)520 cron.unlink(cr, uid, accion_planificada)
511 521
512 def _send_request(self, cr, uid, ids, subject, message, context=None):522 def _send_request(self, cr, uid, ids, subject, message, context=None):
513 """
514 Metodo que envia una notificacion interna de OpenERP
515 """
516 notificaciones = {523 notificaciones = {
517 'name': (subject),524 'name': (subject),
518 'act_to': uid,525 'act_to': uid,
@@ -535,40 +542,36 @@
535 fp.write(result);542 fp.write(result);
536 fp.close();543 fp.close();
537 except Exception,e:544 except Exception,e:
538 print 'Exception in create report:',e545 #~ print 'Exception in create report:',e
539 return (False, str(e))546 return (False, str(e))
540 return (True, ret_file_name)547 return (True, ret_file_name)
541 548
542 def getObtenerDia(self, mes, dia="primer"):549 def getObtenerDia(self, mes, anio):
543 meses = {'ENERO':'01', 'FEBRERO':'02', 'MARZO':'03', 'ABRIL':'04', 'MAYO':'05', 'JUNIO':'06', 550 calendario = calendar.monthrange(anio, mes)
544 'JULIO':'07', 'AGOSTO':'08', 'SEPTIEMBRE':'09', 'OCTUBRE':'10', 'NOVIEMBRE':'11', 'DICIEMBRE':'12'}551 return '%s-%s-%s'%(anio, '0'+ str(mes) if len(str(mes)) < 2 else mes, calendario[1])
545 mes = mes.split(" ")
546 anio = mes[1]
547 mes = meses[mes[0].upper()]
548 calendario = calendar.monthrange(int(anio),int(mes))
549 if dia == "ultimo":
550 fecha_creada = str(anio)+"-"+ str(mes)+ "-" + str(calendario[1])
551 return fecha_creada
552 return str(anio)+"-"+ str(mes)+ "-" + "-01"
553 552
554 def print_report_buton(self, cr, uid, ids, context=None):553 def print_report_buton(self, cr, uid, ids, context=None):
555 554
556 brw = self.browse(cr, uid, ids)[0]555 if context is None:context = {}
557 mes = brw.mes.name556 context['procesar'] = True
558 month_id = brw.mes.id557
559 fecha_creada = self.getObtenerDia(mes, 'ultimo')
560 for_sede = brw.for_sede
561 type_report = brw.type_report
562
563 self._check_email_server(cr, uid, ids, context)558 self._check_email_server(cr, uid, ids, context)
564 email = self._check_user_email_adress(cr, uid, ids, context)559 email = self._check_user_email_adress(cr, uid, ids, context)
565 560
561 if not email:
562 raise osv.except_osv(('ERROR!'), ('No hay un correo electronico asociado al usuario.'))
563
566 parameter_obj = self.pool.get('hr.parameters')564 parameter_obj = self.pool.get('hr.parameters')
567 payroll_obj = self.pool.get('hr.payroll')565 payroll_obj = self.pool.get('hr.payroll')
568 payroll_structure_obj = self.pool.get('hr.payroll.structure')566 payroll_structure_obj = self.pool.get('hr.payroll.structure')
569 obj_line_liq = self.pool.get('hr.linea.liquidacion')
570 obj_process = self.pool.get('hr.process')567 obj_process = self.pool.get('hr.process')
571 obj_period = self.pool.get('hr.period')568 obj_period = self.pool.get('hr.period')
569 obj_line_liq = self.pool.get('hr.linea.liquidacion')
570
571 brw = self.browse(cr, uid, ids)[0]
572 mes_brw = brw.mes
573 sede_id = brw.sede_id
574 fecha_creada = self.getObtenerDia(mes_brw.month_year, mes_brw.hr_year_id.year)
572 575
573 param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')])576 param_struct_id = parameter_obj.search(cr, uid, [('type', '=', 'estructuras_liq')])
574 if not param_struct_id:577 if not param_struct_id:
@@ -611,7 +614,8 @@
611 la pestaña Configuracion -> Configuraciones de nomina -> \614 la pestaña Configuracion -> Configuraciones de nomina -> \
612 Parametros de nomina y registrar un parametro de tipo \615 Parametros de nomina y registrar un parametro de tipo \
613 Conceptos Vacaciones no disfrutadas'))616 Conceptos Vacaciones no disfrutadas'))
614617
618
615 nomina_ids = payroll_obj.search(cr, uid, [])619 nomina_ids = payroll_obj.search(cr, uid, [])
616 nomina_browse = payroll_obj.browse(cr, uid, nomina_ids)620 nomina_browse = payroll_obj.browse(cr, uid, nomina_ids)
617 621
@@ -621,6 +625,7 @@
621 raise osv.except_osv(('ERROR!'), ('No hay una Estructuras de Liquidaciones para la nomina %s')%(i.name))625 raise osv.except_osv(('ERROR!'), ('No hay una Estructuras de Liquidaciones para la nomina %s')%(i.name))
622 626
623 for i in nomina_browse:627 for i in nomina_browse:
628
624 param_concept_salary_id = parameter_obj.search(cr, uid, [('type', '=', 'concepto_sueldo'),629 param_concept_salary_id = parameter_obj.search(cr, uid, [('type', '=', 'concepto_sueldo'),
625 ('payroll_id', '=', i.id)])630 ('payroll_id', '=', i.id)])
626 631
@@ -635,54 +640,58 @@
635 Parametros de nomina y registrar un parametro de tipo \640 Parametros de nomina y registrar un parametro de tipo \
636 Concepto Salario')%(i.name))641 Concepto Salario')%(i.name))
637 642
638 fecha_liquidacion = datetime.strptime(fecha_creada,"%Y-%m-%d")643 period_id = obj_period.search(cr, uid, [('hr_month_id', '=', mes_brw.id), ('state', '=', 'close')])
639
640 period_id = obj_period.search(cr, uid, [('hr_month_id', '=', month_id), ('state', '=', 'close')])
641 644
642 if not period_id:645 if not period_id:
643 raise osv.except_osv(('ERROR!'), ('No hay un periodo asociado a la fecha %s para la %s')%(today, i.name)) 646 raise osv.except_osv(('ERROR!'), ('No hay un periodo asociado al mes seleccionado. para la %s')%(i.name))
644 647
645 otros_procesos_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), 648 otros_procesos_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id),
646 ('type', 'not in', ('prestaciones','bono_alimentacion','guarderias')), 649 ('type', 'not in', ('prestaciones','bono_alimentacion','guarderias')),
647 ('hr_period_ids', 'in', period_id), ('state', '=', 'done')])650 ('hr_period_ids', 'in', period_id), ('state', '=', 'done')])
648 651
649 if otros_procesos_id:652 if otros_procesos_id:
650653
651 proceso_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), ('type', '=', 'prestaciones'), 654 proceso_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id),
652 ('hr_period_ids', 'in', period_id), ('state', '=', 'done')])655 ('type', '=', 'prestaciones'),
656 ('hr_period_ids', 'in', period_id),
657 ('state', '=', 'done')])
653 658
654 if not proceso_id:659 if not proceso_id:
655 raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no \660 raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no posee proceso de Prestaciones Sociales aprobado'%(i.name, mes_brw.name)))
656 posee proceso de Prestaciones Sociales aprobado'%(i.name, mes)))
657 661
658 proceso_nomina_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id), ('type', '=', 'nomina'), 662 proceso_nomina_id = obj_process.search(cr, uid, [('hr_payroll_ids', '=', i.id),
659 ('hr_period_ids', 'in', period_id), ('state', '=', 'done')])663 ('type', '=', 'nomina'),
664 ('hr_period_ids', 'in', period_id),
665 ('state', '=', 'done')])
660 666
661 if not proceso_nomina_id:667 if not proceso_nomina_id:
662 raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no \668 raise osv.except_osv(('ERROR!'), ('La %s para el mes de %s no posee proceso de Nomina aprobado'%(i.name, mes_brw.name)))
663 posee proceso de Nomina aprobado'%(i.name, mes)))
664 669
665 if for_sede:670 if brw.for_sede:
666 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo'])])671 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('state','in',['vacaciones','activo','reposo'])])
667 title = "TODAS LAS SEDES"
668 else:672 else:
669 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('hr_sede_id','=',brw.sede_id.id),('state','in',['vacaciones','activo','reposo'])])673 employee_ids = self.pool.get('hr.employee').search(cr, uid, [('hr_sede_id','=',sede_id.id),('state','in',['vacaciones','activo','reposo'])])
670 title = brw.sede_id.name674
671 675 title = sede_id.name if not brw.for_sede else 'TODAS LAS SEDES'
672 676
673 if employee_ids:677 if employee_ids:
678
674 for i in employee_ids:679 for i in employee_ids:
680
675 employee = self.pool.get('hr.employee').browse(cr, uid, [i])681 employee = self.pool.get('hr.employee').browse(cr, uid, [i])
676 if employee[0].start_rel_lab <= fecha_creada:682 if employee[0].start_rel_lab <= fecha_creada:
677 struct_list = parameter_obj.browse(cr, uid, param_struct_id)[0].estruc_liq_ids683 struct_list = parameter_obj.browse(cr, uid, param_struct_id)[0].estruc_liq_ids
678 struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id]684 struct_brw = [x for x in struct_list if x.hr_payroll_id == employee[0].hr_payroll_id]
679 if struct_brw:685 if struct_brw:
680 reg_vac_no_disf = obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0])686 obj_line_liq.vacaciones_no_disfrutadas(cr, uid, employee[0])
681 else:687 else:
682 raise osv.except_osv(('ERROR!'), ('La %s no esta incluida en los parametros de la estructura para liquidacion'%(employee[0].hr_payroll_id.name)))688 raise osv.except_osv(('ERROR!'), ('La %s no esta incluida en los parametros de la estructura para liquidacion'%(employee[0].hr_payroll_id.name)))
689
683 data = {}690 data = {}
684 data['form'] = {}691 data['form'] = {}
685 data['ids'] = [1]692 data['ids'] = [1]
693 data['titulo'] = title
694 data['sueldo_basico'] = brw.basic
686 data['model'] = "wizard.maximum.passive.holiday"695 data['model'] = "wizard.maximum.passive.holiday"
687 data['sede'] = brw.sede_id.id696 data['sede'] = brw.sede_id.id
688 data['type_report'] = brw.type_report697 data['type_report'] = brw.type_report
@@ -715,11 +724,9 @@
715 self.pool.get('ir.cron').create(cr, uid, vals, context)724 self.pool.get('ir.cron').create(cr, uid, vals, context)
716 self._send_request(cr, uid, ids, subject, request_message, context)725 self._send_request(cr, uid, ids, subject, request_message, context)
717 return {'type':'ir.actions.act_window_close'}726 return {'type':'ir.actions.act_window_close'}
718 else:727
719 raise osv.except_osv(('Accion Denegada!'), ('No existen datos disponibles para generar el reporte'))728 raise osv.except_osv(('Accion Denegada!'), ('No existen datos disponibles para generar el reporte'))
720 else:729
721 raise osv.except_osv(('Accion Denegada!'), ('%s no cuenta con trabajadores para poder generar este reporte')%(title))730 raise osv.except_osv(('Accion Denegada!'), ('%s no cuenta con trabajadores para poder generar este reporte')%(title))
722
723
724 731
725wizard_maximum_passive_holiday()732wizard_maximum_passive_holiday()
726733
=== modified file 'sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml'
--- sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml 2016-11-22 14:39:04 +0000
+++ sisb_nomina/wizard/reporte_pasivo_maximo_vacaciones.xml 2017-11-22 18:25:51 +0000
@@ -7,23 +7,25 @@
7 <field name="type">form</field>7 <field name="type">form</field>
8 <field name="arch" type="xml">8 <field name="arch" type="xml">
9 <form string="maximum passive holiday">9 <form string="maximum passive holiday">
10 <group col="4" colspan="4" >10
11 11 <group colspan="2" col="6">
12 </group>12 <field name="type_report"/>
13 <group colspan="4" col="8">13 <field name="sede_id" attrs= "{'readonly':[('for_sede','=','True')], 'required':[('for_sede','!=','True')] }"/>
14 <field name="type_report" colspan="1"/>14 <field name="for_sede" />
15 <field name="sede_id" colspan="2" attrs= "{'readonly':[('for_sede','=','True')], 'required':[('for_sede','!=','True')] }"/>15 <field name="mes" />
16 <field name="for_sede" colspan="2" />16 <field name="basic" />
17 17 </group>
18 <newline/>18
19 19
20 <field name="mes" colspan="2" />20 <newline/>
21 </group>21
22 <newline/>
23 <newline/>
24 <group>22 <group>
25 <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" />23
24 <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" />
25
26 </group>26 </group>
27
28
27 </form>29 </form>
28 </field>30 </field>
29 </record>31 </record>

Subscribers

People subscribed via source and target branches