refactor(mcp): Decimal arithmetic goes through the kernel (K-U12)
The raw-decimal-arith detector counted 19 places in ledger-mcp before and counts 0 after. No figure changes. Sides become signs through money::on_side and money::signed_amount (server delta, report movement, the P&L-by-class normal-side figure, which collapses two matches into one call); sums and differences of books figures through add_in_range and sub_in_range; the checked sums in helpers and documents through Amount::checked_add with their error handling untouched. The count of withdrawn attachments (a usize, not a Decimal) is the length of the flattened withdraw lists instead of an Iterator::sum of their lengths: the same number. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
5ef5f47ebf
commit
1d612d25b8
7 files changed
+34
-36
No files matched your search
@@ -7,6 +7,7 @@
|
||||
|
||||
use super::*;
|
||||
use ledger_core::InstrumentId;
|
||||
use ledger_core::kernel::Amount;
|
||||
use ledger_store::StoreError;
|
||||
|
||||
/// The book's id, as the commands given to agents name it: its folder's
|
||||
@@ -462,7 +463,7 @@ pub(crate) fn checked_sum(
|
||||
) -> Result<Decimal, String> {
|
||||
values.into_iter().try_fold(Decimal::ZERO, |sum, v| {
|
||||
let v = v.map_err(|e| e.to_string())?;
|
||||
sum.checked_add(v).ok_or_else(|| {
|
||||
Amount::checked_add(sum, v).ok_or_else(|| {
|
||||
ledger_core::LedgerError::TooLargeToCompute(what.to_string()).to_string()
|
||||
})
|
||||
})
|
||||
@@ -548,7 +549,9 @@ pub(crate) fn lines_settled(entry: &JournalEntry) -> bool {
|
||||
.lines()
|
||||
.iter()
|
||||
.filter(|l| l.side == s)
|
||||
.try_fold(Decimal::ZERO, |sum, l| sum.checked_add(l.amount.amount))
|
||||
.try_fold(Decimal::ZERO, |sum, l| {
|
||||
Amount::checked_add(sum, l.amount.amount)
|
||||
})
|
||||
};
|
||||
match (side(Side::Debit), side(Side::Credit)) {
|
||||
(Some(debits), Some(credits)) => !entry.lines().is_empty() && debits == credits,
|
||||
|
||||
Reference in new issue
Block a user