Skip to content

Instantly share code, notes, and snippets.

@l4sh
Created September 18, 2018 15:58
Show Gist options
  • Save l4sh/135d47fe1b091b11c03d6b0673cd1503 to your computer and use it in GitHub Desktop.
Save l4sh/135d47fe1b091b11c03d6b0673cd1503 to your computer and use it in GitHub Desktop.
def find_bad_cfds(cfds):
invoice_types = ['Ingreso', 'Egreso']
bad_cfds = []
for cfd in cfds:
comprobante = {}
for invoice_type in invoice_types:
comprobante = cfd.metadata.get('IR', {}).get(invoice_type, {}).get('Comprobante')
if comprobante:
break
descuento = comprobante.get('Descuento', 0)
subtotal = comprobante.get('SubTotal', 0)
total_impuestos_trasladados = comprobante.get('Impuestos', {}).get('TotalImpuestosTrasladados', 0)
total = comprobante.get('Total', 0)
calc_total = (subtotal - descuento) + total_impuestos_trasladados
diff = abs(total - calc_total)
if diff > 0.5:
bad_cfds.append({
'pk': cfd.pk,
'original_id': cfd.original_id,
'total': total,
'descuento': descuento,
'diff': diff,
'subtotal': subtotal,
'total_impuestos_trasladados': total_impuestos_trasladados,
'calc_total': calc_total
})
return bad_cfds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment