feat(crm,ops): proceso comercial (solicitudes/RFQ, tarifas, cotizaciones) + Operaciones (embarques)
Diagrama 1 (CRM comercial) y Diagrama 2 (Operaciones) del spec de agente de carga: - crm.service_requests (RFQ) + crm.rate_requests (solicitud de tarifas a proveedores) - crm.quotes + crm.quote_items: conceptos costo/venta/margen, totales automáticos, estados borrador→enviada→aceptada/rechazada - schema ops: ops.shipments (booking, Cut Off, ETD/ETA, naviera/agente aduanal/destino) y ops.shipment_documents (MBL/HBL, MAWB/HAWB, CMR…) - liberar-a-operaciones: crea el embarque desde la cotización aceptada - migración b3c4d5e6f7a8, routers/permisos, seed del flujo completo - 52 tests pytest en verde Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
60
backend/tests/test_shipments.py
Normal file
60
backend/tests/test_shipments.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from api.v1.modules.crm.accounts import service as accounts_service
|
||||
from api.v1.modules.crm.accounts.dto import AccountCreate
|
||||
from api.v1.modules.crm.quotes import service as quotes_service
|
||||
from api.v1.modules.crm.quotes.dto import QuoteCreate
|
||||
from api.v1.modules.crm.service_requests import service as sr_service
|
||||
from api.v1.modules.crm.service_requests.dto import ServiceRequestCreate
|
||||
from api.v1.modules.ops.shipments import service
|
||||
from api.v1.modules.ops.shipments.dto import ShipmentCreate, ShipmentDocumentCreate
|
||||
|
||||
T, C = 1, 1
|
||||
|
||||
|
||||
def test_release_requires_accepted_quote(db):
|
||||
q = quotes_service.create_quote(db, QuoteCreate(reference="COT-A"), T, C)
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
service.create_shipment_from_quote(db, q.id, T, C)
|
||||
assert exc.value.status_code == 422 # aún no aceptada
|
||||
|
||||
|
||||
def test_release_from_accepted_quote_copies_data(db):
|
||||
acc = accounts_service.create_account(db, AccountCreate(name="Cliente"), T, C)
|
||||
sr = sr_service.create_service_request(
|
||||
db,
|
||||
ServiceRequestCreate(account_id=acc.id, operation_type="exportacion", transport_mode="maritimo",
|
||||
origin="Veracruz", destination="Rotterdam"),
|
||||
T, C,
|
||||
)
|
||||
q = quotes_service.create_quote(db, QuoteCreate(reference="COT-B", service_request_id=sr.id, account_id=acc.id), T, C)
|
||||
quotes_service.accept_quote(db, q.id, T, C)
|
||||
|
||||
shipment = service.create_shipment_from_quote(db, q.id, T, C, user_id="dev")
|
||||
assert shipment.quote_id == q.id
|
||||
assert shipment.account_id == acc.id
|
||||
assert shipment.operation_type == "exportacion"
|
||||
assert shipment.transport_mode == "maritimo"
|
||||
assert shipment.origin == "Veracruz"
|
||||
assert shipment.status == "abierta"
|
||||
# la solicitud queda liberada
|
||||
sr = sr_service.get_service_request(db, sr.id, T, C)
|
||||
assert sr.status == "liberada"
|
||||
|
||||
|
||||
def test_shipment_crud_and_documents(db):
|
||||
shipment = service.create_shipment(db, ShipmentCreate(reference="EMB-001", status="abierta", origin="MX"), T, C)
|
||||
assert shipment.id is not None
|
||||
doc = service.create_shipment_document(
|
||||
db, ShipmentDocumentCreate(shipment_id=shipment.id, doc_kind="master", doc_type="MBL", number="MBL123"), T, C
|
||||
)
|
||||
assert doc.doc_type == "MBL"
|
||||
docs = service.get_shipment_documents(db, T, C, shipment_id=shipment.id)
|
||||
assert len(docs) == 1
|
||||
|
||||
|
||||
def test_shipment_rejects_unknown_quote(db):
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
service.create_shipment(db, ShipmentCreate(quote_id=999), T, C)
|
||||
assert exc.value.status_code == 422
|
||||
Reference in New Issue
Block a user