fix/INP-filtros-y-modal

This commit is contained in:
2026-06-02 10:28:18 -06:00
parent 7b95c6da86
commit c5a77fb30a
5 changed files with 41 additions and 20 deletions

View File

@@ -13,6 +13,7 @@ router = TenantCRUDRoutes(
tags=["a76.general_catalogs.inpc"],
resource_name="INPC",
enable_list=True,
enable_filters=True,
# Permisos
list_permissions=["cat_inpc.view"],
get_permissions=["cat_inpc.view"],

View File

@@ -22,8 +22,10 @@ class INPCService:
)
if filters:
# Add filters here if needed
pass
if filters.get("year"):
query = query.filter(INPC.year == filters["year"])
if filters.get("month"):
query = query.filter(INPC.month == filters["month"])
total = query.count()
items = query.offset(skip).limit(limit).all()

View File

@@ -34,11 +34,22 @@ export async function getINPCs(
companyId: number,
filters: Record<string, any> = {}
): Promise<ApiResponse<INPCListResponse>> {
const cleanFilters = Object.fromEntries(
Object.entries(filters).filter(([, value]) => {
if (value === undefined || value === null) return false;
if (typeof value === 'string') {
const trimmed = value.trim();
return trimmed !== '' && trimmed.toLowerCase() !== 'undefined';
}
return true;
})
);
const params = new URLSearchParams({
page: page.toString(),
page_size: pageSize.toString(),
company_id: companyId.toString(),
...filters
...cleanFilters
});
return await api.get(`/v1/a76/inpc/?${params.toString()}`);

View File

@@ -86,7 +86,10 @@
</script>
<Dialog.Root bind:open>
<Dialog.Content class="sm:max-w-[500px]">
<Dialog.Content
class="sm:max-w-[500px]"
onInteractOutside={(e) => e.preventDefault()}
>
<Dialog.Header>
<Dialog.Title>{title}</Dialog.Title>
</Dialog.Header>

View File

@@ -11,7 +11,7 @@
import * as Card from '$lib/components/ui/card';
import { Button } from '$lib/components/ui/button';
import { Input } from '$lib/components/ui/input';
import { Pencil, Plus, Trash2, RefreshCw } from 'lucide-svelte';
import { Pencil, Plus, Trash2 } from 'lucide-svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosListaINPC } from '$lib/config/shortcuts/dashboard/general_catalogs/inpc/list';
import { inpcApi, type INPC } from '$lib/api/dashboard/a76/general_catalogs/inpc';
@@ -88,10 +88,11 @@
page: '1',
page_size: pageSize.toString()
});
if (response.data) {
allItems = response.data.items;
currentPage = 1;
totalItems = response.data.total;
const payload = (response as any).items ? response : (response as any).data;
if (payload?.items) {
allItems = payload.items;
currentPage = payload.page || 1;
totalItems = payload.total;
}
} catch (err) {
error = 'Error aplicando filtros';
@@ -118,11 +119,14 @@
page: (currentPage + 1).toString(),
page_size: pageSize.toString()
});
if (response.data?.items) {
allItems = [...allItems, ...response.data.items];
currentPage += 1;
totalItems = response.data.total;
const payload = (response as any).items ? response : (response as any).data;
if (payload?.items) {
allItems = [...allItems, ...payload.items];
currentPage = payload.page || currentPage + 1;
totalItems = payload.total;
}
} catch (err) {
error = 'Error cargando mas datos';
} finally {
loading = false;
}
@@ -139,11 +143,14 @@
page: '1',
page_size: pageSize.toString()
});
if (response.data) {
allItems = response.data.items;
currentPage = 1;
totalItems = response.data.total;
const payload = (response as any).items ? response : (response as any).data;
if (payload?.items) {
allItems = payload.items;
currentPage = payload.page || 1;
totalItems = payload.total;
}
} catch (err) {
error = 'Error al recargar datos';
} finally {
loading = false;
}
@@ -168,9 +175,6 @@
<p class="text-muted-foreground">{m['common.sub_inpc']()}</p>
</div>
<div class="flex items-center gap-3">
<Button variant="outline" size="sm" class="h-9" onclick={reloadData}>
<RefreshCw class="mr-2 h-4 w-4" /> {m['common.btn_refresh']()}
</Button>
{#if !isError && canCreate}
<Button
class="h-9"