merge: golden files for the 1099 worksheet (with a recorded business card's exclusion) and prepaid and deferred amortization (branch t3/golden-1099-prepaid-amortization, 06b571c1; reviewed and recomputed independently)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
de584309fc
7 files changed
+802
-3
No files matched your search
@@ -494,7 +494,7 @@ impl Status1099 {
|
||||
}
|
||||
|
||||
/// One vendor's year.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||
pub struct Vendor1099Line {
|
||||
/// The vendor.
|
||||
pub vendor_id: VendorId,
|
||||
@@ -542,7 +542,7 @@ impl Vendor1099Line {
|
||||
}
|
||||
|
||||
/// One payment on a vendor's year, for the worksheet's lists.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||
pub struct Payment1099 {
|
||||
/// The entry.
|
||||
pub entry_id: EntryId,
|
||||
@@ -557,7 +557,7 @@ pub struct Payment1099 {
|
||||
}
|
||||
|
||||
/// The year's 1099 report.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||
pub struct Vendor1099Report {
|
||||
/// Calendar year.
|
||||
pub year: i32,
|
||||
|
||||
@@ -208,6 +208,10 @@ fn cash_paid_per_vendor_and_who_is_reportable() {
|
||||
assert_eq!(ace.form(), Some(Form1099::Misc));
|
||||
assert_eq!(ace.decided, Some(src()));
|
||||
assert!(!ace.tin_on_file);
|
||||
// No method records the card: Sam's 5,000 on it counts for no one.
|
||||
let sam = line(&r, "Sam");
|
||||
assert_eq!((sam.excluded_card, sam.undetermined), (dec("0"), dec("0")));
|
||||
assert!(r.excluded_card_payments.is_empty());
|
||||
// The untagged 50 paid out for contract labor: the quieter note's one.
|
||||
assert_eq!(r.untagged_payments.len(), 1);
|
||||
}
|
||||
@@ -2511,3 +2515,35 @@ fn card_accounts_are_the_company_cards_liabilities() {
|
||||
[m.card]
|
||||
);
|
||||
}
|
||||
|
||||
/// Golden (oracle Layer 1): the worksheet's figures for the hand-verified
|
||||
/// fixture above, every one recomputed from the entries in
|
||||
/// plan/golden-worksheets/1099-worksheet.md before this test was run.
|
||||
/// 2025 and 2026 together pin the year boundary: Dana's 300.00 on
|
||||
/// 2025-12-30 counts in 2025 only, and the threshold moves from 600 to
|
||||
/// 2,000 (rules.md B-19).
|
||||
#[test]
|
||||
fn golden_1099_worksheet() {
|
||||
let mut l = books();
|
||||
// Record the card (worksheet, "With the card recorded"): Sam's 5,000
|
||||
// is then a card payment, excluded and listed (B-19). books() leaves
|
||||
// it unrecorded, and other tests rely on that.
|
||||
let card = l.chart().find_by_code("2100").unwrap().id;
|
||||
l.add_instrument(
|
||||
InstrumentKind::BusinessCard,
|
||||
"Harbor Visa",
|
||||
Some("0042"),
|
||||
None,
|
||||
card,
|
||||
)
|
||||
.unwrap();
|
||||
let r2026 = report_for(&l, 2026, None, &[]).unwrap();
|
||||
let r2025 = report_for(&l, 2025, None, &[]).unwrap();
|
||||
let got = serde_json::json!({
|
||||
"2025": serde_json::to_value(&r2025).unwrap(),
|
||||
"2026": serde_json::to_value(&r2026).unwrap(),
|
||||
});
|
||||
let want: serde_json::Value =
|
||||
serde_json::from_str(include_str!("golden/form1099_worksheet.json")).unwrap();
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
{
|
||||
"deferred": {
|
||||
"balance_sheet": {
|
||||
"as_of": "2026-03-31",
|
||||
"assets": [
|
||||
{
|
||||
"amount": "1000",
|
||||
"code": "1000",
|
||||
"name": "Cash"
|
||||
}
|
||||
],
|
||||
"current_earnings": "1000.00",
|
||||
"equity": [],
|
||||
"liabilities": [],
|
||||
"total_assets": "1000",
|
||||
"total_equity": "1000.00",
|
||||
"total_liabilities": "0"
|
||||
},
|
||||
"currency": "USD",
|
||||
"description": "Quarterly plan, Acme",
|
||||
"kind": "deferred_revenue",
|
||||
"months": 3,
|
||||
"plan": [
|
||||
{
|
||||
"amount": "333.33",
|
||||
"date": "2026-01-31"
|
||||
},
|
||||
{
|
||||
"amount": "333.33",
|
||||
"date": "2026-02-28"
|
||||
},
|
||||
{
|
||||
"amount": "333.34",
|
||||
"date": "2026-03-31"
|
||||
}
|
||||
],
|
||||
"posted": [
|
||||
"2026-01-31",
|
||||
"2026-02-28",
|
||||
"2026-03-31"
|
||||
],
|
||||
"profit_and_loss": {
|
||||
"end": "2026-03-31",
|
||||
"expenses": [],
|
||||
"revenue": [
|
||||
{
|
||||
"amount": "1000.00",
|
||||
"code": "4000",
|
||||
"name": "Subscription Revenue"
|
||||
}
|
||||
],
|
||||
"start": "2026-01-01",
|
||||
"total_expenses": "0",
|
||||
"total_revenue": "1000.00"
|
||||
},
|
||||
"remaining": "0",
|
||||
"start": "2026-01-01",
|
||||
"total": "1000"
|
||||
},
|
||||
"prepaid": {
|
||||
"balance_sheet": {
|
||||
"as_of": "2026-05-31",
|
||||
"assets": [
|
||||
{
|
||||
"amount": "-1200",
|
||||
"code": "1000",
|
||||
"name": "Cash"
|
||||
},
|
||||
{
|
||||
"amount": "900",
|
||||
"code": "1300",
|
||||
"name": "Prepaid Expenses"
|
||||
}
|
||||
],
|
||||
"current_earnings": "-300",
|
||||
"equity": [],
|
||||
"liabilities": [],
|
||||
"total_assets": "-300",
|
||||
"total_equity": "-300",
|
||||
"total_liabilities": "0"
|
||||
},
|
||||
"currency": "USD",
|
||||
"description": "Liability insurance",
|
||||
"kind": "prepaid_expense",
|
||||
"months": 12,
|
||||
"plan": [
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-03-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-04-30"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-05-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-06-30"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-07-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-08-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-09-30"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-10-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-11-30"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2026-12-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2027-01-31"
|
||||
},
|
||||
{
|
||||
"amount": "100",
|
||||
"date": "2027-02-28"
|
||||
}
|
||||
],
|
||||
"posted": [
|
||||
"2026-03-31",
|
||||
"2026-04-30",
|
||||
"2026-05-31"
|
||||
],
|
||||
"profit_and_loss": {
|
||||
"end": "2026-05-31",
|
||||
"expenses": [
|
||||
{
|
||||
"amount": "300",
|
||||
"code": "6300",
|
||||
"name": "Insurance"
|
||||
}
|
||||
],
|
||||
"revenue": [],
|
||||
"start": "2026-03-01",
|
||||
"total_expenses": "300",
|
||||
"total_revenue": "0"
|
||||
},
|
||||
"remaining": "900",
|
||||
"start": "2026-03-01",
|
||||
"total": "1200"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
{
|
||||
"2025": {
|
||||
"excluded_card_payments": [],
|
||||
"other_receipts": [],
|
||||
"threshold": "600",
|
||||
"through": null,
|
||||
"undetermined_payments": [],
|
||||
"unresolved": [],
|
||||
"untagged_payments": [],
|
||||
"vendors": [
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "misc"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "misc"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Ace Rentals",
|
||||
"not_reportable": "0",
|
||||
"paid": "0",
|
||||
"reportable": false,
|
||||
"status": "under_threshold",
|
||||
"tin_on_file": false,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 2
|
||||
},
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Dana",
|
||||
"not_reportable": "0",
|
||||
"paid": "300",
|
||||
"reportable": false,
|
||||
"status": "under_threshold",
|
||||
"tin_on_file": true,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 1
|
||||
},
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Sam",
|
||||
"not_reportable": "0",
|
||||
"paid": "0",
|
||||
"reportable": false,
|
||||
"status": "under_threshold",
|
||||
"tin_on_file": true,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 3
|
||||
}
|
||||
],
|
||||
"year": 2025
|
||||
},
|
||||
"2026": {
|
||||
"excluded_card_payments": [
|
||||
{
|
||||
"amount": "5000",
|
||||
"date": "2026-04-01",
|
||||
"entry_id": 8,
|
||||
"instrument": null,
|
||||
"vendor_id": 3
|
||||
}
|
||||
],
|
||||
"other_receipts": [],
|
||||
"threshold": "2000",
|
||||
"through": null,
|
||||
"undetermined_payments": [],
|
||||
"unresolved": [],
|
||||
"untagged_payments": [
|
||||
10
|
||||
],
|
||||
"vendors": [
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "misc"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "misc"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Ace Rentals",
|
||||
"not_reportable": "0",
|
||||
"paid": "1200",
|
||||
"reportable": false,
|
||||
"status": "under_threshold",
|
||||
"tin_on_file": false,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 2
|
||||
},
|
||||
{
|
||||
"decided": null,
|
||||
"decision": "undetermined",
|
||||
"decision_needed": true,
|
||||
"decisions": [],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Bigco",
|
||||
"not_reportable": "0",
|
||||
"paid": "9000",
|
||||
"reportable": false,
|
||||
"status": "undetermined",
|
||||
"tin_on_file": false,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 4
|
||||
},
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "0",
|
||||
"name": "Dana",
|
||||
"not_reportable": "0",
|
||||
"paid": "2200",
|
||||
"reportable": true,
|
||||
"status": "reportable",
|
||||
"tin_on_file": true,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 1
|
||||
},
|
||||
{
|
||||
"decided": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
},
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"decision_needed": false,
|
||||
"decisions": [
|
||||
{
|
||||
"decision": {
|
||||
"files": "nec"
|
||||
},
|
||||
"effective": null,
|
||||
"source": {
|
||||
"decided_by": "Riley Chen",
|
||||
"decided_on": "2026-01-05"
|
||||
}
|
||||
}
|
||||
],
|
||||
"effective": null,
|
||||
"excluded_card": "5000",
|
||||
"name": "Sam",
|
||||
"not_reportable": "0",
|
||||
"paid": "0",
|
||||
"reportable": false,
|
||||
"status": "under_threshold",
|
||||
"tin_on_file": true,
|
||||
"undetermined": "0",
|
||||
"vendor_id": 3
|
||||
}
|
||||
],
|
||||
"year": 2026
|
||||
}
|
||||
}
|
||||
@@ -811,3 +811,94 @@ fn a_month_that_rounds_to_nothing_is_never_a_posting() {
|
||||
assert_eq!(s.next().unwrap(), Some(d(3, 31)));
|
||||
assert_eq!(s.remaining().unwrap(), dec("0.01"));
|
||||
}
|
||||
|
||||
/// The plan as JSON: one object per period, in plan order.
|
||||
fn plan_values(plan: Vec<(NaiveDate, Decimal)>) -> Vec<serde_json::Value> {
|
||||
plan.into_iter()
|
||||
.map(|(date, amount)| serde_json::json!({"date": date, "amount": amount}))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Golden (oracle Layer 1): the two hand-verified amortization fixtures,
|
||||
/// every period, rounding remainder and running balance recomputed in
|
||||
/// plan/golden-worksheets/amortization-plans.md before this test was run.
|
||||
/// A year of prepaid insurance at 100.00 a month (three months posted,
|
||||
/// 900.00 left) and three months of deferred revenue at 333.33, 333.33,
|
||||
/// 333.34 (the last period takes the rounding, so the three sum to
|
||||
/// 1,000.00 exactly: rules.md B-16).
|
||||
#[test]
|
||||
fn golden_amortization_plans() {
|
||||
let mut b = books();
|
||||
post(&mut b.l, d(3, 1), b.prepaid, b.cash, "1200");
|
||||
let prepaid_id =
|
||||
b.l.register_schedule(NewSchedule {
|
||||
description: "Liability insurance".into(),
|
||||
kind: ScheduleKind::PrepaidExpense,
|
||||
total: usd("1200"),
|
||||
start: d(3, 1),
|
||||
months: 12,
|
||||
balance_account: b.prepaid,
|
||||
pl_account: b.insurance,
|
||||
convention: ledger_core::ScheduleConvention::MonthlyEven,
|
||||
})
|
||||
.unwrap();
|
||||
for (month, _) in b.l.get_schedule(prepaid_id).unwrap().due(d(5, 31)).unwrap() {
|
||||
b.l.post_schedule_month(prepaid_id, month).unwrap();
|
||||
}
|
||||
let prepaid_schedule = b.l.get_schedule(prepaid_id).unwrap().clone();
|
||||
let prepaid = serde_json::json!({
|
||||
"description": prepaid_schedule.description,
|
||||
"kind": prepaid_schedule.kind,
|
||||
"total": prepaid_schedule.total.amount,
|
||||
"currency": prepaid_schedule.total.currency.code(),
|
||||
"start": prepaid_schedule.start,
|
||||
"months": prepaid_schedule.months,
|
||||
"posted": prepaid_schedule.posted,
|
||||
"plan": plan_values(prepaid_schedule.plan().unwrap()),
|
||||
"remaining": prepaid_schedule.remaining().unwrap(),
|
||||
"profit_and_loss": profit_and_loss_for_period(&b.l, d(3, 1), d(5, 31), None).unwrap(),
|
||||
"balance_sheet": balance_sheet_as_of(&b.l, d(5, 31)).unwrap(),
|
||||
});
|
||||
|
||||
let mut b = books();
|
||||
post(&mut b.l, d(1, 1), b.cash, b.deferred, "1000");
|
||||
let deferred_id =
|
||||
b.l.register_schedule(NewSchedule {
|
||||
description: "Quarterly plan, Acme".into(),
|
||||
kind: ScheduleKind::DeferredRevenue,
|
||||
total: usd("1000"),
|
||||
start: d(1, 1),
|
||||
months: 3,
|
||||
balance_account: b.deferred,
|
||||
pl_account: b.revenue,
|
||||
convention: ledger_core::ScheduleConvention::MonthlyEven,
|
||||
})
|
||||
.unwrap();
|
||||
for (month, _) in
|
||||
b.l.get_schedule(deferred_id)
|
||||
.unwrap()
|
||||
.due(d(12, 31))
|
||||
.unwrap()
|
||||
{
|
||||
b.l.post_schedule_month(deferred_id, month).unwrap();
|
||||
}
|
||||
let deferred_schedule = b.l.get_schedule(deferred_id).unwrap().clone();
|
||||
let deferred = serde_json::json!({
|
||||
"description": deferred_schedule.description,
|
||||
"kind": deferred_schedule.kind,
|
||||
"total": deferred_schedule.total.amount,
|
||||
"currency": deferred_schedule.total.currency.code(),
|
||||
"start": deferred_schedule.start,
|
||||
"months": deferred_schedule.months,
|
||||
"posted": deferred_schedule.posted,
|
||||
"plan": plan_values(deferred_schedule.plan().unwrap()),
|
||||
"remaining": deferred_schedule.remaining().unwrap(),
|
||||
"profit_and_loss": profit_and_loss_for_period(&b.l, d(1, 1), d(3, 31), None).unwrap(),
|
||||
"balance_sheet": balance_sheet_as_of(&b.l, d(3, 31)).unwrap(),
|
||||
});
|
||||
|
||||
let got = serde_json::json!({"prepaid": prepaid, "deferred": deferred});
|
||||
let want: serde_json::Value =
|
||||
serde_json::from_str(include_str!("golden/amortization_plans.json")).unwrap();
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
Reference in new issue
Block a user