Merge pull request 'fix/bug-catalog-envoices-select' (#239) from fix/bug-catalog-envoices-select into development
Reviewed-on: ADUANASOFT/anexo76#239
This commit is contained in:
@@ -33,7 +33,7 @@ seed = [
|
||||
("H1", "EXD", "E"),
|
||||
("H8", "EXD", "E"),
|
||||
("I1", "EXD", "E"),
|
||||
("J1", "EXD", "E"),
|
||||
# ("J1", "EXD", "E"), # No existe en la tabla de pedimento_codes
|
||||
("J2", "EXD", "E"),
|
||||
("K1", "EXD", "E"),
|
||||
("K2", "EXD", "E"),
|
||||
|
||||
@@ -131,15 +131,23 @@
|
||||
|
||||
// Efecto para aplicar filtros automáticamente cuando cambian
|
||||
let filterTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
let lastFiltersKey = '';
|
||||
$effect(() => {
|
||||
// Observar cambios en los filtros
|
||||
const _ = {
|
||||
const currentFilters = {
|
||||
operation_type: filters.operation_type,
|
||||
invoice_type: filters.invoice_type,
|
||||
invoice_number: filters.invoice_number,
|
||||
project_number: filters.project_number,
|
||||
year: filters.year
|
||||
};
|
||||
const currentFiltersKey = JSON.stringify(currentFilters);
|
||||
|
||||
// Limpiar selección cada vez que se modifica algún filtro
|
||||
if (currentFiltersKey !== lastFiltersKey) {
|
||||
selectedInvoiceIds = [];
|
||||
lastFiltersKey = currentFiltersKey;
|
||||
}
|
||||
|
||||
// Debounce para evitar múltiples llamadas rápidas
|
||||
if (filterTimeout) clearTimeout(filterTimeout);
|
||||
|
||||
@@ -486,9 +486,44 @@
|
||||
return list.filter((p: { operation_type?: string }) => p.operation_type === opType);
|
||||
});
|
||||
|
||||
let lastInheritancePedimentoId: number | null = null;
|
||||
let hasInitializedInheritanceState = false;
|
||||
|
||||
// Al seleccionar pedimento, autollenar Aduana y Clave de régimen (document_type)
|
||||
// Fuente de verdad: pedimento.customs_office (aduana) y pedimento.regime (régimen)
|
||||
$effect(() => {
|
||||
const pid = InvoiceTopFieldsFormData?.pedimento_id;
|
||||
const currentPedimentoId =
|
||||
typeof pid === 'string'
|
||||
? (Number.parseInt(pid, 10) || null)
|
||||
: (pid ?? null);
|
||||
|
||||
// Edición: solo reaplicar en transición real a nuevo pedimento.
|
||||
// No sobrescribir/borrar al abrir la pantalla ni en cambios no relacionados.
|
||||
if (!data.isCreate) {
|
||||
if (!hasInitializedInheritanceState) {
|
||||
lastInheritancePedimentoId = currentPedimentoId;
|
||||
hasInitializedInheritanceState = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const pedimentoChanged = lastInheritancePedimentoId !== currentPedimentoId;
|
||||
const hasPedimentoNow = !!currentPedimentoId;
|
||||
const shouldReapplyFromPedimento = pedimentoChanged && hasPedimentoNow;
|
||||
|
||||
lastInheritancePedimentoId = currentPedimentoId;
|
||||
|
||||
if (!shouldReapplyFromPedimento || !generalFormData) return;
|
||||
|
||||
const ped = (data.pedimentos || []).find((p: any) => p?.id === currentPedimentoId);
|
||||
if (!ped) return;
|
||||
|
||||
// En edición, cuando hay transición válida, pedimento manda (incluyendo vacío).
|
||||
generalFormData.aduana = ped.customs_office || '';
|
||||
generalFormData.document_type = ped.regime || '';
|
||||
return;
|
||||
}
|
||||
|
||||
// Si se marca pedimento pendiente, el componente ya limpia pedimento/remesa;
|
||||
// aquí limpiamos también los campos que dependen del pedimento.
|
||||
if (InvoiceTopFieldsFormData?.is_pedimento_pending) {
|
||||
@@ -499,9 +534,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const pid = InvoiceTopFieldsFormData?.pedimento_id;
|
||||
if (!pid || !generalFormData) return;
|
||||
const id = typeof pid === 'string' ? parseInt(pid, 10) : pid;
|
||||
const id = typeof pid === 'string' ? Number.parseInt(pid, 10) : pid;
|
||||
if (!id || Number.isNaN(id)) return;
|
||||
|
||||
const ped = (filteredPedimentos || []).find((p: any) => p?.id === id);
|
||||
|
||||
Reference in New Issue
Block a user