From fdce64ebd2fa3f87496de3d941e933c9e3af1849 Mon Sep 17 00:00:00 2001 From: A R R R Associates Date: Sun, 23 Aug 2026 12:45:44 +0530 Subject: [PATCH] Fix historical sync progress reload loop --- .../templates/accounting/historical_learning.html | 11 ++++++++++- .../templates/accounting/sales_learning.html | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/modules/accounting/templates/accounting/historical_learning.html b/app/modules/accounting/templates/accounting/historical_learning.html index 86726f2..747fbef 100644 --- a/app/modules/accounting/templates/accounting/historical_learning.html +++ b/app/modules/accounting/templates/accounting/historical_learning.html @@ -20,6 +20,7 @@ {% if latest_run %}
@@ -84,6 +85,9 @@ const s=document.getElementById('wsCompany'); if(s){s.addEventListener('change', const box = document.getElementById("historicalRunProgress"); if (!box) return; const url = box.dataset.statusUrl; + const initialStatus = String(box.dataset.runStatus || "").toLowerCase(); + const terminalAtLoad = ["completed", "failed", "cancelled"].includes(initialStatus); + const label = document.getElementById("runProgressLabel"); const detail = document.getElementById("runProgressDetail"); const meta = document.getElementById("runProgressMeta"); @@ -150,7 +154,12 @@ const s=document.getElementById('wsCompany'); if(s){s.addEventListener('change', if (!completedReloaded) window.setTimeout(poll, 3000); } - poll(); + // If this page was rendered with an already-terminal latest run, + // do not poll it and do not reload. This prevents an endless + // Completed -> reload -> Completed -> reload loop. + if (!terminalAtLoad) { + poll(); + } })(); diff --git a/app/modules/accounting/templates/accounting/sales_learning.html b/app/modules/accounting/templates/accounting/sales_learning.html index 517aa51..6f50bbc 100644 --- a/app/modules/accounting/templates/accounting/sales_learning.html +++ b/app/modules/accounting/templates/accounting/sales_learning.html @@ -135,6 +135,9 @@ const box = document.getElementById("historicalRunProgress"); if (!box) return; const url = box.dataset.statusUrl; + const initialStatus = String(box.dataset.runStatus || "").toLowerCase(); + const terminalAtLoad = ["completed", "failed", "cancelled"].includes(initialStatus); + const label = document.getElementById("runProgressLabel"); const detail = document.getElementById("runProgressDetail"); const meta = document.getElementById("runProgressMeta"); @@ -201,7 +204,12 @@ if (!completedReloaded) window.setTimeout(poll, 3000); } - poll(); + // If this page was rendered with an already-terminal latest run, + // do not poll it and do not reload. This prevents an endless + // Completed -> reload -> Completed -> reload loop. + if (!terminalAtLoad) { + poll(); + } })();