refactor(gui): the cash page's average net refuses oversized months

The burn-and-runway card subtracted each month's out from in with a raw
- inside a map and summed raw; it totals with kernel::total_try and shows
a note when the figures are too large to compute. Display unchanged
otherwise.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-08 12:23:11 -07:00
1 parent e6104b49d6
commit 5230585e53
1 file changed
+9 -2
+9 -2
View File
@@ -181,8 +181,15 @@ fn runway(ui: &mut Ui, b: &Books) {
ui.label(RichText::new("Needs at least one full month of books.").color(p.muted));
return;
}
let net: Decimal = months.iter().map(|(_, _, i, o)| i - o).sum::<Decimal>()
/ Decimal::from(months.len() as u64);
// Exact or refused: books near the arithmetic's limit show a
// note, never a crash (rules.md B-28).
let Some(net) = ledger_core::kernel::total_try(&months, |&(_, _, i, o)| {
ledger_core::kernel::Amount::checked_sub(i, o)
})
.and_then(|sum| sum.checked_div(Decimal::from(months.len() as u64))) else {
ui.label(RichText::new("The figures are too large to compute.").color(p.muted));
return;
};
let net = net.round_dp(2);
let big = |ui: &mut Ui, label: &str, value: String, color| {
ui.vertical(|ui| {