feat: update pedimento operation type to use string values and enhance validation logic
This commit is contained in:
@@ -21,4 +21,67 @@ def validate_common(db: Session, invoice: schemas.InvoiceHeaderCreate, tenant_id
|
||||
|
||||
if not invoice.compliance_mx.is_regime_change:
|
||||
if not pedimento.operation_type == 1:
|
||||
pass
|
||||
errors.add_error(
|
||||
field="compliance_mx.pedimento_id",
|
||||
message="El Pedimento seleccionado no corresponde a una Importación.",
|
||||
solution=["Selecciona un Pedimento de Importación"],
|
||||
code="INVALID_OPERATION_TYPE",
|
||||
value=pedimento.operation_type
|
||||
)
|
||||
else:
|
||||
if pedimento.regime in ["EXD", "ETE", "ETR"]:
|
||||
errors.add_error(
|
||||
field="compliance_mx.pedimento_id",
|
||||
message="El Pedimento seleccionado corresponde a una Exportación, no a una Importación.",
|
||||
solution=["Selecciona un Pedimento de Importación"],
|
||||
code="INVALID_REGIME",
|
||||
value=pedimento.regime
|
||||
)
|
||||
else:
|
||||
if invoice.document_type.upper().strip() != pedimento.regime:
|
||||
errors.add_error(
|
||||
field="document_type",
|
||||
message=f"El Tipo de Documento '{invoice.document_type}' no coincide con el Régimen '{pedimento.regime}' del Pedimento seleccionado.",
|
||||
solution=["Ajusta el Tipo de Documento o selecciona otro Pedimento"],
|
||||
code="REGIME_MISMATCH",
|
||||
value=invoice.document_type
|
||||
)
|
||||
else:
|
||||
if pedimento.operation_type != 2:
|
||||
errors.add_error(
|
||||
field="compliance_mx.pedimento_id",
|
||||
message="El Pedimento seleccionado no corresponde a una Importacion Definitiva.",
|
||||
solution=["Selecciona un Pedimento de Importacion Definitiva"],
|
||||
code="INVALID_OPERATION_TYPE",
|
||||
value=pedimento.operation_type
|
||||
)
|
||||
else:
|
||||
if pedimento.regime != "IMD":
|
||||
errors.add_error(
|
||||
field="compliance_mx.pedimento_id",
|
||||
message=f"El Pedimento {pedimento.customs_office}-{pedimento.license}-{pedimento.pedimento_number} no corresponde a una Importacion Definitiva.",
|
||||
solution=["Selecciona un Pedimento de Importacion Definitiva"],
|
||||
code="INVALID_REGIME",
|
||||
value=pedimento.regime
|
||||
)
|
||||
else:
|
||||
if invoice.document_type.upper().strip() != pedimento.regime:
|
||||
errors.add_error(
|
||||
field="document_type",
|
||||
message=f"El Tipo de Documento '{invoice.document_type}' no coincide con el Régimen '{pedimento.regime}' del Pedimento seleccionado.",
|
||||
solution=["Ajusta el Tipo de Documento o selecciona otro Pedimento"],
|
||||
code="REGIME_MISMATCH",
|
||||
value=invoice.document_type
|
||||
)
|
||||
else:
|
||||
if pedimento.pedimento_code not in ["A1", "A3"]:
|
||||
errors.add_error(
|
||||
field="compliance_mx.pedimento_id",
|
||||
message=f"El Pedimento seleccionado no es de tipo A1 o A3 requerido para Cambio de Régimen.",
|
||||
solution=["Selecciona un Pedimento de tipo A1 o A3"],
|
||||
code="INVALID_PEDEMENTO_CODE",
|
||||
value=pedimento.pedimento_code
|
||||
)
|
||||
|
||||
if pedimento.pedimento_type == "normal":
|
||||
pass
|
||||
@@ -1,33 +1,64 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from enum import IntEnum
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from .pedimento_config_additional import PedimentoConfigAdditionalCreate, PedimentoConfigAdditionalResponse
|
||||
from .pedimento_config_calculations import PedimentoConfigCalculationsCreate, PedimentoConfigCalculationsResponse
|
||||
from .pedimento_config_parameters import PedimentoConfigParametersCreate, PedimentoConfigParametersResponse
|
||||
from .pedimento_config_surcharges import PedimentoConfigSurchargesCreate, PedimentoConfigSurchargesResponse
|
||||
from .pedimento_config_update_rectification import PedimentoConfigUpdateRectificationCreate, PedimentoConfigUpdateRectificationResponse
|
||||
from .pedimento_config_updates import PedimentoConfigUpdatesCreate, PedimentoConfigUpdatesResponse
|
||||
from .pedimento_customs_offices import PedimentoCustomsOfficesCreate, PedimentoCustomsOfficesResponse
|
||||
from ..models.pedimentos import OperationType, PedimentoType
|
||||
from .pedimento_config_additional import (
|
||||
PedimentoConfigAdditionalCreate,
|
||||
PedimentoConfigAdditionalResponse,
|
||||
)
|
||||
from .pedimento_config_calculations import (
|
||||
PedimentoConfigCalculationsCreate,
|
||||
PedimentoConfigCalculationsResponse,
|
||||
)
|
||||
from .pedimento_config_parameters import (
|
||||
PedimentoConfigParametersCreate,
|
||||
PedimentoConfigParametersResponse,
|
||||
)
|
||||
from .pedimento_config_surcharges import (
|
||||
PedimentoConfigSurchargesCreate,
|
||||
PedimentoConfigSurchargesResponse,
|
||||
)
|
||||
from .pedimento_config_update_rectification import (
|
||||
PedimentoConfigUpdateRectificationCreate,
|
||||
PedimentoConfigUpdateRectificationResponse,
|
||||
)
|
||||
from .pedimento_config_updates import (
|
||||
PedimentoConfigUpdatesCreate,
|
||||
PedimentoConfigUpdatesResponse,
|
||||
)
|
||||
from .pedimento_customs_offices import (
|
||||
PedimentoCustomsOfficesCreate,
|
||||
PedimentoCustomsOfficesResponse,
|
||||
)
|
||||
from .pedimento_dates import PedimentoDatesCreate, PedimentoDatesResponse
|
||||
from .pedimento_decrementables import PedimentoDecrementablesCreate, PedimentoDecrementablesResponse
|
||||
from .pedimento_incrementables import PedimentoIncrementablesCreate, PedimentoIncrementablesResponse
|
||||
from .pedimento_decrementables import (
|
||||
PedimentoDecrementablesCreate,
|
||||
PedimentoDecrementablesResponse,
|
||||
)
|
||||
from .pedimento_incrementables import (
|
||||
PedimentoIncrementablesCreate,
|
||||
PedimentoIncrementablesResponse,
|
||||
)
|
||||
from .pedimento_indexes import PedimentoIndexesCreate, PedimentoIndexesResponse
|
||||
from .pedimento_payments import PedimentoPaymentsCreate, PedimentoPaymentsResponse
|
||||
from .pedimento_rectification_destination import PedimentoRectificationDestinationCreate, PedimentoRectificationDestinationResponse
|
||||
from .pedimento_rectification_origin import PedimentoRectificationOriginCreate, PedimentoRectificationOriginResponse
|
||||
from .pedimento_transport_means import PedimentoTransportMeansCreate, PedimentoTransportMeansResponse
|
||||
from .pedimento_rectification_destination import (
|
||||
PedimentoRectificationDestinationCreate,
|
||||
PedimentoRectificationDestinationResponse,
|
||||
)
|
||||
from .pedimento_rectification_origin import (
|
||||
PedimentoRectificationOriginCreate,
|
||||
PedimentoRectificationOriginResponse,
|
||||
)
|
||||
from .pedimento_transport_means import (
|
||||
PedimentoTransportMeansCreate,
|
||||
PedimentoTransportMeansResponse,
|
||||
)
|
||||
from .pedimento_validation import PedimentoValidationCreate, PedimentoValidationResponse
|
||||
|
||||
|
||||
class OperationType(IntEnum):
|
||||
EXPORTACION = 1
|
||||
IMPORTACION = 2
|
||||
|
||||
|
||||
class PedimentosBase(BaseModel):
|
||||
"""Base schema for Pedimentos"""
|
||||
|
||||
@@ -40,18 +71,17 @@ class PedimentosBase(BaseModel):
|
||||
None, max_length=7, description="Pedimento number"
|
||||
)
|
||||
client_id: Optional[int] = Field(None, description="Client ID")
|
||||
operation_type: Optional[int] = Field(None, description="Operation type")
|
||||
pedimento_type: Optional[str] = Field(None, max_length=20, description="Pedimento type")
|
||||
pedimento_code: str = Field(
|
||||
..., max_length=2, description="Pedimento key"
|
||||
)
|
||||
operation_type: Optional[OperationType] = Field(None, description="Operation type")
|
||||
pedimento_type: Optional[PedimentoType] = Field(None, description="Pedimento type")
|
||||
pedimento_code: str = Field(..., max_length=2, description="Pedimento key")
|
||||
regime: str = Field(..., max_length=3, description="Regime")
|
||||
status: Optional[str] = Field(None, max_length=30, description="Status")
|
||||
usd_value: Optional[Decimal] = Field(None, description="USD value")
|
||||
paid_price: Optional[Decimal] = Field(None, description="Paid price")
|
||||
gross_weight: Optional[Decimal] = Field(None, description="Gross weight")
|
||||
exchange_rate: Optional[Decimal] = Field(None, description="Exchange rate")
|
||||
observations: Optional[str] = Field(None, description="Observations")
|
||||
observations: Optional[str] = Field(None, description="Observations")
|
||||
|
||||
|
||||
class PedimentosCreate(PedimentosBase):
|
||||
"""Schema for creating a new Pedimento"""
|
||||
@@ -63,28 +93,31 @@ class PedimentosCreate(PedimentosBase):
|
||||
pedimento_number: str = Field(..., max_length=7, description="Pedimento number")
|
||||
client_id: int = Field(..., description="Client ID")
|
||||
# operation_type, pedimento_type, status son opcionales - se pueden llenar después
|
||||
pedimento_code: str = Field(
|
||||
..., max_length=2, description="Pedimento key"
|
||||
)
|
||||
regime: str = Field(..., max_length=3, description="Regime")
|
||||
|
||||
pedimento_code: str = Field(..., max_length=2, description="Pedimento key")
|
||||
regime: str = Field(..., max_length=3, description="Regime")
|
||||
|
||||
pedimento_dates: Optional[PedimentoDatesCreate] = None
|
||||
pedimento_decrementables: Optional[PedimentoDecrementablesCreate] = None
|
||||
pedimento_incrementables: Optional[PedimentoIncrementablesCreate] = None
|
||||
pedimento_indexes: Optional[PedimentoIndexesCreate] = None
|
||||
pedimento_validation: Optional[PedimentoValidationCreate] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesCreate] = None
|
||||
pedimento_validation: Optional[PedimentoValidationCreate] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesCreate] = None
|
||||
pedimento_payments: Optional[PedimentoPaymentsCreate] = None
|
||||
pedimento_rectification_destination: Optional[PedimentoRectificationDestinationCreate] = None
|
||||
pedimento_rectification_destination: Optional[
|
||||
PedimentoRectificationDestinationCreate
|
||||
] = None
|
||||
pedimento_rectification_origin: Optional[PedimentoRectificationOriginCreate] = None
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansCreate] = None
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansCreate] = None
|
||||
pedimento_config_additional: Optional[PedimentoConfigAdditionalCreate] = None
|
||||
pedimento_config_calculations: Optional[PedimentoConfigCalculationsCreate] = None
|
||||
pedimento_config_parameters: Optional[PedimentoConfigParametersCreate] = None
|
||||
pedimento_config_surcharges: Optional[PedimentoConfigSurchargesCreate] = None
|
||||
pedimento_config_update_rectification: Optional[PedimentoConfigUpdateRectificationCreate] = None
|
||||
pedimento_config_update_rectification: Optional[
|
||||
PedimentoConfigUpdateRectificationCreate
|
||||
] = None
|
||||
pedimento_config_updates: Optional[PedimentoConfigUpdatesCreate] = None
|
||||
|
||||
|
||||
class PedimentosUpdate(BaseModel):
|
||||
"""Schema for updating a Pedimento"""
|
||||
|
||||
@@ -93,7 +126,7 @@ class PedimentosUpdate(BaseModel):
|
||||
license: Optional[str] = Field(None, max_length=4)
|
||||
pedimento_number: Optional[str] = Field(None, max_length=7)
|
||||
client_id: Optional[int] = None
|
||||
operation_type: Optional[int] = None
|
||||
operation_type: Optional[str] = Field(None, max_length=3)
|
||||
pedimento_type: Optional[str] = Field(None, max_length=20)
|
||||
pedimento_code: Optional[str] = Field(None, max_length=2)
|
||||
regime: Optional[str] = Field(None, max_length=3)
|
||||
@@ -103,23 +136,27 @@ class PedimentosUpdate(BaseModel):
|
||||
gross_weight: Optional[Decimal] = None
|
||||
exchange_rate: Optional[Decimal] = None
|
||||
observations: Optional[str] = None
|
||||
|
||||
|
||||
# Sub-resources
|
||||
pedimento_dates: Optional[PedimentoDatesCreate] = None
|
||||
pedimento_decrementables: Optional[PedimentoDecrementablesCreate] = None
|
||||
pedimento_incrementables: Optional[PedimentoIncrementablesCreate] = None
|
||||
pedimento_indexes: Optional[PedimentoIndexesCreate] = None
|
||||
pedimento_validation: Optional[PedimentoValidationCreate] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesCreate] = None
|
||||
pedimento_validation: Optional[PedimentoValidationCreate] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesCreate] = None
|
||||
pedimento_payments: Optional[PedimentoPaymentsCreate] = None
|
||||
pedimento_rectification_destination: Optional[PedimentoRectificationDestinationCreate] = None
|
||||
pedimento_rectification_destination: Optional[
|
||||
PedimentoRectificationDestinationCreate
|
||||
] = None
|
||||
pedimento_rectification_origin: Optional[PedimentoRectificationOriginCreate] = None
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansCreate] = None
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansCreate] = None
|
||||
pedimento_config_additional: Optional[PedimentoConfigAdditionalCreate] = None
|
||||
pedimento_config_calculations: Optional[PedimentoConfigCalculationsCreate] = None
|
||||
pedimento_config_parameters: Optional[PedimentoConfigParametersCreate] = None
|
||||
pedimento_config_surcharges: Optional[PedimentoConfigSurchargesCreate] = None
|
||||
pedimento_config_update_rectification: Optional[PedimentoConfigUpdateRectificationCreate] = None
|
||||
pedimento_config_update_rectification: Optional[
|
||||
PedimentoConfigUpdateRectificationCreate
|
||||
] = None
|
||||
pedimento_config_updates: Optional[PedimentoConfigUpdatesCreate] = None
|
||||
|
||||
|
||||
@@ -129,22 +166,28 @@ class PedimentosResponse(PedimentosBase):
|
||||
id: int
|
||||
tenant_id: int
|
||||
created_at: datetime
|
||||
|
||||
|
||||
pedimento_dates: Optional[PedimentoDatesResponse] = None
|
||||
pedimento_decrementables: Optional[PedimentoDecrementablesResponse] = None
|
||||
pedimento_incrementables: Optional[PedimentoIncrementablesResponse] = None
|
||||
pedimento_indexes: Optional[PedimentoIndexesResponse] = None
|
||||
pedimento_validation: Optional[PedimentoValidationResponse] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesResponse] = None
|
||||
pedimento_validation: Optional[PedimentoValidationResponse] = None
|
||||
pedimento_customs_offices: Optional[PedimentoCustomsOfficesResponse] = None
|
||||
pedimento_payments: Optional[PedimentoPaymentsResponse] = None
|
||||
pedimento_rectification_destination: Optional[PedimentoRectificationDestinationResponse] = None
|
||||
pedimento_rectification_origin: Optional[PedimentoRectificationOriginResponse] = None
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansResponse] = None
|
||||
pedimento_rectification_destination: Optional[
|
||||
PedimentoRectificationDestinationResponse
|
||||
] = None
|
||||
pedimento_rectification_origin: Optional[PedimentoRectificationOriginResponse] = (
|
||||
None
|
||||
)
|
||||
pedimento_transport_means: Optional[PedimentoTransportMeansResponse] = None
|
||||
pedimento_config_additional: Optional[PedimentoConfigAdditionalResponse] = None
|
||||
pedimento_config_calculations: Optional[PedimentoConfigCalculationsResponse] = None
|
||||
pedimento_config_parameters: Optional[PedimentoConfigParametersResponse] = None
|
||||
pedimento_config_surcharges: Optional[PedimentoConfigSurchargesResponse] = None
|
||||
pedimento_config_update_rectification: Optional[PedimentoConfigUpdateRectificationResponse] = None
|
||||
pedimento_config_update_rectification: Optional[
|
||||
PedimentoConfigUpdateRectificationResponse
|
||||
] = None
|
||||
pedimento_config_updates: Optional[PedimentoConfigUpdatesResponse] = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from decimal import Decimal
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
|
||||
@@ -62,6 +63,17 @@ if TYPE_CHECKING:
|
||||
)
|
||||
|
||||
|
||||
class PedimentoType(str, Enum):
|
||||
NORMAL = "normal"
|
||||
CONSOLIDATED = "consolidated"
|
||||
COMPLEMENTARY = "complementary"
|
||||
AUTOMOBILE = "automobile"
|
||||
|
||||
class OperationType(str, Enum):
|
||||
IMP = "imp" # Importación
|
||||
EXP = "exp" # Exportación
|
||||
|
||||
|
||||
class Pedimentos(Base, TenantScopedMixin, TimestampMixin):
|
||||
__tablename__ = "pedimentos"
|
||||
__table_args__ = (
|
||||
@@ -99,8 +111,8 @@ class Pedimentos(Base, TenantScopedMixin, TimestampMixin):
|
||||
license: Mapped[str] = mapped_column(String(4))
|
||||
pedimento_number: Mapped[str] = mapped_column(String(7))
|
||||
client_id: Mapped[int] = mapped_column(Integer)
|
||||
operation_type: Mapped[int] = mapped_column(Integer)
|
||||
pedimento_type: Mapped[str] = mapped_column(String(20))
|
||||
operation_type: Mapped[OperationType] = mapped_column(String(3))
|
||||
pedimento_type: Mapped[PedimentoType] = mapped_column(String(20))
|
||||
pedimento_code: Mapped[str] = mapped_column(String(2))
|
||||
regime: Mapped[str] = mapped_column(String(3))
|
||||
status: Mapped[Optional[str]] = mapped_column(String(30))
|
||||
@@ -111,59 +123,104 @@ class Pedimentos(Base, TenantScopedMixin, TimestampMixin):
|
||||
observations: Mapped[Optional[str]] = mapped_column(Text)
|
||||
|
||||
pedimento_config_additional: Mapped["PedimentoConfigAdditional"] = relationship(
|
||||
"PedimentoConfigAdditional", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigAdditional",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_config_calculations: Mapped["PedimentoConfigCalculations"] = relationship(
|
||||
"PedimentoConfigCalculations", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigCalculations",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_config_parameters: Mapped["PedimentoConfigParameters"] = relationship(
|
||||
"PedimentoConfigParameters", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigParameters",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_config_surcharges: Mapped["PedimentoConfigSurcharges"] = relationship(
|
||||
"PedimentoConfigSurcharges", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigSurcharges",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_config_update_rectification: Mapped[
|
||||
"PedimentoConfigUpdateRectification"
|
||||
] = relationship(
|
||||
"PedimentoConfigUpdateRectification", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigUpdateRectification",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_config_updates: Mapped["PedimentoConfigUpdates"] = relationship(
|
||||
"PedimentoConfigUpdates", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoConfigUpdates",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_customs_offices: Mapped["PedimentoCustomsOffices"] = relationship(
|
||||
"PedimentoCustomsOffices", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoCustomsOffices",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_dates: Mapped["PedimentoDates"] = relationship(
|
||||
"PedimentoDates", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoDates",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_decrementables: Mapped["PedimentoDecrementables"] = relationship(
|
||||
"PedimentoDecrementables", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoDecrementables",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_incrementables: Mapped["PedimentoIncrementables"] = relationship(
|
||||
"PedimentoIncrementables", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoIncrementables",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_indexes: Mapped["PedimentoIndexes"] = relationship(
|
||||
"PedimentoIndexes", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoIndexes",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_payments: Mapped["PedimentoPayments"] = relationship(
|
||||
"PedimentoPayments", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoPayments",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_rectification_destination: Mapped["PedimentoRectificationDestination"] = (
|
||||
relationship(
|
||||
"PedimentoRectificationDestination",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan"
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
)
|
||||
pedimento_rectification_origin: Mapped["PedimentoRectificationOrigin"] = (
|
||||
relationship(
|
||||
"PedimentoRectificationOrigin", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoRectificationOrigin",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
)
|
||||
pedimento_transport_means: Mapped["PedimentoTransportMeans"] = relationship(
|
||||
"PedimentoTransportMeans", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoTransportMeans",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
pedimento_validation: Mapped["PedimentoValidation"] = relationship(
|
||||
"PedimentoValidation", uselist=False, back_populates="pedimento", cascade="all, delete-orphan"
|
||||
"PedimentoValidation",
|
||||
uselist=False,
|
||||
back_populates="pedimento",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ export interface Pedimento {
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
operation_type?: string | null;
|
||||
pedimento_type?: string | null;
|
||||
pedimento_code?: string | null;
|
||||
regime?: string | null;
|
||||
@@ -198,7 +198,7 @@ export interface CreatePedimentoData {
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
operation_type?: string | null;
|
||||
pedimento_type?: string | null;
|
||||
pedimento_code?: string | null;
|
||||
regime?: string | null;
|
||||
@@ -231,7 +231,7 @@ export interface UpdatePedimentoData {
|
||||
license?: string | null;
|
||||
pedimento_number?: string | null;
|
||||
client_id?: number | null;
|
||||
operation_type?: number | null;
|
||||
operation_type?: string | null;
|
||||
pedimento_type?: string | null;
|
||||
pedimento_code?: string | null;
|
||||
regime?: string | null;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
trailers?: any[];
|
||||
customsSections?: any[];
|
||||
codePedimentoRegimens?: any[];
|
||||
defaultOperationType?: number | null;
|
||||
defaultOperationType?: string | null;
|
||||
defaultInvoiceType?: string | null;
|
||||
operationType?: number | null;
|
||||
exchangeRate?: number | null;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
formData?: any;
|
||||
invoiceTypes?: InvoiceType[];
|
||||
pedimentos?: Pedimento[];
|
||||
defaultOperationType?: number | null;
|
||||
defaultOperationType?: string | null;
|
||||
defaultInvoiceType?: string | null;
|
||||
} = $props();
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
}
|
||||
|
||||
if (!formData) {
|
||||
let operationType: number | null = null;
|
||||
let operationType: string | null = null;
|
||||
if (invoice?.operation_type) {
|
||||
operationType = invoice.operation_type === 'exp' ? 1 : 2;
|
||||
operationType = invoice.operation_type;
|
||||
} else if (defaultOperationType !== undefined) {
|
||||
operationType = defaultOperationType ?? null;
|
||||
}
|
||||
@@ -73,21 +73,21 @@
|
||||
<Label for="operation_type" class="text-xs">Tipo de Operación<span class="text-red-500">*</span></Label>
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={formData.operation_type !== null ? String(formData.operation_type) : ''}
|
||||
value={formData.operation_type || ''}
|
||||
onValueChange={(v) => {
|
||||
formData.operation_type = v ? parseInt(v) : null;
|
||||
formData.operation_type = v;
|
||||
}}
|
||||
>
|
||||
<Select.Trigger id="operation_type" class="h-8 text-sm">
|
||||
<span class="truncate">
|
||||
{formData.operation_type !== null
|
||||
? (formData.operation_type === 1 ? 'Exp' : 'Imp')
|
||||
{formData.operation_type
|
||||
? (formData.operation_type === 'exp' ? 'Exp' : 'Imp')
|
||||
: '...'}
|
||||
</span>
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
<Select.Item value="1">Exportación</Select.Item>
|
||||
<Select.Item value="2">Importación</Select.Item>
|
||||
<Select.Item value="exp">Exportación</Select.Item>
|
||||
<Select.Item value="imp">Importación</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
|
||||
@@ -40,12 +40,12 @@
|
||||
// Mapear el tipo de pedimento a un nombre legible
|
||||
const tipoPedimentoNombre = $derived.by(() => {
|
||||
switch(pedimentoType?.toLowerCase()) {
|
||||
case 'automovil':
|
||||
return 'Automóvil';
|
||||
case 'complementario':
|
||||
return 'Complementario';
|
||||
case 'consolidado':
|
||||
return 'Consolidado';
|
||||
case 'automobile':
|
||||
return 'Automobile';
|
||||
case 'complementary':
|
||||
return 'Complementary';
|
||||
case 'consolidated':
|
||||
return 'Consolidated';
|
||||
case 'normal':
|
||||
return 'Normal';
|
||||
default:
|
||||
|
||||
@@ -44,32 +44,32 @@
|
||||
.map(code => ({ code, label: code }))
|
||||
);
|
||||
|
||||
// Funciones de mapeo entre type_code (E/I) y operation_type (1/2)
|
||||
function typeCodeToOperationType(typeCode: string | null | undefined): number | null {
|
||||
// Funciones de mapeo entre type_code (E/I) y operation_type (exp/imp)
|
||||
function typeCodeToOperationType(typeCode: string | null | undefined): string | null {
|
||||
if (!typeCode) return null;
|
||||
// E = Exportación = 1, I = Importación = 2
|
||||
if (typeCode.toUpperCase() === 'E') return 1;
|
||||
if (typeCode.toUpperCase() === 'I') return 2;
|
||||
// E = Exportación = exp, I = Importación = imp
|
||||
if (typeCode.toUpperCase() === 'E') return 'exp';
|
||||
if (typeCode.toUpperCase() === 'I') return 'imp';
|
||||
return null;
|
||||
}
|
||||
|
||||
function operationTypeToTypeCode(operationType: number | null | undefined): string | null {
|
||||
function operationTypeToTypeCode(operationType: string | null | undefined): string | null {
|
||||
if (operationType === null || operationType === undefined) return null;
|
||||
// 1 = Exportación = E, 2 = Importación = I
|
||||
if (operationType === 1) return 'E';
|
||||
if (operationType === 2) return 'I';
|
||||
// exp = Exportación = E, imp = Importación = I
|
||||
if (operationType === 'exp') return 'E';
|
||||
if (operationType === 'imp') return 'I';
|
||||
return null;
|
||||
}
|
||||
|
||||
// Opciones constantes
|
||||
const operationOptions = [
|
||||
{ value: 1, label: 'Exportación' },
|
||||
{ value: 2, label: 'Importación' },
|
||||
{ value: 'exp', label: 'Exportación' },
|
||||
{ value: 'imp', label: 'Importación' },
|
||||
];
|
||||
|
||||
// Track previous values to detect changes
|
||||
let previousPedimentoCode = $state('');
|
||||
let previousOperationType = $state<number | null>(null);
|
||||
let previousOperationType = $state<string | null>(null);
|
||||
|
||||
// Opciones filtradas para Régimen y Tipo de Operación basadas en las selecciones actuales
|
||||
// NOTA: La Clave NO se filtra, siempre muestra todas las opciones
|
||||
@@ -284,9 +284,9 @@
|
||||
];
|
||||
|
||||
const pedimentoTypeOptions = [
|
||||
{ value: 'automovil', label: 'Automóvil' },
|
||||
{ value: 'complementario', label: 'Complementario' },
|
||||
{ value: 'consolidado', label: 'Consolidado' },
|
||||
{ value: 'automobile', label: 'Automóvil' },
|
||||
{ value: 'complementary', label: 'Complementario' },
|
||||
{ value: 'consolidated', label: 'Consolidado' },
|
||||
{ value: 'normal', label: 'Normal' }
|
||||
];
|
||||
|
||||
@@ -460,15 +460,15 @@
|
||||
<Label for="operation_type">Tipo de Operación</Label>
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={String(formData.operation_type ?? '')}
|
||||
onValueChange={(v: string) => formData.operation_type = v ? Number(v) : null}
|
||||
value={formData.operation_type || ''}
|
||||
onValueChange={(v: string) => formData.operation_type = v || null}
|
||||
>
|
||||
<Select.Trigger class="w-full">
|
||||
{operationOptions.find(o => o.value === formData.operation_type)?.label || 'Seleccionar...'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each filteredOperationTypes as option}
|
||||
<Select.Item value={String(option.value)} label={option.label} />
|
||||
<Select.Item value={option.value} label={option.label} />
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
companies?: any[];
|
||||
authenticated?: boolean;
|
||||
filters?: {
|
||||
operation_type?: number | null;
|
||||
operation_type?: string | null;
|
||||
invoice_type?: string | null;
|
||||
};
|
||||
pedimentos?: any[];
|
||||
|
||||
Reference in New Issue
Block a user