feat: Números per machine, month by month (front 1b)
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 5m58s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m4s
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 5m58s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m4s
A new Números section, "Máquinas, mês a mês", one column per machine and a month at a time: metres printed, metres per hour and hours running (time shared by two orders counted once), hours stopped with their reasons; metres per film roll, ink per 100 m by colour, powder per 100 m; supplies, parts and total cost per metre; what the printed orders sold, the month's contribution and since installation; and the return in % and months to pay back once Gestão types the price. Refills stand for consumption. Every ratio without data shows "—". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,13 +3,16 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
|
||||
from .. import machine_log
|
||||
from .. import machine_log, machine_stats
|
||||
from ..core import db
|
||||
from ..core.auth import audit, can
|
||||
from ..core.auth import audit, can, operator
|
||||
from ..core.models import MachineEntry, MachineSheet
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# Números is read by management and by the seller and finance, who consult it.
|
||||
STATS_ROLES = ('superadmin', 'admin', 'gestao', 'vendedor', 'financeiro')
|
||||
|
||||
|
||||
def machine_row(c, mid):
|
||||
row = c.execute('SELECT id,name,price_cents,installed_on FROM dtf_local.machines WHERE id=%s',
|
||||
@@ -117,3 +120,18 @@ def snooze_alert(mid: UUID, key: str, request: Request, user=Depends(can('print'
|
||||
machine_log.snooze(c, mid, key, user)
|
||||
audit('machine_alert_snoozed', operator=user, machine=str(mid), alert=key)
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
@router.get('/api/operator/stats/machines')
|
||||
def machine_stats_month(request: Request, month: str | None = None, user=Depends(operator)):
|
||||
"""Números per machine, month by month (Fase 2, front 1b)."""
|
||||
if request.state.operator['role'] not in STATS_ROLES:
|
||||
raise HTTPException(403, 'Seu perfil não permite esta ação.')
|
||||
try:
|
||||
start, _ = machine_stats.month_bounds(month)
|
||||
except ValueError:
|
||||
raise HTTPException(422, 'Informe o mês como AAAA-MM.')
|
||||
if start > machine_stats.month_bounds(None)[0]:
|
||||
raise HTTPException(422, 'Esse mês ainda não começou.')
|
||||
with db.connect() as c:
|
||||
return machine_stats.report(c, month=month)
|
||||
|
||||
Reference in New Issue
Block a user