Solucion a tipos de datos, blindaje y resoluciones con el token expirado
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
import base64
|
||||
import logging
|
||||
from core.celery_app import celery_app
|
||||
|
||||
@@ -3,6 +3,7 @@ from celery import shared_task
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import CoreSessionLocal as SessionLocal
|
||||
from .service import DescargaReportService # FORCE RELOAD 2
|
||||
from fastapi import HTTPException
|
||||
import base64
|
||||
import traceback
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from celery import Task
|
||||
from fastapi import HTTPException
|
||||
from core.celery_app import celery_app
|
||||
from core.celery_app import celery_app
|
||||
from core.database import get_core_db as get_db
|
||||
|
||||
@@ -15,7 +15,7 @@ class ClienteSchema(BaseModel):
|
||||
ciudad: Optional[str] = ""
|
||||
estado: Optional[str] = ""
|
||||
pais: Optional[str] = ""
|
||||
tax_id: str
|
||||
tax_id: Optional[str] = ""
|
||||
programa: Optional[str] = ""
|
||||
autorizacion: Optional[str] = ""
|
||||
prosec: Optional[str] = ""
|
||||
@@ -23,7 +23,7 @@ class ClienteSchema(BaseModel):
|
||||
cert: Optional[str] = ""
|
||||
|
||||
# Si llega un None, lo convertimos en "" automáticamente
|
||||
@field_validator('direccion', 'nombre', mode='before')
|
||||
@field_validator('direccion', 'nombre', 'tax_id', mode='before')
|
||||
@classmethod
|
||||
def prevent_none(cls, v):
|
||||
return v or ""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
import base64
|
||||
import logging
|
||||
from core.celery_app import celery_app
|
||||
@@ -43,10 +44,12 @@ def generar_pdf_consolidado_async(self, invoice_id: int, company_id: int):
|
||||
"media_type": media_type
|
||||
}
|
||||
|
||||
except HTTPException as e:
|
||||
logger.error(f"HTTP Error en Celery Worker: {str(e.detail)}")
|
||||
return {"status": "error", "message": str(e.detail)}
|
||||
except Exception as e:
|
||||
logger.error(f"Error en Celery Worker: {str(e)}")
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
return {"status": "error", "message": f"Error interno en el servidor de reportes: {str(e)}"}
|
||||
finally:
|
||||
# 5. MUY IMPORTANTE: Cerramos la conexión para no saturar Postgres
|
||||
db.close()
|
||||
|
||||
@@ -15,7 +15,7 @@ class ClienteSchema(BaseModel):
|
||||
ciudad: Optional[str] = ""
|
||||
estado: Optional[str] = ""
|
||||
pais: Optional[str] = ""
|
||||
tax_id: str
|
||||
tax_id: Optional[str] = ""
|
||||
programa: Optional[str] = ""
|
||||
autorizacion: Optional[str] = ""
|
||||
prosec: Optional[str] = ""
|
||||
@@ -23,7 +23,7 @@ class ClienteSchema(BaseModel):
|
||||
cert: Optional[str] = ""
|
||||
|
||||
# Si llega un None, lo convertimos en "" automáticamente
|
||||
@field_validator('direccion', 'nombre', mode='before')
|
||||
@field_validator('direccion', 'nombre', 'tax_id', mode='before')
|
||||
@classmethod
|
||||
def prevent_none(cls, v):
|
||||
return v or ""
|
||||
|
||||
@@ -12,14 +12,14 @@ class ClienteSchema(BaseModel):
|
||||
ciudad: Optional[str] = ""
|
||||
estado: Optional[str] = ""
|
||||
pais: Optional[str] = ""
|
||||
tax_id: str
|
||||
tax_id: Optional[str] = ""
|
||||
programa: Optional[str] = ""
|
||||
autorizacion: Optional[str] = ""
|
||||
prosec: Optional[str] = ""
|
||||
reg_emp: Optional[str] = ""
|
||||
cert: Optional[str] = ""
|
||||
|
||||
@field_validator('direccion', 'nombre', mode='before')
|
||||
@field_validator('direccion', 'nombre', 'tax_id', mode='before')
|
||||
@classmethod
|
||||
def prevent_none(cls, v):
|
||||
return v or ""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
import base64
|
||||
from core.celery_app import celery_app
|
||||
from core.database import CoreSessionLocal
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
from core.celery_app import celery_app
|
||||
from core.database import get_core_db as get_db
|
||||
from .service import Mainx30DefinitiveService
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from celery import Task
|
||||
from fastapi import HTTPException
|
||||
from core.celery_app import celery_app
|
||||
from core.celery_app import celery_app
|
||||
from core.database import get_core_db as get_db
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
from core.celery_app import celery_app
|
||||
from core.database import CoreSessionLocal
|
||||
from .service import WinsaaiService
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from fastapi import HTTPException
|
||||
import logging
|
||||
from typing import List
|
||||
import base64
|
||||
|
||||
@@ -16,7 +16,19 @@ export const avisoConsolidadoReportsApi = {
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación del Aviso Consolidado');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación del Aviso Consolidado';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -29,7 +41,19 @@ export const avisoConsolidadoReportsApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado del Aviso Consolidado');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado del Aviso Consolidado';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,7 +16,19 @@ export const consolidatedReportsApi = {
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación del consolidado');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación del consolidado';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -29,7 +41,19 @@ export const consolidatedReportsApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado del consolidado');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado del consolidado';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,7 +17,19 @@ export const dischargeReportsApi = {
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación del Reporte de Descarga');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación del Reporte de Descarga';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -30,7 +42,19 @@ export const dischargeReportsApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado del Reporte de Descarga');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado del Reporte de Descarga';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_URL || '';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export const invoicesReportsApi = {
|
||||
|
||||
@@ -9,62 +8,33 @@ export const invoicesReportsApi = {
|
||||
invoice_type: invoiceType,
|
||||
currency_code: currency
|
||||
});
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/facturas/${invoiceId}/download-async?${params.toString()}`;
|
||||
const endpoint = `/v1/a76/reports/importacion/facturas/${invoiceId}/download-async?${params.toString()}`;
|
||||
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación');
|
||||
return await response.json();
|
||||
const res = await api.post(endpoint, {});
|
||||
if (res.error) throw new Error(res.error || 'Error al iniciar la generación');
|
||||
return res.data;
|
||||
},
|
||||
|
||||
getTaskStatus: async (taskId: string) => {
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/facturas/tasks/${taskId}`;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado');
|
||||
return await response.json();
|
||||
const endpoint = `/v1/a76/reports/importacion/facturas/tasks/${taskId}`;
|
||||
const res = await api.get(endpoint);
|
||||
if (res.error) throw new Error(res.error || 'Error al consultar estado');
|
||||
return res.data;
|
||||
},
|
||||
|
||||
triggerPackingListGeneration: async (invoiceId: number, companyId: number) => {
|
||||
const params = new URLSearchParams({ company_id: companyId.toString() });
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/packing-lists/${invoiceId}/download-async?${params.toString()}`;
|
||||
const endpoint = `/v1/a76/reports/importacion/packing-lists/${invoiceId}/download-async?${params.toString()}`;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación de Packing List');
|
||||
return await response.json();
|
||||
const res = await api.post(endpoint, {});
|
||||
if (res.error) throw new Error(res.error || 'Error al iniciar la generación de Packing List');
|
||||
return res.data;
|
||||
},
|
||||
|
||||
getPackingListTaskStatus: async (taskId: string) => {
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/importacion/packing-lists/tasks/${taskId}`;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado de Packing List');
|
||||
return await response.json();
|
||||
const endpoint = `/v1/a76/reports/importacion/packing-lists/tasks/${taskId}`;
|
||||
const res = await api.get(endpoint);
|
||||
if (res.error) throw new Error(res.error || 'Error al consultar estado de Packing List');
|
||||
return res.data;
|
||||
}
|
||||
};
|
||||
@@ -16,7 +16,19 @@ export const reportsTransmissionApi = {
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación del archivo de transmisión');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación del archivo de transmisión';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -29,7 +41,19 @@ export const reportsTransmissionApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado de la transmisión');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado de la transmisión';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -46,7 +70,19 @@ export const reportsTransmissionApi = {
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación temporal');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación temporal';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -59,7 +95,19 @@ export const reportsTransmissionApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado de la transmisión temporal');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado de la transmisión temporal';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -76,7 +124,19 @@ export const reportsTransmissionApi = {
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación definitiva');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación definitiva';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -89,7 +149,19 @@ export const reportsTransmissionApi = {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Error al consultar estado de la transmisión definitiva');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado de la transmisión definitiva';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,19 @@ export const reportsWinsaaiApi = {
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación WINSAAI de facturas');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación WINSAAI de facturas';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -33,7 +45,19 @@ export const reportsWinsaaiApi = {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
if (!response.ok) throw new Error('Error al consultar estado WINSAAI de facturas');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado WINSAAI de facturas';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -61,7 +85,19 @@ export const reportsWinsaaiApi = {
|
||||
is_by_class: isByClass
|
||||
})
|
||||
});
|
||||
if (!response.ok) throw new Error('Error al iniciar la generación WINSAAI de pedimentos');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al iniciar la generación WINSAAI de pedimentos';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
@@ -71,7 +107,19 @@ export const reportsWinsaaiApi = {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
if (!response.ok) throw new Error('Error al consultar estado WINSAAI de pedimentos');
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Error al consultar estado WINSAAI de pedimentos';
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage;
|
||||
} catch (e) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
if (text) errorMessage = text;
|
||||
} catch (e2) {}
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
|
||||
@@ -776,9 +776,9 @@
|
||||
currentStatusFunction = invoicesReportsApi.getTaskStatus;
|
||||
progressDialogTitle = m.invoice_list_progress_title_pdf();
|
||||
showProgressDialog = true;
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toast.error(m.invoice_list_toasts_download_start_error());
|
||||
toast.error(error.message || m.invoice_list_toasts_download_start_error());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1507,9 +1507,9 @@
|
||||
currentTaskId = task_id;
|
||||
currentStatusFunction = invoicesReportsApi.getTaskStatus;
|
||||
showProgressDialog = true;
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toast.error(m.invoice_list_toasts_download_start_error());
|
||||
toast.error(error.message || m.invoice_list_toasts_download_start_error());
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user