(data.pedimentoId ?? null);
@@ -274,6 +303,16 @@
success = false;
try {
+ // Verificar tipo de cambio antes de guardar si hay instancia del tab general y hay fecha de pago
+ if (generalTabInstance && generalFormData?.payment_date) {
+ const rateExists = await generalTabInstance.checkPaymentDateRate(generalFormData.payment_date);
+ if (!rateExists) {
+ saving = false;
+ // Asegurar que se muestre el tab general
+ activeTab = 'general';
+ return;
+ }
+ }
// Validar campos requeridos para creación
if (data.isCreate && generalFormData) {
@@ -718,14 +757,60 @@
success = false;
}, 3000);
} catch (e) {
- if (e instanceof Error && e.message.includes('401')) {
- error = 'Sesión expirada. Recargando página...';
- setTimeout(() => {
- window.location.reload();
- }, 1500);
- } else {
- error = e instanceof Error ? e.message : 'Error al guardar los cambios';
- }
+ if (e instanceof Error) {
+ if (e.message.includes('401')) {
+ error = 'Sesión expirada. Recargando página...';
+ setTimeout(() => {
+ window.location.reload();
+ }, 1500);
+ } else {
+ // Extracción segura del error
+ let errorStr = "";
+ try {
+ if (typeof e.message === 'object') {
+ errorStr = JSON.stringify(e.message);
+ } else if (e.message === '[object Object]') {
+ // Si el mensaje es literalmente [object Object], intentamos ver si e tiene otras props
+ errorStr = JSON.stringify(e);
+ } else {
+ errorStr = e.message || String(e);
+ }
+ } catch (jsonErr) {
+ errorStr = String(e);
+ }
+
+ if (errorStr.includes('No existe un Tipo de Cambio registrado') || errorStr.includes('financials.exchange_rate')) {
+ // Interceptar error de tipo de cambio
+ console.log("Interceptor: Exchange rate missing error caught (Pedimento).");
+ error = null;
+
+ const dateMatch = errorStr.match(/(\d{4}-\d{2}-\d{2})/);
+ const missingDate = dateMatch ? dateMatch[0] : (generalFormData?.payment_date || "");
+
+ missingExchangeRateDate = missingDate;
+ showExchangeRateDialog = true;
+ activeTab = 'general';
+ return;
+ }
+
+ // Fallback normal: intentar mostrar algo legible
+ if (errorStr.includes('{')) {
+ // Si parece JSON, intentar formatearlo un poco o mostrar mensaje genérico
+ try {
+ const errObj = JSON.parse(errorStr);
+ // Si es del formato {"field": ["msg"]}
+ const values = Object.values(errObj).flat();
+ error = values.join(', ');
+ } catch {
+ error = "Error al guardar (ver consola)";
+ }
+ } else {
+ error = errorStr;
+ }
+ }
+ } else {
+ error = 'Error al guardar los cambios';
+ }
console.error('Error saving all:', e);
} finally {
saving = false;
@@ -794,6 +879,7 @@
0:
+ print(f"Found {total} exchange rate(s) for today. Deleting...")
+ for rate in rates:
+ ExchangeRateService.delete(db, rate.id, tenant_id, company_id)
+ print("Deleted.")
+else:
+ print("No exchange rate found for today.")
+
+db.close()