Merge branch 'feature/descargo_peps' into development
Integración de funcionalidad de Descargo PEPS con reportes de Packing List y Aviso Consolidado: - Frontend: Agregados imports de dischargeReportsApi y ClipboardList - Frontend: Agregada función handleDownloadDescargo con cálculo PEPS - Frontend: Agregado botón condicional de Descargo PEPS (solo exportaciones) - Frontend: Integradas funciones de Aviso Consolidado y Packing List - Backend: Agregados routers y tasks de descargo y otros reportes - Backend: Configurado Celery con todas las tareas de reportes - Backend: Corregido ForeignKey en line_quantities.package_id - Resueltos conflictos manteniendo funcionalidades de ambas ramas
This commit is contained in:
35
frontend/src/lib/api/dashboard/a24/inv.ts
Normal file
35
frontend/src/lib/api/dashboard/a24/inv.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import axios from 'axios';
|
||||
import { PUBLIC_API_URL } from '$env/static/public';
|
||||
|
||||
/**
|
||||
* Cliente API para el módulo de Inventarios (A24)
|
||||
*/
|
||||
export const invApi = {
|
||||
/**
|
||||
* Ejecuta el proceso de asignación PEPS (FIFO) para una factura de exportación
|
||||
* @param invoiceId ID de la factura de exportación
|
||||
* @returns Promesa con la respuesta del servidor
|
||||
*/
|
||||
assignFifo: async (invoiceId: number) => {
|
||||
try {
|
||||
const token = localStorage.getItem('access_token');
|
||||
const response = await axios.post(
|
||||
`${PUBLIC_API_URL}/api/v1/a76/reports/exportacion/descargo/fifo-assign/${invoiceId}`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
return { data: response.data, error: null };
|
||||
} catch (error: any) {
|
||||
console.error('Error executing FIFO:', error);
|
||||
return {
|
||||
data: null,
|
||||
error: error.response?.data?.detail || 'Error al ejecutar cálculo PEPS'
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_URL || '';
|
||||
|
||||
export const dischargeReportsApi = {
|
||||
|
||||
triggerPdfGeneration: async (invoiceId: number, companyId: number) => {
|
||||
const params = new URLSearchParams({ company_id: companyId.toString() });
|
||||
// Endpoint matches routes.py
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/exportacion/descargo/${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 del Reporte de Descarga');
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
getTaskStatus: async (taskId: string) => {
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/exportacion/descargo/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 del Reporte de Descarga');
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
assignFifo: async (invoiceId: number) => {
|
||||
// Endpoint: /a76/reports/exportacion/descargo/fifo-assign/{invoice_id}
|
||||
const endpoint = `${BASE_URL}/v1/a76/reports/exportacion/descargo/fifo-assign/${invoiceId}`;
|
||||
const token = localStorage.getItem('access_token');
|
||||
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errData = await response.json().catch(() => ({}));
|
||||
return { data: null, error: errData.detail || 'Error al ejecutar PEPS' };
|
||||
}
|
||||
|
||||
return { data: await response.json(), error: null };
|
||||
} catch (e: any) {
|
||||
return { data: null, error: e.message || 'Error de conexión PEPS' };
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user