fix/pedimentos-edit-datos-borrados
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"),
|
||||
|
||||
@@ -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