mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-05-19 15:08:48 +02:00
All checks were successful
Deploy to VPS / deploy (push) Successful in 23s
Ahorro was already deducted from gross salary so displaying it in budget projections was misleading. This removes the Ahorro card, summary line, Proyecciones column, and Ahorro Anual card from the UI, and strips all savings fields from budget API responses. Adds SALARY TransactionType so salary deposits can be distinguished from generic DEPOSITO transfers. When a SALARY transaction arrives, the system auto-increments MEMP and MPAT savings account balances (+200K CRC each) once per month via an idempotent accrual log. New CRUD endpoints at /api/v1/savings-accrual/ allow manual correction of the accrual history. Feb+Mar 2026 are seeded as historical baseline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from pydantic import BaseModel
|
|
from sqlmodel import Session, col, func, select
|
|
|
|
from app.auth import get_current_user
|
|
from app.db import get_session
|
|
from app.models.models import Transaction, TransactionRead, TransactionType
|
|
from app.services.exchange_rate import get_converted_amount_expr
|
|
|
|
router = APIRouter(prefix="/salarios", tags=["salarios"])
|
|
|
|
SALARIO_TYPES = (TransactionType.SALARY, TransactionType.DEPOSITO)
|
|
|
|
|
|
class SalariosSummary(BaseModel):
|
|
count: int
|
|
total_amount: float
|
|
latest_date: Optional[datetime] = None
|
|
|
|
|
|
@router.get("/", response_model=list[TransactionRead])
|
|
def list_salarios(
|
|
limit: int = Query(default=50, le=500),
|
|
offset: int = 0,
|
|
session: Session = Depends(get_session),
|
|
_user: str = Depends(get_current_user),
|
|
):
|
|
query = (
|
|
select(Transaction)
|
|
.where(col(Transaction.transaction_type).in_(SALARIO_TYPES))
|
|
.order_by(col(Transaction.date).desc())
|
|
.offset(offset)
|
|
.limit(limit)
|
|
)
|
|
return session.exec(query).all()
|
|
|
|
|
|
@router.get("/summary", response_model=SalariosSummary)
|
|
def salarios_summary(
|
|
session: Session = Depends(get_session),
|
|
_user: str = Depends(get_current_user),
|
|
):
|
|
amount_crc = get_converted_amount_expr(session)
|
|
result = session.exec(
|
|
select(
|
|
func.count(),
|
|
func.coalesce(func.sum(amount_crc), 0),
|
|
func.max(Transaction.date),
|
|
).where(col(Transaction.transaction_type).in_(SALARIO_TYPES))
|
|
).first()
|
|
return SalariosSummary(
|
|
count=result[0] if result else 0,
|
|
total_amount=float(result[1]) if result else 0.0,
|
|
latest_date=result[2] if result else None,
|
|
)
|