Formularios para cada uno de los tipos de importacion
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -28,6 +28,13 @@ seed = [
|
||||
"both",
|
||||
"imp",
|
||||
),
|
||||
(
|
||||
"REP",
|
||||
"REPARACION",
|
||||
"REPARACION DE ACTIVOS FIJOS",
|
||||
"fixed asset",
|
||||
"imp",
|
||||
),
|
||||
|
||||
# === TIPOS DE EXPORTACION ===
|
||||
("DONAC", "DONACION", "", "both", "exp"),
|
||||
|
||||
35
backend/sync_invoice_types.py
Normal file
35
backend/sync_invoice_types.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from core.database import CoreSessionLocal
|
||||
from api.v1.modules.public.reference_data.invoice_types.models import InvoiceType
|
||||
from api.v1.modules.public.reference_data.invoice_types.seed import seed
|
||||
|
||||
def sync_invoice_types():
|
||||
db = CoreSessionLocal()
|
||||
try:
|
||||
for s in seed:
|
||||
key, description, note, type_, operation = s
|
||||
obj = db.query(InvoiceType).filter(InvoiceType.key == key).first()
|
||||
if obj:
|
||||
print(f"Updating {key}...")
|
||||
obj.description = description
|
||||
obj.note = note
|
||||
obj.type = type_
|
||||
obj.operation = operation
|
||||
else:
|
||||
print(f"Creating {key}...")
|
||||
obj = InvoiceType(
|
||||
key=key,
|
||||
description=description,
|
||||
note=note,
|
||||
type=type_,
|
||||
operation=operation
|
||||
)
|
||||
db.add(obj)
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
db.rollback()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
sync_invoice_types()
|
||||
Reference in New Issue
Block a user