FEAT: re-integracion de tax-api y simulador F29

This commit is contained in:
Nachou-u
2026-09-09 14:45:50 -03:00
parent 522d5337f4
commit f0a4fa64e8
9 changed files with 324 additions and 52 deletions
+74
View File
@@ -1014,3 +1014,77 @@ def api_sii_calculate_taxes(request):
'description': res['description']
})
from datetime import datetime, date
import calendar
from django.db.models import Sum
from procurement.models import PurchaseOrder
@login_required
def f29_simulator(request):
year = request.GET.get('year', date.today().year)
month = request.GET.get('month', date.today().month)
ventas_netas = request.GET.get('ventas_netas', 0)
ventas_exentas = request.GET.get('ventas_exentas', 0)
tasa_ppm = request.GET.get('tasa_ppm', 0.01)
try:
year, month = int(year), int(month)
ventas_netas = float(ventas_netas)
ventas_exentas = float(ventas_exentas)
tasa_ppm = float(tasa_ppm)
except ValueError:
year, month = date.today().year, date.today().month
ventas_netas, ventas_exentas, tasa_ppm = 0, 0, 0.01
_, last_day = calendar.monthrange(year, month)
start_date = date(year, month, 1)
end_date = date(year, month, last_day)
# 1. Compras Netas (Facturas con IVA 19%)
compras_expenses = Expense.objects.filter(
date__range=(start_date, end_date),
tax_type='IVA_19',
approval_status='LIBERADO_PAGADO'
).aggregate(total=Sum('amount_clp'))['total'] or 0
compras_po = PurchaseOrder.objects.filter(
order_date__range=(start_date, end_date),
status='LIBERADA_PAGADA'
).aggregate(total=Sum('net_amount_clp'))['total'] or 0
compras_netas = float(compras_expenses) + float(compras_po)
# 2. Honorarios
honorarios_expenses = Expense.objects.filter(
date__range=(start_date, end_date),
tax_type='HONORARIOS_13_75',
approval_status='LIBERADO_PAGADO'
).aggregate(total=Sum('tax_amount_clp'))['total'] or 0
retenciones_honorarios = float(honorarios_expenses)
f29_data = {
'ventas_netas': ventas_netas,
'compras_netas': compras_netas,
'ventas_exentas': ventas_exentas,
'compras_activo_fijo': 0,
'remanente_anterior': 0,
'tasa_ppm': tasa_ppm,
'retenciones_honorarios': retenciones_honorarios
}
simulation = SIIService.simulate_f29(f29_data)
context = {
'year': year,
'month': month,
'months': range(1, 13),
'years': range(date.today().year - 2, date.today().year + 2),
'ventas_netas': ventas_netas,
'ventas_exentas': ventas_exentas,
'tasa_ppm': tasa_ppm,
'simulation': simulation,
'compras_netas': compras_netas,
'retenciones_honorarios': retenciones_honorarios
}
return render(request, 'expenses/f29_simulator.html', context)