feat(ops,fin,crm): reglas de negocio del PDF (decisiones, cierre, facturación, continuidad, RBAC)
Cierra los huecos de la auditoría contra "SOFTWARE PARA AGENTES DE CARGA": - ops (Diag. 2/3): bitácora con puntos de decisión (kind=decision) y ciclo de corrección (parent_event_id/attempt) para ¿Cut Off? y ¿despacho autorizado? (R-E-05/13, R-I-06). Reprogramación de salida (previous_etd, R-E-06). Hitos operativos completos export/import. Cierre operativo con costos finales (close_shipment, R-E-22). - fin (Diag. 4): facturación con gate por cierre operativo y sin duplicar (R-F-01), costos de operación arrastrados (ops_cost_total, R-F-02), envío con PDF generado y guardado en MinIO (send_invoice + pdf.py sin dependencias, R-F-05) y revisión del cliente (en_revision_cliente + aprobación, R-F-06). - crm (Diag. 1): opportunity_id enlaza embudo→RFQ (R-C-02), contacto como etapa (first_contact_at, R-C-04), re-cotización (clone_quote + reopen, R-C-12). - transversal: catálogo de Incoterms y participantes/actores incl. autoridad aduanera (R-T-01/10), enforcement de permisos por carril (RBAC) con roles sembrados y dependencias dev-safe (R-T-07). - Migración d5e6f7a8b9c0 con downgrade. Seed extendido. 70 tests (12 nuevos). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
@@ -17,14 +19,19 @@ class ShipmentBase(BaseModel):
|
||||
status: str = Field("abierta", max_length=20)
|
||||
booking_number: str | None = Field(None, max_length=60)
|
||||
carrier_supplier_id: int | None = None
|
||||
ground_carrier_supplier_id: int | None = None
|
||||
customs_agent_id: int | None = None
|
||||
destination_agent_id: int | None = None
|
||||
cutoff_date: datetime | None = None
|
||||
pickup_at: datetime | None = None
|
||||
etd: date | None = None
|
||||
previous_etd: date | None = None
|
||||
eta: date | None = None
|
||||
vessel_flight: str | None = Field(None, max_length=120)
|
||||
container_number: str | None = Field(None, max_length=60)
|
||||
notes: str | None = None
|
||||
actual_cost_total: Decimal | None = None
|
||||
cost_currency: str | None = Field(None, max_length=3)
|
||||
owner_user_id: str | None = Field(None, max_length=64)
|
||||
|
||||
|
||||
@@ -44,9 +51,11 @@ class ShipmentUpdate(BaseModel):
|
||||
status: str | None = Field(None, max_length=20)
|
||||
booking_number: str | None = Field(None, max_length=60)
|
||||
carrier_supplier_id: int | None = None
|
||||
ground_carrier_supplier_id: int | None = None
|
||||
customs_agent_id: int | None = None
|
||||
destination_agent_id: int | None = None
|
||||
cutoff_date: datetime | None = None
|
||||
pickup_at: datetime | None = None
|
||||
etd: date | None = None
|
||||
eta: date | None = None
|
||||
vessel_flight: str | None = Field(None, max_length=120)
|
||||
@@ -55,10 +64,26 @@ class ShipmentUpdate(BaseModel):
|
||||
owner_user_id: str | None = Field(None, max_length=64)
|
||||
|
||||
|
||||
class ShipmentRescheduleInput(BaseModel):
|
||||
"""Reprogramación de salida cuando no se alcanza el Cut Off (R-E-06)."""
|
||||
etd: date | None = None
|
||||
cutoff_date: datetime | None = None
|
||||
reason: str | None = None
|
||||
|
||||
|
||||
class ShipmentCloseInput(BaseModel):
|
||||
"""Cierre operativo del embarque con costos finales (R-E-22)."""
|
||||
actual_cost_total: Decimal = Field(..., ge=0)
|
||||
cost_currency: str = Field("MXN", max_length=3)
|
||||
notes: str | None = None
|
||||
|
||||
|
||||
class ShipmentResponse(ShipmentBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
closed_at: datetime | None = None
|
||||
closed_by: str | None = None
|
||||
created_by: str | None = None
|
||||
updated_by: str | None = None
|
||||
tenant_id: int
|
||||
@@ -71,7 +96,11 @@ class ShipmentEventBase(BaseModel):
|
||||
shipment_id: int
|
||||
event_type: str | None = Field(None, max_length=60)
|
||||
title: str = Field(..., min_length=1, max_length=160)
|
||||
kind: str = Field("hito", max_length=20) # hito | decision
|
||||
status: str = Field("pendiente", max_length=20)
|
||||
outcome: str | None = Field(None, max_length=20) # autorizado | rechazado
|
||||
parent_event_id: int | None = None
|
||||
attempt: int = Field(1, ge=1)
|
||||
position: int = Field(0, ge=0)
|
||||
planned_date: datetime | None = None
|
||||
actual_date: datetime | None = None
|
||||
@@ -85,6 +114,7 @@ class ShipmentEventCreate(ShipmentEventBase):
|
||||
class ShipmentEventUpdate(BaseModel):
|
||||
event_type: str | None = Field(None, max_length=60)
|
||||
title: str | None = Field(None, min_length=1, max_length=160)
|
||||
kind: str | None = Field(None, max_length=20)
|
||||
status: str | None = Field(None, max_length=20)
|
||||
position: int | None = Field(None, ge=0)
|
||||
planned_date: datetime | None = None
|
||||
@@ -92,6 +122,12 @@ class ShipmentEventUpdate(BaseModel):
|
||||
notes: str | None = None
|
||||
|
||||
|
||||
class ShipmentEventDecisionInput(BaseModel):
|
||||
"""Resultado de un punto de decisión del flujo (R-E-13, R-E-05, R-I-06)."""
|
||||
outcome: Literal["autorizado", "rechazado"]
|
||||
notes: str | None = None
|
||||
|
||||
|
||||
class ShipmentEventResponse(ShipmentEventBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user