Formularios para cada uno de los tipos de importacion

This commit is contained in:
2026-02-11 10:27:32 -06:00
parent 4190ac891e
commit ac47a99f1a
23 changed files with 1093 additions and 617 deletions

View File

@@ -14,7 +14,7 @@ def validate_create(db: Session, invoice: InvoiceHeaderCreate, tenant_id: int, c
if not invoice.invoice_type:
errors.add_required_error("invoice_type")
if not invoice.document_type:
if not invoice.document_type and invoice.invoice_type != "MEX":
errors.add_required_error("document_type")
if not invoice.invoice_number:

View File

@@ -224,9 +224,10 @@ def validate_update(
else:
invoice_data.compliance_mx.aduana = existing_invoice.compliance_mx.aduana if existing_invoice.compliance_mx else None
# Validar que aduana sea obligatorio
if not invoice_data.compliance_mx or not invoice_data.compliance_mx.aduana:
errors.add_required_error("aduana")
# Validar que aduana sea obligatorio (excepto para MEX)
if existing_invoice.invoice_type != "MEX":
if not invoice_data.compliance_mx or not invoice_data.compliance_mx.aduana:
errors.add_required_error("aduana")
# Columna AC: Sección de Despacho / Puerto de Entrada (Opcional)
if invoice_data.compliance_mx and invoice_data.compliance_mx.port_of_entry:

View File

@@ -58,7 +58,7 @@ class TransportType(str, Enum):
PLATES = "licence plates"
TRUCK = "truck"
VESSEL = "vessel"
BARGE = "rail barge"
BARGE = "rail_barge"
CONTAINER = "container"
AIRPLANE = "airplane"
GONDOLA = "gondola"
@@ -82,9 +82,10 @@ class InvoiceHeader(Base, TenantScopedMixin, TimestampMixin):
invoice_type: Mapped[str] = mapped_column(
ForeignKey("public.invoice_types.key")
) # TIPOFACTURA / TIPODOC
document_type: Mapped[str] = mapped_column(
ForeignKey("public.pedimento_regimens.code")
) # CLAVEDOCUMENTO / Clave de documento
document_type: Mapped[Optional[str]] = mapped_column(
ForeignKey("public.pedimento_regimens.code"), nullable=True
)
# CLAVEDOCUMENTO / Clave de documento
invoice_number: Mapped[str] = mapped_column(
String(100)
) # FACTURAIMPO/FACTURAEXPO/FACTURAREMISION/FACTURAENVIO/FACTURASALIDA
@@ -299,6 +300,9 @@ class InvoiceComplianceMx(Base, TenantScopedMixin, TimestampMixin):
act_value: Mapped[Optional[str]] = mapped_column(
String(5)
) # ACTVALOR / Actualizar valor
rule_3121_parties_ii: Mapped[Optional[bool]] = mapped_column(
Boolean, default=False, server_default="false"
) # REGLA3121PARTESII / Regla 3.1.21 Partes II
is_pedimento_pending: Mapped[Optional[bool]] = mapped_column(
Boolean, default=False, server_default="false"
) # PED_PENDIENTE_ASIGNAR (Mapear 1 -> True, 0 -> False)
@@ -375,7 +379,7 @@ class InvoiceComplianceMx(Base, TenantScopedMixin, TimestampMixin):
String(1)
) # RAZONEXPORTACION / Razón de exportación
signature_key: Mapped[Optional[str]] = mapped_column(
String(10)
String(100)
) # CLAVEFIRMA / Clave de firma
# SM specific

View File

@@ -22,8 +22,8 @@ class InvoiceHeaderBase(BaseModel):
invoice_type: Optional[str] = Field(
None, max_length=5, description="Invoice type key"
)
document_type: str = Field(
..., max_length=3, description="Document type (Regimen Aduanero)"
document_type: Optional[str] = Field(
None, max_length=3, description="Document type (Regimen Aduanero)"
)
invoice_number: Optional[str] = Field(
None, max_length=100, description="Invoice number"
@@ -139,6 +139,9 @@ class InvoiceComplianceMxBase(BaseModel):
which_exchange_rate: Optional[str] = Field(
None, max_length=5, description="Which exchange rate"
)
rule_3121_parties_ii: Optional[bool] = Field(
False, description="Is Rule 3.1.21 Parties II"
)
value_method: Optional[str] = Field(None, max_length=2, description="Value method")
act_value: Optional[str] = Field(None, max_length=5, description="Act value")
is_pedimento_pending: bool = Field(..., description="Is pedimento pending")
@@ -187,7 +190,7 @@ class InvoiceComplianceMxBase(BaseModel):
None, max_length=1, description="Reason for export"
)
signature_key: Optional[str] = Field(
None, max_length=10, description="Signature key"
None, max_length=100, description="Signature key"
)
sem_id: Optional[int] = Field(None, description="SEM ID")

View File

@@ -128,6 +128,10 @@ class InvoiceService:
invoice_dict = clean_dict(raw_invoice_dict)
invoice_dict["tenant_id"] = tenant_id
invoice_dict["company_id"] = company_id
# Ensure document_type respects DB constraints for MEX invoices (bypass clean_dict)
if invoice_dict.get("invoice_type") == "MEX" and not invoice_dict.get("document_type"):
invoice_dict["document_type"] = None
new_invoice = models.InvoiceHeader(**invoice_dict)

View File

@@ -28,6 +28,13 @@ seed = [
"both",
"imp",
),
(
"REP",
"REPARACION",
"REPARACION DE ACTIVOS FIJOS",
"fixed asset",
"imp",
),
# === TIPOS DE EXPORTACION ===
("DONAC", "DONACION", "", "both", "exp"),