Fix - Nómina separación

This commit is contained in:
Mauricio Baeza 2018-04-09 00:47:14 -05:00
parent 790e8ed7d6
commit 66b5ceab1f
2 changed files with 75 additions and 5 deletions

View File

@ -1008,7 +1008,12 @@ class LIBO(object):
count -= 1
first = True
separacion = {}
for r in percepciones:
if 'TotalPagado' in r:
separacion = r
continue
tipo = r.get('TipoPercepcion')
concepto = r.get('Concepto')
gravado = r.get('ImporteGravado')
@ -1264,6 +1269,15 @@ class LIBO(object):
data = tuple([r[2:] for r in rows[:count+2]])
return data, ''
def _get_separacion(self, doc, count):
rows, msg = self._get_data(doc, 'Separacion')
if len(rows) == 2:
msg = 'Sin Separacion'
return {}, msg
data = tuple([r[1:] for r in rows[:count+2]])
return data, ''
def _get_horas_extras(self, doc, count):
rows, msg = self._get_data(doc, 'HorasExtras')
if len(rows) == 2:
@ -1318,6 +1332,11 @@ class LIBO(object):
doc.close(True)
return {}, msg
separacion, msg = self._get_separacion(doc, len(nomina))
if msg:
doc.close(True)
return {}, msg
horas_extras, msg = self._get_horas_extras(doc, len(nomina))
if msg:
doc.close(True)
@ -1333,6 +1352,7 @@ class LIBO(object):
data['percepciones'] = percepciones
data['deducciones'] = deducciones
data['otros_pagos'] = otros_pagos
data['separacion'] = separacion
data['horas_extras'] = horas_extras
data['incapacidades'] = incapacidades

View File

@ -6146,6 +6146,7 @@ class CfdiNomina(BaseModel):
total_jubilacion += gravado + exento
elif key in ('022', '023', '025'):
total_separacion += gravado + exento
new = {
'tipo_percepcion': tp,
'importe_gravado': gravado,
@ -6153,15 +6154,15 @@ class CfdiNomina(BaseModel):
}
data.append(new)
total_sueldos = round(total_gravado + total_exento, DECIMALES)
total_percepciones = round(total_gravado + total_exento, DECIMALES)
total_sueldos = round(total_percepciones - total_jubilacion - total_separacion, DECIMALES)
totals = {
'total_gravado': total_gravado,
'total_exento': total_exento,
'total_jubilacion': total_jubilacion,
'total_separacion': total_separacion,
'total_sueldos': total_sueldos,
'total_percepciones': round(
total_sueldos + total_jubilacion + total_separacion, DECIMALES)
'total_percepciones': total_percepciones
}
return data, totals, ''
@ -6239,6 +6240,31 @@ class CfdiNomina(BaseModel):
return data, totals, ''
def _validate_separacion(self, row):
if not row[0]:
return {}, ''
if not row[2] or isinstance(row[2], str):
msg = 'El campo Ultimo Sueldo debe ser un importe'
return {}, msg
if isinstance(row[3], str):
msg = 'El campo Ingreso Acumulable debe ser un importe'
return {}, msg
if isinstance(row[4], str):
msg = 'El campo Ingreso No Acumulable debe ser un importe'
return {}, msg
new = {
'total_pagado': round(row[0], DECIMALES),
'years_servicio': int(row[1]),
'ultimo_sueldo': round(row[2], DECIMALES),
'ingreso_acumulable': round(row[3], DECIMALES),
'ingreso_no_acumulable': round(row[4], DECIMALES),
}
return new, ''
def _validate_horas_extras(self, row):
data = []
for i, key in enumerate(row[::4]):
@ -6327,6 +6353,7 @@ class CfdiNomina(BaseModel):
deducciones = data['deducciones'][2:]
ho = data['otros_pagos'][:1]
otros_pagos = data['otros_pagos'][2:]
separacion = data['separacion'][2:]
horas_extras = data['horas_extras'][2:]
incapacidades = data['incapacidades'][2:]
@ -6361,6 +6388,11 @@ class CfdiNomina(BaseModel):
util.log_file('nomina', msg)
continue
new_separacion, msg = self._validate_separacion(self, separacion[i])
if msg:
util.log_file('nomina', msg)
continue
new_horas_extras, msg = self._validate_horas_extras(self, horas_extras[i])
if msg:
util.log_file('nomina', msg)
@ -6413,6 +6445,10 @@ class CfdiNomina(BaseModel):
row['cfdi'] = obj
CfdiNominaRelacionados.create(**row)
if new_separacion:
new_separacion['cfdi'] = obj
CfdiNominaSeparacion.create(**new_separacion)
concepto = {
'cfdi': obj,
'valor_unitario': totals['subtotal'],
@ -6618,6 +6654,18 @@ class CfdiNomina(BaseModel):
details.append(p)
percepciones['details'] = details
rows = CfdiNominaSeparacion.select().where(CfdiNominaSeparacion.cfdi==cfdi)
for row in rows:
separacion = {
'TotalPagado': FORMAT.format(row.total_pagado),
'NumAñosServicio': str(row.years_servicio),
'UltimoSueldoMensOrd': FORMAT.format(row.ultimo_sueldo),
'IngresoAcumulable': FORMAT.format(row.ingreso_acumulable),
'IngresoNoAcumulable': FORMAT.format(row.ingreso_no_acumulable),
}
percepciones['separacion'] = separacion
break
rows = CfdiNominaHorasExtra.select().where(CfdiNominaHorasExtra.cfdi==cfdi)
details = []
for row in rows:
@ -6812,6 +6860,8 @@ class CfdiNomina(BaseModel):
q.execute()
q = CfdiNominaOtroPago.delete().where(CfdiNominaOtroPago.cfdi==obj)
q.execute()
q = CfdiNominaSeparacion.delete().where(CfdiNominaSeparacion.cfdi==obj)
q.execute()
q = CfdiNominaHorasExtra.delete().where(CfdiNominaHorasExtra.cfdi==obj)
q.execute()
q = CfdiNominaIncapacidad.delete().where(CfdiNominaIncapacidad.cfdi==obj)
@ -8131,8 +8181,8 @@ def _exportar_documentos():
_, name = Facturas.get_xml(row['id'])
msg = '\tXML extraido...'
log.info(msg)
# ~ name = name[:-3] + 'pdf'
# ~ path = '/home/mau/facturas/{}/{}/{}/{}'.format(rfc, year, month, name)
name = name[:-3] + 'pdf'
# ~ path = '/home/mau/facturas/CURG62080951A/{}/{}/{}'.format(year, month.zfill(2), name)
# ~ if util.exists(path):
# ~ continue
Facturas.get_pdf(row['id'], rfc, True)