fix(vat): run the recompute once after the report-fill (dövr) settles

Selecting dövr triggers populate_vat_tables + formula_editor, which fill leaf
cells from reports but do not roll parents up (e.g. 301.1 = Σ 301.1.1..4). The
per-write recompute is suppressed during that storm; previously nothing ran
afterwards, so 301.1 (and other roll-ups / appendix→turnover passthrough) stayed
stale. Now "fill mode" runs the recompute ONCE, 3s after the fill settles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-07-15 15:25:06 +00:00
parent 67f258daf0
commit 26e72c253e
1 changed files with 15 additions and 8 deletions

View File

@ -284,18 +284,25 @@ function vc_recompute(frm) {
frm.refresh_field("sertifikathesabatdövründəmalındəyərininsəhifəsicəmi");
}
// --- Suppress recompute during the report-fill storm (populate_vat_tables / formula_editor
// write hundreds of cells via set_value; recomputing on each would freeze the UI and
// clobber report values). "Fill mode" starts on period change and re-arms on every
// programmatic write, ending 3s after the fill settles. User edits are debounced. ---
var vc_fill_mode = false, vc_fill_timer = null, vc_calc_timer = null;
function vc_mark_fill() {
// --- Suppress the per-write recompute during the report-fill storm (populate_vat_tables /
// formula_editor write hundreds of cells via set_value; recomputing on each would freeze
// the UI). "Fill mode" starts on period change and re-arms on every programmatic write.
// 3s after the fill settles it runs the recompute ONCE, so roll-ups / passthrough
// (e.g. 301.1 = Σ children, turnover ← appendices) fill in from the report data.
// User edits (outside fill mode) are debounced. ---
var vc_fill_mode = false, vc_fill_timer = null, vc_calc_timer = null, vc_frm = null;
function vc_mark_fill(frm) {
if (frm) vc_frm = frm;
vc_fill_mode = true;
if (vc_fill_timer) clearTimeout(vc_fill_timer);
vc_fill_timer = setTimeout(function () { vc_fill_mode = false; }, 3000);
vc_fill_timer = setTimeout(function () {
vc_fill_mode = false;
if (vc_frm) vc_recompute(vc_frm); // one recompute after the report-fill settles
}, 3000);
}
function vc_onchange(frm) {
if (vc_fill_mode) { vc_mark_fill(); return; } // ignore fill writes
vc_frm = frm;
if (vc_fill_mode) { vc_mark_fill(frm); return; } // during fill: extend window, no per-write recompute
if (vc_calc_timer) clearTimeout(vc_calc_timer);
vc_calc_timer = setTimeout(function () { vc_recompute(frm); }, 300); // debounce user edits
}