merge: P4b S7, bad debts (branch S7, 4b4fecb9)
The fourth of the paused branches: Ledger::write_off and the bad_debts control role, invoice.written_off with its evidence filed in the same store call, books.write_off_invoice, the write-off on the timeline and in Needs attention, Lean writeOff_within_bounds, rules.md B-41 and the bookspec examples. Twenty-eight files conflicted with the S4.4, S5 and S6 merges; resolved as plan 8.0.2 says, keeping both sides' appends with their seams restored, and: the scope table at 125; S7's law numbered 37; B-41 placed before B-42; the handbook's step 4 and recovery procedures folded into the one invoices-and-bills section; S7's wire tests in their own module with the confirm S4.4's contract needs; S7's copy of the payment steps dropped (S6 replaced them with Ledger::settle) and its write-off journaled through S6's journal_auto_lines; in the old-books fixture S7's hand-written write-off moved to a second invoice, since S6's hand-written payment settles invoice 1 in full. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
commit
335a3eaa7e
47 files changed
+2883
-74
No files matched your search
@@ -42,7 +42,11 @@
|
||||
//! `invoicing.unsent_days` (Todo, its prompt naming books.mark_sent;
|
||||
//! a legacy invoice with no number is exempt); an overdue invoice
|
||||
//! whose last send is older than `invoicing.reminder_days` (Todo, the
|
||||
//! same tool); money owed to
|
||||
//! same tool);
|
||||
//! invoices (Problem, one each, with the total); a written-off
|
||||
//! invoice whose write-off is dated this calendar year and stands
|
||||
//! (Todo, one per invoice, "Write-off awaiting the CPA's note",
|
||||
//! its prompt naming books.document); money owed to
|
||||
//! owners (Info, per account with a balance); the database differing
|
||||
//! from the journal or unreadable, and damaged or missing stored
|
||||
//! files (Problem); depreciation due through the last finished month
|
||||
@@ -802,6 +806,62 @@ pub fn find_with(
|
||||
});
|
||||
}
|
||||
}
|
||||
// A write-off this year waits for the CPA's note: the deduction rests
|
||||
// on evidence of worthlessness a human signs off, and §166's judgments
|
||||
// stay with the CPA (plan P4b S7, 8.3.16; IRC §166(a); Treas. Reg.
|
||||
// §1.166-2(a)). Listed until the year ends.
|
||||
let mut written_off: Vec<(u64, Option<String>, NaiveDate, Decimal)> = Vec::new();
|
||||
for inv in ledger.invoices() {
|
||||
let doc = ledger_core::DocRef::Invoice(inv.id);
|
||||
let state = ledger.invoice_state(inv.id, today).ok().flatten();
|
||||
if state.map(|s| s.status) != Some(ledger_core::DocStatus::WrittenOff) {
|
||||
continue;
|
||||
}
|
||||
let lines: Vec<ledger_core::DocLine> = ledger
|
||||
.doc_lines(doc)
|
||||
.into_iter()
|
||||
.filter(|l| {
|
||||
l.movement == ledger_core::Movement::WriteOff
|
||||
&& l.date.year() == today.year()
|
||||
&& ledger.stands_on(l.entry, today)
|
||||
})
|
||||
.collect();
|
||||
let Some(last) = lines.last() else {
|
||||
continue;
|
||||
};
|
||||
match lines
|
||||
.iter()
|
||||
.try_fold(Decimal::ZERO, |t, l| t.checked_sub(l.amount))
|
||||
{
|
||||
Some(amount) => written_off.push((inv.id, inv.number.clone(), last.date, amount)),
|
||||
None => out.push(cant_compute(
|
||||
format!("Invoice {}", inv.id),
|
||||
&LedgerError::TooLargeToCompute("what was written off".into()),
|
||||
Target::Documents,
|
||||
)),
|
||||
}
|
||||
}
|
||||
for (id, number, on, amount) in written_off {
|
||||
let name = number.unwrap_or_else(|| format!("Invoice {id}"));
|
||||
out.push(Attention {
|
||||
severity: Severity::Todo,
|
||||
kind: "write_off_note",
|
||||
title: format!("Write-off awaiting the CPA's note: {name}"),
|
||||
detail: format!(
|
||||
"{} written off on {} (IRC §166; Treas. Reg. §1.166-2: the evidence of worthlessness is filed with the write-off).",
|
||||
dollars(amount),
|
||||
date(on)
|
||||
),
|
||||
target: Target::Documents,
|
||||
prompt: format!(
|
||||
"In wanderbooks, show me invoice {id}'s write-off (books.document), with its reason and the evidence filed with it, and note it for the CPA at year end."
|
||||
),
|
||||
tool: Some((
|
||||
"books.document".into(),
|
||||
serde_json::json!({ "ref": format!("invoice:{id}") }),
|
||||
)),
|
||||
});
|
||||
}
|
||||
|
||||
for a in ledger.chart().all().filter(|a| {
|
||||
a.account_type == AccountType::Liability && {
|
||||
|
||||
Reference in new issue
Block a user