feature/catalogo-pedimento
This commit is contained in:
@@ -35,7 +35,7 @@ def load_pedimentos_fk_sets(
|
||||
valid_clave_regimen_tipo, # (pedimento_code, regimen_code, type_code)
|
||||
valid_aduana_seccion, # customs_code
|
||||
existing_pedimento_keys, # key strings para actualizar
|
||||
valid_anexo22_claves, # stub vacío hasta tener catálogo
|
||||
valid_anexo22_claves, # catálogo de transporte Anexo 22 (pedimento_transport_catalog.code)
|
||||
valid_patentes, # CustomsBroker.license (tenant/company)
|
||||
short_name_to_id, # short_name normalizado (upper) -> client id (primera aparición gana)
|
||||
"""
|
||||
@@ -48,6 +48,9 @@ def load_pedimentos_fk_sets(
|
||||
from api.v1.modules.public.reference_data.customs_sections.models import CustomsSection
|
||||
from api.v1.modules.public.reference_data.pedimento_codes.models import PedimentoCode
|
||||
from api.v1.modules.public.reference_data.pedimento_regimens.models import RegimenPedimento
|
||||
from api.v1.modules.public.reference_data.pedimento_transport_catalog.models import (
|
||||
PedimentoTransportCatalog,
|
||||
)
|
||||
|
||||
valid_client_ids: Set[int] = set()
|
||||
valid_regimes: Set[str] = set()
|
||||
@@ -96,6 +99,10 @@ def load_pedimentos_fk_sets(
|
||||
for cs in session.query(CustomsSection).all():
|
||||
valid_aduana_seccion.add(cs.customs_code.strip())
|
||||
|
||||
for tm in session.query(PedimentoTransportCatalog.code).all():
|
||||
if (tm[0] or "").strip():
|
||||
valid_anexo22_claves.add((tm[0] or "").strip().upper())
|
||||
|
||||
for cb in (
|
||||
session.query(CustomsBroker)
|
||||
.filter(
|
||||
|
||||
@@ -8,6 +8,9 @@ from api.v1.modules.public.reference_data.customs_sections.models import Customs
|
||||
from api.v1.modules.public.reference_data.code_pedimento_regimens.models import CodePedimentoRegimen
|
||||
from api.v1.modules.public.reference_data.transport_types.models import TransportType
|
||||
from api.v1.modules.public.reference_data.transport_modes.models import TransportMode
|
||||
from api.v1.modules.public.reference_data.pedimento_transport_catalog.models import (
|
||||
PedimentoTransportCatalog,
|
||||
)
|
||||
|
||||
# Import A76 Services
|
||||
from api.v1.modules.a76.customs_brokers.services import CustomsBrokerService
|
||||
@@ -19,6 +22,9 @@ from api.v1.modules.public.reference_data.customs_sections.dto import CustomsSec
|
||||
from api.v1.modules.public.reference_data.code_pedimento_regimens.dto import CodePedimentoRegimenDTO
|
||||
from api.v1.modules.public.reference_data.transport_types.dto import TransportTypeDTO
|
||||
from api.v1.modules.public.reference_data.transport_modes.dto import TransportModeDTO
|
||||
from api.v1.modules.public.reference_data.pedimento_transport_catalog.dto import (
|
||||
PedimentoTransportCatalogDTO,
|
||||
)
|
||||
from api.v1.modules.a76.customs_brokers.dto import CustomsBrokerResponseDTO
|
||||
from api.v1.modules.a76.clients_and_providers.dto import ClientProviderResponseDTO
|
||||
from .dtos.pedimentos import PedimentosResponse
|
||||
@@ -71,6 +77,16 @@ class PedimentoCatalogService:
|
||||
except Exception as e:
|
||||
print(f"Error fetching transport_modes: {e}")
|
||||
|
||||
try:
|
||||
response.pedimento_transport_catalog = [
|
||||
PedimentoTransportCatalogDTO.model_validate(obj)
|
||||
for obj in db.query(PedimentoTransportCatalog)
|
||||
.order_by(PedimentoTransportCatalog.code.asc())
|
||||
.all()
|
||||
]
|
||||
except Exception as e:
|
||||
print(f"Error fetching pedimento_transport_catalog: {e}")
|
||||
|
||||
# Helper to fetch tenant/company specific data
|
||||
def fetch_tenant_data():
|
||||
# Customs Brokers
|
||||
|
||||
@@ -10,27 +10,27 @@ class PedimentoTransportMeansBase(BaseModel):
|
||||
pedimento_id: Optional[int] = Field(None, description="Pedimento ID")
|
||||
tenant_id: Optional[int] = Field(None, description="Tenant ID")
|
||||
destination: Optional[int] = Field(None, description="Destination")
|
||||
entry_exit: Optional[str] = Field(None, max_length=2, description="Entry/exit")
|
||||
arrival: str = Field(..., max_length=2, description="Arrival")
|
||||
departure: str = Field(..., max_length=2, description="Departure")
|
||||
entry_exit: Optional[str] = Field(None, max_length=3, description="Entry/exit")
|
||||
arrival: str = Field(..., max_length=3, description="Arrival")
|
||||
departure: str = Field(..., max_length=3, description="Departure")
|
||||
|
||||
|
||||
class PedimentoTransportMeansCreate(BaseModel):
|
||||
"""Schema for creating a new Pedimento Transport Means - pedimento_id and tenant_id are set by backend"""
|
||||
|
||||
destination: Optional[int] = Field(None, description="Destination")
|
||||
entry_exit: Optional[str] = Field(None, max_length=2, description="Entry/exit")
|
||||
arrival: str = Field(..., max_length=2, description="Arrival")
|
||||
departure: str = Field(..., max_length=2, description="Departure")
|
||||
entry_exit: Optional[str] = Field(None, max_length=3, description="Entry/exit")
|
||||
arrival: str = Field(..., max_length=3, description="Arrival")
|
||||
departure: str = Field(..., max_length=3, description="Departure")
|
||||
|
||||
|
||||
class PedimentoTransportMeansUpdate(BaseModel):
|
||||
"""Schema for updating a Pedimento Transport Means"""
|
||||
|
||||
destination: Optional[int] = None
|
||||
entry_exit: Optional[str] = Field(None, max_length=2)
|
||||
arrival: Optional[str] = Field(None, max_length=2)
|
||||
departure: Optional[str] = Field(None, max_length=2)
|
||||
entry_exit: Optional[str] = Field(None, max_length=3)
|
||||
arrival: Optional[str] = Field(None, max_length=3)
|
||||
departure: Optional[str] = Field(None, max_length=3)
|
||||
|
||||
|
||||
class PedimentoTransportMeansResponse(PedimentoTransportMeansBase):
|
||||
|
||||
@@ -39,9 +39,9 @@ class PedimentoTransportMeans(Base, TenantScopedMixin, TimestampMixin):
|
||||
pedimento_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
|
||||
destination: Mapped[int] = mapped_column(SmallInteger)
|
||||
entry_exit: Mapped[str] = mapped_column(String(2))
|
||||
arrival: Mapped[str] = mapped_column(String(2))
|
||||
departure: Mapped[str] = mapped_column(String(2))
|
||||
entry_exit: Mapped[str] = mapped_column(String(3))
|
||||
arrival: Mapped[str] = mapped_column(String(3))
|
||||
departure: Mapped[str] = mapped_column(String(3))
|
||||
|
||||
pedimento: Mapped["Pedimentos"] = relationship(
|
||||
"Pedimentos", back_populates="pedimento_transport_means"
|
||||
|
||||
@@ -13,6 +13,9 @@ from api.v1.modules.a76.customs_brokers.dto import CustomsBrokerResponseDTO
|
||||
from api.v1.modules.a76.clients_and_providers.dto import ClientProviderResponseDTO
|
||||
from api.v1.modules.public.reference_data.transport_types.dto import TransportTypeDTO
|
||||
from api.v1.modules.public.reference_data.transport_modes.dto import TransportModeDTO
|
||||
from api.v1.modules.public.reference_data.pedimento_transport_catalog.dto import (
|
||||
PedimentoTransportCatalogDTO,
|
||||
)
|
||||
from .dtos.pedimentos import PedimentosResponse
|
||||
|
||||
|
||||
@@ -26,6 +29,7 @@ class PedimentoCatalogsResponse(BaseModel):
|
||||
clients: List[ClientProviderResponseDTO] = []
|
||||
transport_types: List[TransportTypeDTO] = []
|
||||
transport_modes: List[TransportModeDTO] = []
|
||||
pedimento_transport_catalog: List[PedimentoTransportCatalogDTO] = []
|
||||
|
||||
|
||||
class PedimentoCreationResponse(PedimentoCatalogsResponse):
|
||||
|
||||
@@ -227,7 +227,7 @@ BASE_SELECT = """
|
||||
COALESCE(icm.vucem_operation_num,'') AS "C41",
|
||||
COALESCE(cl.material_key,'') AS "C42",
|
||||
CONCAT(ped.year,'-',ped.customs_office,'-',ped.license,'-',ped.pedimento_number) AS "C43",
|
||||
'' AS "C44",
|
||||
COALESCE(ptc.payment_date_code, 'P') AS "C44",
|
||||
COALESCE(ilc.octave_fraction,'') AS "C45",
|
||||
'' AS "C47",
|
||||
COALESCE(ped.pedimento_code,'') AS "C48",
|
||||
@@ -243,6 +243,8 @@ BASE_JOINS = """
|
||||
JOIN a76.invoice_compliance_mx icm ON icm.invoice_id = ih.id
|
||||
LEFT JOIN a76.pedimentos ped ON ped.id = icm.pedimento_id
|
||||
LEFT JOIN a76.pedimento_dates pd ON pd.pedimento_id = ped.id
|
||||
LEFT JOIN a76.pedimento_transport_means ptm ON ptm.pedimento_id = ped.id
|
||||
LEFT JOIN public.pedimento_transport_catalog ptc ON ptc.code = ptm.entry_exit
|
||||
LEFT JOIN a76.classes cl ON cl.id = il.class_id
|
||||
LEFT JOIN a76.item_line_quantities ilq ON ilq.item_line_id = il.id
|
||||
LEFT JOIN a76.item_line_financials ilf ON ilf.item_line_id = il.id
|
||||
@@ -440,20 +442,21 @@ def _build_row(
|
||||
peso_usado = (cant_ret * peso_neto / cant_orig) if cant_orig != 0 else Decimal(0)
|
||||
peso_saldo = peso_neto - peso_usado
|
||||
|
||||
# TIPO DE CAMBIO — per Clarion logic:
|
||||
# Si TipoPedimentoTransporteE IN ('4','1','98E') → usar Fecha_Inicio, else Fecha_Pago
|
||||
# TIPO DE CAMBIO:
|
||||
# C44 now carries payment_date_code from pedimento_transport_catalog:
|
||||
# E => Fecha_Inicio, P => Fecha_Pago.
|
||||
# If explicitly "invoice_date", we use invoice_date (C11) instead.
|
||||
tc = Decimal(1)
|
||||
fecha_pago = row.get("C7")
|
||||
fecha_inicio = row.get("C9")
|
||||
fecha_factura= row.get("C11")
|
||||
transport_type = str(row.get("C44") or "")
|
||||
payment_date_code = str(row.get("C44") or "").upper()
|
||||
|
||||
tc_fecha_display = None
|
||||
# TIPO DE CAMBIO
|
||||
tc_fecha = None
|
||||
if use_fp:
|
||||
tc_fecha = fecha_inicio if transport_type in ("1", "4", "98E") else fecha_pago
|
||||
tc_fecha = fecha_inicio if payment_date_code == "E" else fecha_pago
|
||||
else:
|
||||
tc_fecha = fecha_factura
|
||||
|
||||
|
||||
Reference in New Issue
Block a user