merge: the adapter runs refused dates, amounts, periods, roles, exports, 1099 years and returns (X-H1d's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for its picks on refused input: 95 run, 95 passed, 16 for options it did not pick. The IIF export now keeps its typed refusal (an entry on two receivable or payable accounts is BS-format-10's), where it had stringified it; the package and the MCP tool still show the same text. A test walks every role the schema lists through the engine's control_account, so the two lists cannot drift apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f5826d45a4
20 files changed
+250
-24
No files matched your search
Generated
+1
@@ -3977,6 +3977,7 @@ dependencies = [
|
|||||||
"ledger-import",
|
"ledger-import",
|
||||||
"ledger-package",
|
"ledger-package",
|
||||||
"ledger-store",
|
"ledger-store",
|
||||||
|
"ledger-vault",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"num-rational",
|
"num-rational",
|
||||||
"proptest",
|
"proptest",
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "2b3b6
|
|||||||
ledger-package = { path = "../ledger-package" }
|
ledger-package = { path = "../ledger-package" }
|
||||||
ledger-import = { path = "../ledger-import" }
|
ledger-import = { path = "../ledger-import" }
|
||||||
ledger-store = { path = "../ledger-store" }
|
ledger-store = { path = "../ledger-store" }
|
||||||
|
ledger-vault = { path = "../ledger-vault" }
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ pub(crate) struct Books<'a> {
|
|||||||
/// What each disposal took, by asset id, as the engine computed it
|
/// What each disposal took, by asset id, as the engine computed it
|
||||||
/// just before posting it.
|
/// just before posting it.
|
||||||
pub(crate) disposals: BTreeMap<String, DisposalPreview>,
|
pub(crate) disposals: BTreeMap<String, DisposalPreview>,
|
||||||
|
/// The TIN vault outside the books, when the setup puts a full TIN
|
||||||
|
/// there (BS-partner-8's outside-the-books option): the real
|
||||||
|
/// `ledger_vault::Vault`, in the books' own directory, holding only
|
||||||
|
/// what the example spells.
|
||||||
|
pub(crate) vault: Option<Vault>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A store command's result, unwrapped: the example's books take it.
|
/// A store command's result, unwrapped: the example's books take it.
|
||||||
@@ -289,6 +294,7 @@ impl<'a> Books<'a> {
|
|||||||
posted: Vec::new(),
|
posted: Vec::new(),
|
||||||
runs: BTreeMap::new(),
|
runs: BTreeMap::new(),
|
||||||
disposals: BTreeMap::new(),
|
disposals: BTreeMap::new(),
|
||||||
|
vault: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,6 +449,34 @@ impl<'a> Books<'a> {
|
|||||||
assert_eq!(total, Decimal::ONE, "{}: the shares sum to 1", ex.id);
|
assert_eq!(total, Decimal::ONE, "{}: the shares sum to 1", ex.id);
|
||||||
}
|
}
|
||||||
let parties = add_parties(ex, &mut self.store);
|
let parties = add_parties(ex, &mut self.store);
|
||||||
|
// The vault outside the books (BS-partner-8's outside-the-books
|
||||||
|
// option): the real encrypted store, in the books' own directory,
|
||||||
|
// holding the full TINs the example puts there and nothing else.
|
||||||
|
if !s.vault_tins.is_empty() {
|
||||||
|
let vault = Vault::open(
|
||||||
|
&self._dir.path().join("vault"),
|
||||||
|
&self._dir.path().join("vault.key"),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.unwrap_or_else(|e| panic!("{}: the TIN vault: {e}", ex.id));
|
||||||
|
for v in &s.vault_tins {
|
||||||
|
let id = *parties.get(&v.party).unwrap_or_else(|| {
|
||||||
|
panic!("{}: vault TIN: party {:?} not in setup", ex.id, v.party)
|
||||||
|
});
|
||||||
|
let digits: String = v.tin.chars().filter(|c| *c != '-').collect();
|
||||||
|
let kind = if digits.starts_with('9') {
|
||||||
|
ledger_vault::TinType::Itin
|
||||||
|
} else {
|
||||||
|
ledger_vault::TinType::Ssn
|
||||||
|
};
|
||||||
|
let tin = Tin::new(&v.tin, kind)
|
||||||
|
.unwrap_or_else(|e| panic!("{}: vault TIN {:?}: {e}", ex.id, v.tin));
|
||||||
|
vault
|
||||||
|
.put_tin(id, &tin)
|
||||||
|
.unwrap_or_else(|e| panic!("{}: vault TIN: {e}", ex.id));
|
||||||
|
}
|
||||||
|
self.vault = Some(vault);
|
||||||
|
}
|
||||||
// A member who is a party (by name, with the member role), as the
|
// A member who is a party (by name, with the member role), as the
|
||||||
// settings' members are (settings::Company::party_members).
|
// settings' members are (settings::Company::party_members).
|
||||||
let party_members: Vec<PartyMember> = members
|
let party_members: Vec<PartyMember> = members
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
only(
|
only(
|
||||||
x.party.is_some(),
|
x.party.is_some(),
|
||||||
"party",
|
"party",
|
||||||
&["party_part", "party_totals", "party_tin_last4"],
|
&[
|
||||||
|
"party_part",
|
||||||
|
"party_totals",
|
||||||
|
"party_tin_last4",
|
||||||
|
"return_tin",
|
||||||
|
],
|
||||||
);
|
);
|
||||||
only(x.basis.is_some(), "basis", &["party_totals"]);
|
only(x.basis.is_some(), "basis", &["party_totals"]);
|
||||||
only(x.payee.is_some(), "payee", &["vendor_1099"]);
|
only(x.payee.is_some(), "payee", &["vendor_1099"]);
|
||||||
@@ -65,6 +70,10 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
"add_account",
|
"add_account",
|
||||||
"set_tax_category",
|
"set_tax_category",
|
||||||
"period",
|
"period",
|
||||||
|
"vendor_1099",
|
||||||
|
"iif_lines",
|
||||||
|
"iif_changes",
|
||||||
|
"return_tin",
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
if COMMANDS.contains(&q) {
|
if COMMANDS.contains(&q) {
|
||||||
@@ -77,12 +86,29 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
check_command(ex, l, x);
|
check_command(ex, l, x);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// Anything else shows its values; a period may be refused instead.
|
// Anything else shows its values; a period may be refused instead, and
|
||||||
|
// so may a 1099 worksheet, an export and a return (BS-1099-2,
|
||||||
|
// BS-format-10, BS-partner-8). The refusal is the engine's own.
|
||||||
assert!(
|
assert!(
|
||||||
x.refused.is_some() != x.values.as_ref().is_some_and(|v| !v.is_empty()),
|
x.refused.is_some() != x.values.as_ref().is_some_and(|v| !v.is_empty()),
|
||||||
"{}: {q} expects values (a period: values or refused)",
|
"{}: {q} expects values (a period: values or refused)",
|
||||||
ex.id
|
ex.id
|
||||||
);
|
);
|
||||||
|
if let Some(want) = &x.refused
|
||||||
|
&& matches!(
|
||||||
|
q,
|
||||||
|
"vendor_1099" | "iif_lines" | "iif_changes" | "return_tin"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
match b.answer(&x.query()) {
|
||||||
|
Err(r) => assert_eq!(&r.reason, want, "{}: {q} refused ({})", ex.id, r.reason),
|
||||||
|
Ok(v) => panic!("{}: {q} answered {v}, expected refused: {want}", ex.id),
|
||||||
|
}
|
||||||
|
if matches!(q, "iif_lines" | "iif_changes") {
|
||||||
|
check_format_refused(ex, x);
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
match q {
|
match q {
|
||||||
"period" => check_period(ex, x),
|
"period" => check_period(ex, x),
|
||||||
"day" => check_day(ex, x),
|
"day" => check_day(ex, x),
|
||||||
@@ -110,6 +136,7 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
"party_part" => check_party_part(b, x),
|
"party_part" => check_party_part(b, x),
|
||||||
"party_totals" => check_party_totals(b, x),
|
"party_totals" => check_party_totals(b, x),
|
||||||
"party_tin_last4" => check_party_tin_last4(b, x),
|
"party_tin_last4" => check_party_tin_last4(b, x),
|
||||||
|
"return_tin" => check_return_tin(b, x),
|
||||||
"project" => check_project(b, x),
|
"project" => check_project(b, x),
|
||||||
"aging" => check_aging(b, x),
|
"aging" => check_aging(b, x),
|
||||||
"document_dates" => check_document_dates(b, x),
|
"document_dates" => check_document_dates(b, x),
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ pub(crate) fn refusal(e: &LedgerError) -> String {
|
|||||||
LedgerError::ParentTypeMismatch { .. } => "parent_type_mismatch",
|
LedgerError::ParentTypeMismatch { .. } => "parent_type_mismatch",
|
||||||
LedgerError::EntryAlreadyReversed(..) => "already_reversed",
|
LedgerError::EntryAlreadyReversed(..) => "already_reversed",
|
||||||
LedgerError::ClosedPeriod(..) => "period_closed",
|
LedgerError::ClosedPeriod(..) => "period_closed",
|
||||||
|
// A period that shares days with another while neither contains the
|
||||||
|
// other (BS-period-4, and BS-period-2 for an engine that nests).
|
||||||
|
LedgerError::PeriodsOverlap { .. } => "period_overlaps",
|
||||||
// A line on a header account (a placeholder takes no postings),
|
// A line on a header account (a placeholder takes no postings),
|
||||||
// BS-entry-1 and BS-entry-6.
|
// BS-entry-1 and BS-entry-6.
|
||||||
LedgerError::PlaceholderAccount(_) => "header_account",
|
LedgerError::PlaceholderAccount(_) => "header_account",
|
||||||
@@ -174,6 +177,16 @@ pub(crate) fn refusal(e: &LedgerError) -> String {
|
|||||||
LedgerError::EntryAlreadyPosted(_)
|
LedgerError::EntryAlreadyPosted(_)
|
||||||
| LedgerError::PostedEntryImmutable
|
| LedgerError::PostedEntryImmutable
|
||||||
| LedgerError::UnknownEntry(_) => "not_drafted",
|
| LedgerError::UnknownEntry(_) => "not_drafted",
|
||||||
|
// A date outside 0001-01-01 through 9999-12-31, or an amount past
|
||||||
|
// a line's cap: refused rather than wrapped (BS-entry-4,
|
||||||
|
// BS-entry-7).
|
||||||
|
LedgerError::DateOutOfRange(_) => "date_out_of_range",
|
||||||
|
LedgerError::AmountOutOfRange => "amount_out_of_range",
|
||||||
|
// A role assigned to an account that is not postable or not of the
|
||||||
|
// role's type (BS-ledger-19).
|
||||||
|
LedgerError::ControlAccountMismatch { .. } => "role_account_mismatch",
|
||||||
|
// A 1099 threshold for a year the books do not know (BS-1099-2).
|
||||||
|
LedgerError::RuleNotKnown { .. } => "unknown_1099_year",
|
||||||
other => return format!("another refusal: {other}"),
|
other => return format!("another refusal: {other}"),
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ impl Books<'_> {
|
|||||||
("set_draft_state", e.set_draft_state.is_some()),
|
("set_draft_state", e.set_draft_state.is_some()),
|
||||||
("attach_receipt", e.attach_receipt.is_some()),
|
("attach_receipt", e.attach_receipt.is_some()),
|
||||||
("discard_draft", e.discard_draft.is_some()),
|
("discard_draft", e.discard_draft.is_some()),
|
||||||
|
("assign_role", e.assign_role.is_some()),
|
||||||
];
|
];
|
||||||
match kinds.iter().filter(|(_, given)| *given).collect::<Vec<_>>()[..] {
|
match kinds.iter().filter(|(_, given)| *given).collect::<Vec<_>>()[..] {
|
||||||
[(kind, _)] => kind,
|
[(kind, _)] => kind,
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules, register_schedule, post_draft, set_draft_state, attach_receipt or discard_draft",
|
"{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules, register_schedule, post_draft, set_draft_state, attach_receipt, discard_draft or assign_role",
|
||||||
self.ex.id
|
self.ex.id
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -467,6 +468,8 @@ impl Books<'_> {
|
|||||||
// then thrown away. The refusal is the engine's, never
|
// then thrown away. The refusal is the engine's, never
|
||||||
// rebuilt here.
|
// rebuilt here.
|
||||||
let mut rehearsal = self.rehearsal(what);
|
let mut rehearsal = self.rehearsal(what);
|
||||||
|
// The books' own new-work entry point, so a date past the
|
||||||
|
// calendar (BS-entry-7) is refused there, not rebuilt here.
|
||||||
let entry = rehearsal.create_entry(day(), description)?;
|
let entry = rehearsal.create_entry(day(), description)?;
|
||||||
for (i, line) in e.lines.iter().enumerate() {
|
for (i, line) in e.lines.iter().enumerate() {
|
||||||
let side = match line.side.as_str() {
|
let side = match line.side.as_str() {
|
||||||
@@ -817,6 +820,13 @@ impl Books<'_> {
|
|||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
"assign_role" => {
|
||||||
|
let a = e.assign_role.as_ref().expect("checked: a role assignment");
|
||||||
|
let account = self.id(&a.account);
|
||||||
|
// The books' own journaled command: it checks the role's
|
||||||
|
// account before it writes anything (BS-ledger-19).
|
||||||
|
self.store.assign_role(&a.role, Some(account))
|
||||||
|
}
|
||||||
other => unreachable!("{other} is no event"),
|
other => unreachable!("{other} is no event"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -918,3 +928,18 @@ impl Books<'_> {
|
|||||||
.unwrap_or_else(|r| panic!("{what}: {}", r.reason));
|
.unwrap_or_else(|r| panic!("{what}: {}", r.reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Every role the schema's list names is a role this engine's command
|
||||||
|
/// takes, spelled the same: the adapter passes `assign_role`'s key
|
||||||
|
/// straight to `Store::assign_role`, so a key this engine spelled
|
||||||
|
/// differently would make every example that named it a refused
|
||||||
|
/// assignment the example did not ask for.
|
||||||
|
#[test]
|
||||||
|
fn every_listed_role_is_the_engine_role() {
|
||||||
|
for &(role, _) in bookspec_checker::ACCOUNT_ROLES {
|
||||||
|
assert!(
|
||||||
|
ledger_core::control_account(role).is_some(),
|
||||||
|
"{role}: the schema names a role this engine does not have"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -165,10 +165,14 @@ pub(crate) fn every_bookspec_example_holds() {
|
|||||||
// BS-prepaid-2's equal-months and BS-ledger-20's refuse (each option's
|
// BS-prepaid-2's equal-months and BS-ledger-20's refuse (each option's
|
||||||
// example, so no allow-list grows), BS-entry-6's check-only-when-posting
|
// example, so no allow-list grows), BS-entry-6's check-only-when-posting
|
||||||
// and BS-ledger-17's reversal-needs-its-own (wanderbooks refuses a line on
|
// and BS-ledger-17's reversal-needs-its-own (wanderbooks refuses a line on
|
||||||
// a header as it is added, and a reversal needs no evidence of its own).
|
// a header as it is added, and a reversal needs no evidence of its own),
|
||||||
|
// and BS-period-4's allow-partial-overlap, BS-1099-2's
|
||||||
|
// carry-the-last-amount and BS-partner-8's nowhere (wanderbooks nests
|
||||||
|
// periods, refuses a year whose threshold it does not know, and keeps
|
||||||
|
// the full TIN outside the books).
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
skipped.len(),
|
skipped.len(),
|
||||||
13,
|
16,
|
||||||
"the thirteen unpicked-option examples: {skipped:?}"
|
"the sixteen unpicked-option examples: {skipped:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@ pub(crate) use ledger_core::{
|
|||||||
trial_balance_as_of, vendor_1099_report,
|
trial_balance_as_of, vendor_1099_report,
|
||||||
};
|
};
|
||||||
pub(crate) use ledger_store::{DepreciationRun, DisposalPreview, Store, StoreError};
|
pub(crate) use ledger_store::{DepreciationRun, DisposalPreview, Store, StoreError};
|
||||||
|
pub(crate) use ledger_vault::{Tin, Vault};
|
||||||
pub(crate) use rust_decimal::Decimal;
|
pub(crate) use rust_decimal::Decimal;
|
||||||
|
|
||||||
pub(crate) use bookspec_checker::{
|
pub(crate) use bookspec_checker::{
|
||||||
|
|||||||
@@ -3,8 +3,16 @@ use crate::*;
|
|||||||
impl Books<'_> {
|
impl Books<'_> {
|
||||||
pub(crate) fn answer_iif(&self, q: &Query) -> Result<Value, Refusal> {
|
pub(crate) fn answer_iif(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
let as_of = self.q_day(q)?;
|
let as_of = self.q_day(q)?;
|
||||||
let iif = export_iif(self.l(), &self.ex.setup.cash_accounts, as_of)
|
let iif = export_iif(self.l(), &self.ex.setup.cash_accounts, as_of).map_err(|e| {
|
||||||
.map_err(|e| engine_refusal(RuleId::new(Area::Format, 2), e))?;
|
// An entry on more than one A/R or A/P account is BS-format-10's
|
||||||
|
// refusal; every other IIF refusal stays BS-format-2's.
|
||||||
|
match e {
|
||||||
|
ledger_import::IifError::SeveralReceivablePayableAccounts { .. } => {
|
||||||
|
Refusal::of_reason("several_receivable_payable_accounts")
|
||||||
|
}
|
||||||
|
other => engine_refusal(RuleId::new(Area::Format, 2), other),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
match q.name.as_str() {
|
match q.name.as_str() {
|
||||||
"iif_lines" => {
|
"iif_lines" => {
|
||||||
let mut lines: Vec<&str> = iif.text.split("\r\n").collect();
|
let mut lines: Vec<&str> = iif.text.split("\r\n").collect();
|
||||||
@@ -56,9 +64,9 @@ pub(crate) const FORMAT_QUERIES: [(&str, &str); 2] = [
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// A format query's shape, checked here; its values are checked by
|
/// A refused format query (BS-format-10): the appendix and the day, no
|
||||||
/// [`FORMAT_QUERIES`]' test.
|
/// values.
|
||||||
pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
|
pub(crate) fn check_format_refused(ex: &Example, x: &Expect) {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ex.appendix.as_deref(),
|
ex.appendix.as_deref(),
|
||||||
Some("formats"),
|
Some("formats"),
|
||||||
@@ -66,7 +74,6 @@ pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
|
|||||||
ex.id,
|
ex.id,
|
||||||
x.query
|
x.query
|
||||||
);
|
);
|
||||||
// ledger-package reads the as_of itself: given, never defaulted.
|
|
||||||
assert!(x.as_of.is_some(), "{}: {} gives as_of", ex.id, x.query);
|
assert!(x.as_of.is_some(), "{}: {} gives as_of", ex.id, x.query);
|
||||||
day(ex, x);
|
day(ex, x);
|
||||||
assert!(
|
assert!(
|
||||||
@@ -75,6 +82,15 @@ pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
|
|||||||
ex.id,
|
ex.id,
|
||||||
x.query
|
x.query
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A format query's shape, checked here; its values are checked by
|
||||||
|
/// [`FORMAT_QUERIES`]' test.
|
||||||
|
pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
|
||||||
|
check_format_refused(ex, x);
|
||||||
|
if x.refused.is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
match (x.query.as_str(), x.values(&ex.id)) {
|
match (x.query.as_str(), x.values(&ex.id)) {
|
||||||
("iif_lines", Values::Lines(_)) => {}
|
("iif_lines", Values::Lines(_)) => {}
|
||||||
("iif_changes", Values::Rows(rows)) => {
|
("iif_changes", Values::Rows(rows)) => {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ impl Books<'_> {
|
|||||||
"party_part" => self.answer_party_part(q),
|
"party_part" => self.answer_party_part(q),
|
||||||
"party_totals" => self.answer_party_totals(q),
|
"party_totals" => self.answer_party_totals(q),
|
||||||
"party_tin_last4" => self.answer_party_tin_last4(q),
|
"party_tin_last4" => self.answer_party_tin_last4(q),
|
||||||
|
"return_tin" => self.answer_return_tin(q),
|
||||||
"project" => self.answer_project(q),
|
"project" => self.answer_project(q),
|
||||||
"aging" => self.answer_aging(q),
|
"aging" => self.answer_aging(q),
|
||||||
"document_dates" => self.answer_document_dates(q),
|
"document_dates" => self.answer_document_dates(q),
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ impl Books<'_> {
|
|||||||
let l = self.l();
|
let l = self.l();
|
||||||
let sources = self.payment_accounts()?;
|
let sources = self.payment_accounts()?;
|
||||||
let r = vendor_1099_report(l, year, None, &sources, &self.party_members, Some(to))
|
let r = vendor_1099_report(l, year, None, &sources, &self.party_members, Some(to))
|
||||||
.map_err(|e| engine_refusal(RuleId::new(Area::Tax1099, 1), e))?;
|
.map_err(|e| match e {
|
||||||
|
// A year whose threshold is not published is BS-1099-2's
|
||||||
|
// refusal, never a guess (the engine picks
|
||||||
|
// refuse-an-unknown-year).
|
||||||
|
LedgerError::RuleNotKnown { .. } => Refusal::of_reason("unknown_1099_year"),
|
||||||
|
other => engine_refusal(RuleId::new(Area::Tax1099, 1), other),
|
||||||
|
})?;
|
||||||
let _ = from;
|
let _ = from;
|
||||||
let mut m = JsonMap::new();
|
let mut m = JsonMap::new();
|
||||||
for (name, vendor) in &self.payees {
|
for (name, vendor) in &self.payees {
|
||||||
@@ -41,7 +47,10 @@ impl Books<'_> {
|
|||||||
&self.party_members,
|
&self.party_members,
|
||||||
Some(to),
|
Some(to),
|
||||||
)
|
)
|
||||||
.map_err(|e| engine_refusal(RuleId::new(Area::Tax1099, 1), e))?;
|
.map_err(|e| match e {
|
||||||
|
LedgerError::RuleNotKnown { .. } => Refusal::of_reason("unknown_1099_year"),
|
||||||
|
other => engine_refusal(RuleId::new(Area::Tax1099, 1), other),
|
||||||
|
})?;
|
||||||
let line = r.vendors.iter().find(|l| l.vendor_id == v).ok_or_else(|| {
|
let line = r.vendors.iter().find(|l| l.vendor_id == v).ok_or_else(|| {
|
||||||
Refusal::new(
|
Refusal::new(
|
||||||
RuleId::new(Area::Tax1099, 1),
|
RuleId::new(Area::Tax1099, 1),
|
||||||
@@ -159,6 +168,34 @@ impl Books<'_> {
|
|||||||
Ok(json_figures([("tin_last4".to_string(), got.to_string())]))
|
Ok(json_figures([("tin_last4".to_string(), got.to_string())]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The full TIN a return produced for `party` carries (BS-partner-8,
|
||||||
|
/// outside-the-books): read from the vault outside the books, never
|
||||||
|
/// from the books' records, which hold only the last four. A party
|
||||||
|
/// whose number the vault does not hold is refused `tin_not_held`.
|
||||||
|
pub(crate) fn return_tin(&self, party: PartyId) -> Result<String, Refusal> {
|
||||||
|
let vault = self
|
||||||
|
.vault
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| Refusal::of_reason("tin_not_held"))?;
|
||||||
|
let tin = vault
|
||||||
|
.tin(party)
|
||||||
|
.map_err(|_| Refusal::of_reason("tin_not_held"))?
|
||||||
|
.ok_or_else(|| Refusal::of_reason("tin_not_held"))?;
|
||||||
|
Ok(tin.formatted())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn answer_return_tin(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
|
let name = q.party.as_deref().ok_or_else(|| self.missing("party"))?;
|
||||||
|
let party = *self.parties.get(name).ok_or_else(|| {
|
||||||
|
Refusal::new(
|
||||||
|
RuleId::new(Area::Partner, 8),
|
||||||
|
format!("party {name:?} not in setup"),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let tin = self.return_tin(party)?;
|
||||||
|
Ok(json_figures([("tin".to_string(), tin)]))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn answer_project(&self, q: &Query) -> Result<Value, Refusal> {
|
pub(crate) fn answer_project(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
let name = q
|
let name = q
|
||||||
.project
|
.project
|
||||||
@@ -475,6 +512,30 @@ pub(crate) fn check_project(b: &Books<'_>, x: &Expect) {
|
|||||||
/// Check one `party_tin_last4` expectation: the last four of the party's
|
/// Check one `party_tin_last4` expectation: the last four of the party's
|
||||||
/// TIN the books keep (its TIN facts', else its W-9's; `""` for none:
|
/// TIN the books keep (its TIN facts', else its W-9's; `""` for none:
|
||||||
/// BS-partner-2).
|
/// BS-partner-2).
|
||||||
|
/// Check one `return_tin` expectation: the full TIN a return produced for
|
||||||
|
/// the party carries, taken from the vault outside the books
|
||||||
|
/// (BS-partner-8's outside-the-books option).
|
||||||
|
pub(crate) fn check_return_tin(b: &Books<'_>, x: &Expect) {
|
||||||
|
let ex = b.ex;
|
||||||
|
assert!(
|
||||||
|
x.from.is_none() && x.to.is_none() && x.as_of.is_none(),
|
||||||
|
"{}: return_tin takes no dates",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
let party = expect_party(b, x);
|
||||||
|
exactly(ex, x, &["tin".to_string()].into());
|
||||||
|
let got = b
|
||||||
|
.return_tin(party)
|
||||||
|
.unwrap_or_else(|r| panic!("{}: return_tin refused ({})", ex.id, r.reason));
|
||||||
|
assert_eq!(
|
||||||
|
got,
|
||||||
|
x.figures(&ex.id)["tin"],
|
||||||
|
"{}: {:?}'s return TIN",
|
||||||
|
ex.id,
|
||||||
|
x.party
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn check_party_tin_last4(b: &Books<'_>, x: &Expect) {
|
pub(crate) fn check_party_tin_last4(b: &Books<'_>, x: &Expect) {
|
||||||
let ex = b.ex;
|
let ex = b.ex;
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -1513,7 +1513,7 @@ impl BooksServer {
|
|||||||
} else {
|
} else {
|
||||||
cash
|
cash
|
||||||
};
|
};
|
||||||
ledger_package::export_iif(store.ledger(), cash, as_of)
|
ledger_package::export_iif(store.ledger(), cash, as_of).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
/// The general journal as JSON or CSV: each entry posted in the
|
/// The general journal as JSON or CSV: each entry posted in the
|
||||||
/// period (BS-period-3, as the XLSX journal), in posting order.
|
/// period (BS-period-3, as the XLSX journal), in posting order.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub fn export_iif(
|
|||||||
ledger: &Ledger,
|
ledger: &Ledger,
|
||||||
cash_codes: &[String],
|
cash_codes: &[String],
|
||||||
as_of: NaiveDate,
|
as_of: NaiveDate,
|
||||||
) -> Result<ledger_import::Iif, String> {
|
) -> Result<ledger_import::Iif, ledger_import::IifError> {
|
||||||
use ledger_import::{QbAccountType as Qb, iif_accounts, iif_classes, journal_to_iif};
|
use ledger_import::{QbAccountType as Qb, iif_accounts, iif_classes, journal_to_iif};
|
||||||
let fixed: std::collections::HashSet<AccountId> = ledger
|
let fixed: std::collections::HashSet<AccountId> = ledger
|
||||||
.registered_assets()
|
.registered_assets()
|
||||||
@@ -71,5 +71,5 @@ pub fn export_iif(
|
|||||||
.posted_entries()
|
.posted_entries()
|
||||||
.filter(|e| e.date() <= as_of && !closes.contains(&e.id()))
|
.filter(|e| e.date() <= as_of && !closes.contains(&e.id()))
|
||||||
.collect();
|
.collect();
|
||||||
journal_to_iif(&accounts, &iif_classes(ledger), &entries).map_err(|e| e.to_string())
|
journal_to_iif(&accounts, &iif_classes(ledger), &entries)
|
||||||
}
|
}
|
||||||
@@ -564,7 +564,7 @@ pub fn build_package<B: PackageBooks + ?Sized>(
|
|||||||
let seq = books.journal_seq();
|
let seq = books.journal_seq();
|
||||||
// The journal through as_of for QuickBooks, closes left out, and what
|
// The journal through as_of for QuickBooks, closes left out, and what
|
||||||
// it writes differently (INVARIANT 8).
|
// it writes differently (INVARIANT 8).
|
||||||
let iif = export_iif(ledger, cash_codes, as_of)?;
|
let iif = export_iif(ledger, cash_codes, as_of).map_err(|e| e.to_string())?;
|
||||||
let (warnings, iif_changes) = (iif.warnings(), iif.changes.len());
|
let (warnings, iif_changes) = (iif.warnings(), iif.changes.len());
|
||||||
let receivable_payable: Vec<String> = iif
|
let receivable_payable: Vec<String> = iif
|
||||||
.receivable_payable
|
.receivable_payable
|
||||||
|
|||||||
@@ -62,7 +62,14 @@ Kani `payment_bucket_is_the_table`, `payment_split_is_exact`,
|
|||||||
`the_untagged_note_counts_only_money_out`,
|
`the_untagged_note_counts_only_money_out`,
|
||||||
`the_other_receipts_note_says_what_each_entry_did` (ledger-package); the
|
`the_other_receipts_note_says_what_each_entry_did` (ledger-package); the
|
||||||
MCP tests through a real books server (ledger-cli); bookspec
|
MCP tests through a real books server (ledger-cli); bookspec
|
||||||
`examples/1099-*.toml`.
|
`examples/1099-*.toml`, including
|
||||||
|
`1099-a-worksheet-for-an-unpublished-year-is-refused` (BS-1099-2, the
|
||||||
|
option picked: a 2027 worksheet is refused through
|
||||||
|
`LedgerError::RuleNotKnown` as unknown_1099_year, never guessed), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`; the example for the option
|
||||||
|
not picked, `1099-a-worksheet-for-an-unpublished-year-carries-the-last-amount`,
|
||||||
|
is skipped.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,13 @@ replay pair; `a_foreign_amount_and_a_rate_take_at_most_ten_places`),
|
|||||||
`out_of_range_amount_is_rejected`; `ledger-store` `tests/bounds.rs`,
|
`out_of_range_amount_is_rejected`; `ledger-store` `tests/bounds.rs`,
|
||||||
`tests/store.rs` `a_journaled_foreign_line_finer_than_ten_places_still_opens`;
|
`tests/store.rs` `a_journaled_foreign_line_finer_than_ten_places_still_opens`;
|
||||||
`ledger-cli` `server.rs` `periods_are_a_year_and_a_month`,
|
`ledger-cli` `server.rs` `periods_are_a_year_and_a_month`,
|
||||||
`dates_are_four_digit_years_and_real_days`.
|
`dates_are_four_digit_years_and_real_days`; bookspec examples
|
||||||
|
`entry-a-date-past-9999-is-refused` and
|
||||||
|
`entry-an-amount-past-the-line-cap-is-refused` (BS-entry-7, the option picked:
|
||||||
|
the books refuse `try_create_entry`'s date past 9999 and `add_line`'s amount
|
||||||
|
past the cap, read off `LedgerError::DateOutOfRange` and
|
||||||
|
`LedgerError::AmountOutOfRange`), run by `every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,14 @@ a file. **Checked:** `ledger-import` `tests/spec_import.rs`
|
|||||||
`tests/package.rs`
|
`tests/package.rs`
|
||||||
(`the_package_refuses_an_entry_on_two_receivable_or_payable_accounts`);
|
(`the_package_refuses_an_entry_on_two_receivable_or_payable_accounts`);
|
||||||
`ledger-cli` `oracle_mcp.rs`
|
`ledger-cli` `oracle_mcp.rs`
|
||||||
(`iif_and_the_package_refuse_an_entry_on_two_receivable_or_payable_accounts`).
|
(`iif_and_the_package_refuse_an_entry_on_two_receivable_or_payable_accounts`);
|
||||||
|
bookspec example
|
||||||
|
`format-an-export-of-an-entry-on-two-control-accounts-is-refused`
|
||||||
|
(BS-format-10, the option picked: an entry an earlier version wrote on a
|
||||||
|
receivable and a payable account is refused for export, read off
|
||||||
|
`IifError::SeveralReceivablePayableAccounts`), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
**Enforced:** `ledger_import::iif` (`field`, `iif_accounts`, `iif_classes`,
|
**Enforced:** `ledger_import::iif` (`field`, `iif_accounts`, `iif_classes`,
|
||||||
`journal_to_iif`, `Iif::warnings`, `Iif::changes`, `Iif::receivable_payable`),
|
`journal_to_iif`, `Iif::warnings`, `Iif::changes`, `Iif::receivable_payable`),
|
||||||
|
|||||||
@@ -191,7 +191,14 @@ None.
|
|||||||
`check_assign_role`, `Ledger::check_renumber_account` (an assigned role
|
`check_assign_role`, `Ledger::check_renumber_account` (an assigned role
|
||||||
frees its code); the control guard and `Ledger::control_check` (B-38).
|
frees its code); the control guard and `Ledger::control_check` (B-38).
|
||||||
**Checked:** `ledger-core` `tests/spec_roles.rs`, `tests/spec_documents.rs`;
|
**Checked:** `ledger-core` `tests/spec_roles.rs`, `tests/spec_documents.rs`;
|
||||||
`ledger-store` replay of `role.assigned`.
|
`ledger-store` replay of `role.assigned`; bookspec example
|
||||||
|
`ledger-a-role-on-a-header-or-wrong-typed-account-is-refused` (BS-ledger-19,
|
||||||
|
the option picked: the receivables role on a header account and the payables
|
||||||
|
role on a postable revenue account are refused through `Store::assign_role`
|
||||||
|
and `Ledger::check_assign_role`'s `ControlAccountMismatch`, and the chart is
|
||||||
|
as it was), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,14 @@ the books' last fours).
|
|||||||
`tests/spec_parties.rs`, `tests/spec_vault.rs` (every response, every
|
`tests/spec_parties.rs`, `tests/spec_vault.rs` (every response, every
|
||||||
file handed over, the server's log, and every file in the books' folder
|
file handed over, the server's log, and every file in the books' folder
|
||||||
outside `vault/` and the files kept for their download scanned for the
|
outside `vault/` and the files kept for their download scanned for the
|
||||||
TINs in any formatting), `tests/tin_files.rs`
|
TINs in any formatting), bookspec examples
|
||||||
|
`partner-a-return-takes-the-full-tin-from-the-vault` (BS-partner-8, the
|
||||||
|
option picked: the books hold 6789 and the return takes 123-45-6789 from
|
||||||
|
the vault) and `partner-a-return-with-no-full-tin-is-refused` (the nowhere
|
||||||
|
option, which wanderbooks does not pick: the return is refused
|
||||||
|
tin_not_held), the first run by `every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`, the second skipped;
|
||||||
|
`tests/tin_files.rs`
|
||||||
(`a_tin_bearing_file_is_refused_from_every_session_and_after_a_restart`,
|
(`a_tin_bearing_file_is_refused_from_every_session_and_after_a_restart`,
|
||||||
`text_with_a_vault_tin_or_a_printed_one_is_refused_and_a_bank_export_is_not`,
|
`text_with_a_vault_tin_or_a_printed_one_is_refused_and_a_bank_export_is_not`,
|
||||||
`text_probing_for_a_tin_is_refused_alike_by_every_filing_tool`), and the
|
`text_probing_for_a_tin_is_refused_alike_by_every_filing_tool`), and the
|
||||||
|
|||||||
@@ -37,7 +37,15 @@ decision, D-73, 2026-11-08). **Checked:** Kani
|
|||||||
store property `refused_commands_never_reach_the_journal` (no draft in a
|
store property `refused_commands_never_reach_the_journal` (no draft in a
|
||||||
closed period); `periods_nest_but_never_partially_overlap`
|
closed period); `periods_nest_but_never_partially_overlap`
|
||||||
(`crates/ledger-core/tests/invariants.rs`) and `periods_nest`
|
(`crates/ledger-core/tests/invariants.rs`) and `periods_nest`
|
||||||
(`crates/ledger-core/tests/spec_ledger.rs`).
|
(`crates/ledger-core/tests/spec_ledger.rs`); bookspec example
|
||||||
|
`period-a-period-that-partly-overlaps-another-is-refused` (BS-period-4, the
|
||||||
|
option picked: a February through April period that shares days with a
|
||||||
|
closed quarter is refused through `Ledger::create_period`'s
|
||||||
|
`PeriodsOverlap`, and the quarter stands), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`; the example for the option
|
||||||
|
not picked, `period-a-period-that-partly-overlaps-another-is-allowed`, is
|
||||||
|
skipped.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user