refactor(gui): the viewer's Decimal arithmetic goes through the kernel (K-U12)
The detector (scripts/raw-decimal-arith.sh ledger-gui) counted 123 places in the viewer that did Decimal arithmetic outside the kernel; it counts 0 now. No figure the viewer shows changes: a raw operator panicked when the exact answer did not fit, and add_in_range / sub_in_range / neg panic in exactly that case; rust_decimal's checked_* methods, which round past 96 bits, became the kernel's Amount::checked_* (exact or None), with the existing None handling untouched. Places that are not plain sums or differences, and what each became: - Sums of balances and posted lines (receivables, due to members, a disposal's true-up, a statement row across columns, cleared total): kernel::total / total_of; a refused sum is an expect where the figure is drawn from the books, and a blank cell in the cash-flow keyed rows (which already blank a refused statement). - The share split (books.rs): share_of(v, share, net), the same multiply then divide; the scaled parts use checked_mul_rounded because the fraction is a quotient, truncated to cents on the next line. - Percents of a share (capital, company, reports): checked_mul_rounded by 100, exactly what * did. - Averages and runway (monthly burn, cash runway, net per month, a third of an amount, build-in pct): Amount::checked_div, a None joins the None or "can't compute" the code already has. - The 125% watch threshold: checked_mul_rounded and is_some_and. - Rescale to one place (pct): rescale_exact, keeping the value when it would round. - The demo's rounding to a step ((x / 50).round() * 50): to_step, the same half-to-even rounding through round_places. - f32 widths and usize counts: plain folds, no allow. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0de906e9ed
commit
e4c41ccb3f
16 files changed
+244
-151
No files matched your search
@@ -16,6 +16,7 @@ use crate::widgets;
|
||||
use chrono::NaiveDate;
|
||||
use egui::Ui;
|
||||
use egui_phosphor::regular as icon;
|
||||
use ledger_core::money::add_in_range;
|
||||
use ledger_core::{DocRef, DocState, DocStatus, DocumentLine};
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
@@ -200,7 +201,7 @@ pub fn summary(b: &Books, bills: bool) -> Option<(Decimal, usize, usize)> {
|
||||
if let Ok(Some(st)) = &it.state
|
||||
&& Filter::Open.keeps(st)
|
||||
{
|
||||
owed += st.outstanding;
|
||||
owed = add_in_range(owed, st.outstanding);
|
||||
if st.overdue_days > 0 {
|
||||
late += 1;
|
||||
} else if it.due <= week {
|
||||
@@ -265,10 +266,10 @@ pub fn show_list(ui: &mut Ui, b: &Books, bills: bool, shell: &mut Shell<'_>) {
|
||||
for it in &all {
|
||||
match &it.state {
|
||||
Ok(Some(st)) if Filter::Open.keeps(st) => {
|
||||
owed += st.outstanding;
|
||||
owed = add_in_range(owed, st.outstanding);
|
||||
open_n += 1;
|
||||
if st.overdue_days > 0 {
|
||||
late += st.outstanding;
|
||||
late = add_in_range(late, st.outstanding);
|
||||
late_n += 1;
|
||||
}
|
||||
}
|
||||
@@ -473,8 +474,8 @@ fn tie_out(b: &Books, bills: bool) -> (String, String, bool) {
|
||||
return ("Agrees".into(), "No account holds them yet".into(), true);
|
||||
}
|
||||
let names: Vec<String> = mine.iter().map(|c| b.account_label(c.account)).collect();
|
||||
let loose: usize = mine.iter().map(|c| c.unattached.len()).sum();
|
||||
let odd: usize = mine.iter().map(|c| c.attention.len()).sum();
|
||||
let loose: usize = mine.iter().fold(0_usize, |n, c| n + c.unattached.len());
|
||||
let odd: usize = mine.iter().fold(0_usize, |n, c| n + c.attention.len());
|
||||
let off = mine.iter().any(|c| !c.difference.is_zero());
|
||||
if off {
|
||||
("Differs".into(), "An engine error: report it".into(), false)
|
||||
|
||||
Reference in new issue
Block a user