refactor(store,config): their Decimal arithmetic goes through the kernel (K-U12)
Ten places, now zero, and both crates join kernel_only_crates so the lint part of `just check` holds them there. ledger-store (8): a disposal's preview adds the asset's posted runs and takes book value and gain or loss by subtraction; an attested receipt is compared with the entry's debits; an older settlement's remainder is the document's total less what was recorded. Each called rust_decimal's own checked_add or checked_sub, which rounds where the exact answer needs more than 96 bits and says nothing. They call the kernel's now (kernel::total_of, Amount::checked_add and checked_sub): exact, or the refusal each of these places already had (too_large, or no figure to compare). Two unary minuses go through money::neg. Posted lines are bounded (BS-entry-3, BS-entry-4), so no figure in real books changes. ledger-config (2): a member's "50%" is divided by a hundred through Amount::checked_div (the raw `/` computed the same quotient), and the members' shares are added by kernel::total_of. Shares that cannot be added exactly are refused with a sentence saying to write them with fewer places, where the raw sum would have rounded them and then compared the rounded figure with one. ledger-core's own check of the same setting already did this. Checked: the detector reads 0 for both; both crates' suites pass (682 tests); clippy with -D warnings. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0de906e9ed
commit
1c28760d87
5 files changed
+37
-25
No files matched your search
@@ -642,11 +642,13 @@ impl Store {
|
||||
"attachment {attachment_id} is not filed on or linked to entry {entry_id}"
|
||||
)));
|
||||
}
|
||||
let debits = entry
|
||||
.lines()
|
||||
.iter()
|
||||
.filter(|l| l.side == ledger_core::Side::Debit)
|
||||
.try_fold(Decimal::ZERO, |s, l| s.checked_add(l.amount.amount));
|
||||
let debits = ledger_core::kernel::total_of(
|
||||
entry
|
||||
.lines()
|
||||
.iter()
|
||||
.filter(|l| l.side == ledger_core::Side::Debit),
|
||||
|l| l.amount.amount,
|
||||
);
|
||||
let amount_agrees =
|
||||
debits == Some(amount) || entry.lines().iter().any(|l| l.amount.amount == amount);
|
||||
let disagrees = !amount_agrees || date != entry.date();
|
||||
|
||||
Reference in new issue
Block a user