merge: the adapter runs schedules that take the pick, yen schedules, the IIF's options and the books' own facts (X-H1e1's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for its picks: 104 run, 104 passed, 22 for options it did not pick. A schedule plan is answered as the engine holds it (a yen month 333, a dollar month 33.33); the IIF line ending is cr-lf only when every line ends so; bookspec's setting keys map to the engine's in one place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1add7df419
12 files changed
+293
-28
No files matched your search
@@ -216,8 +216,14 @@ pub(crate) fn new_schedule(
|
|||||||
months: s.months,
|
months: s.months,
|
||||||
balance_account: account(&s.balance_account),
|
balance_account: account(&s.balance_account),
|
||||||
pl_account: account(&s.pl_account),
|
pl_account: account(&s.pl_account),
|
||||||
convention: ScheduleConvention::parse(&s.convention)
|
// A schedule that names no convention takes the engine's method for
|
||||||
.unwrap_or_else(|| panic!("{what}: schedule convention {:?}", s.convention)),
|
// new schedules (BS-prepaid-2): wanderbooks spreads new schedules by
|
||||||
|
// the day (D-11, D-37).
|
||||||
|
convention: match s.convention.as_deref() {
|
||||||
|
Some(c) => ScheduleConvention::parse(c)
|
||||||
|
.unwrap_or_else(|| panic!("{what}: schedule convention {c:?}")),
|
||||||
|
None => ScheduleConvention::Daily,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +364,8 @@ impl<'a> Books<'a> {
|
|||||||
&what,
|
&what,
|
||||||
);
|
);
|
||||||
if let Some(c) = &a.tax_category {
|
if let Some(c) = &a.tax_category {
|
||||||
took(self.store.set_account_tax(account, Some(c), None), &what);
|
let percent = a.deductible_percent.as_deref().map(|p| exact(p, &what));
|
||||||
|
took(self.store.set_account_tax(account, Some(c), percent), &what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let first = ex
|
let first = ex
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
"code",
|
"code",
|
||||||
&["rename_account", "set_tax_category"],
|
&["rename_account", "set_tax_category"],
|
||||||
);
|
);
|
||||||
|
only(x.key.is_some(), "key", &["setting"]);
|
||||||
|
only(x.role.is_some(), "role", &["role_account"]);
|
||||||
only(x.name.is_some(), "name", &["rename_account"]);
|
only(x.name.is_some(), "name", &["rename_account"]);
|
||||||
only(x.category.is_some(), "category", &["set_tax_category"]);
|
only(x.category.is_some(), "category", &["set_tax_category"]);
|
||||||
only(x.account.is_some(), "account", &["add_account"]);
|
only(x.account.is_some(), "account", &["add_account"]);
|
||||||
@@ -144,6 +146,9 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|||||||
"invoice_numbers" => check_invoice_numbers(b, x),
|
"invoice_numbers" => check_invoice_numbers(b, x),
|
||||||
"draft_state" => check_draft_state(b, x),
|
"draft_state" => check_draft_state(b, x),
|
||||||
"evidence" => check_evidence(b, x),
|
"evidence" => check_evidence(b, x),
|
||||||
|
"setting" => check_setting(b, x),
|
||||||
|
"role_account" => check_role_account(b, x),
|
||||||
|
"tax_summary" => check_tax_summary(b, x),
|
||||||
q => {
|
q => {
|
||||||
let &(_, by) = FORMAT_QUERIES
|
let &(_, by) = FORMAT_QUERIES
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ impl Books<'_> {
|
|||||||
("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()),
|
("assign_role", e.assign_role.is_some()),
|
||||||
|
("set_setting", e.set_setting.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, discard_draft or assign_role",
|
"{} 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, assign_role or set_setting",
|
||||||
self.ex.id
|
self.ex.id
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -827,6 +828,22 @@ impl Books<'_> {
|
|||||||
// account before it writes anything (BS-ledger-19).
|
// account before it writes anything (BS-ledger-19).
|
||||||
self.store.assign_role(&a.role, Some(account))
|
self.store.assign_role(&a.role, Some(account))
|
||||||
}
|
}
|
||||||
|
"set_setting" => {
|
||||||
|
let s = e.set_setting.as_ref().expect("checked: a setting");
|
||||||
|
// The books' own journaled command: the fact and who decided
|
||||||
|
// it are kept in the journal (BS-ledger-9).
|
||||||
|
let change = Change {
|
||||||
|
key: engine_setting_key(&s.key).to_string(),
|
||||||
|
value: Some(Value::String(s.value.clone())),
|
||||||
|
};
|
||||||
|
let source = Source {
|
||||||
|
decided_by: s.decided_by.clone(),
|
||||||
|
decided_on: date(&s.decided_on, what),
|
||||||
|
citation: None,
|
||||||
|
note: None,
|
||||||
|
};
|
||||||
|
self.store.change_settings(&[change], &source).map(|_| ())
|
||||||
|
}
|
||||||
other => unreachable!("{other} is no event"),
|
other => unreachable!("{other} is no event"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ pub(crate) fn every_bookspec_example_holds() {
|
|||||||
("party_tin_last4", 5),
|
("party_tin_last4", 5),
|
||||||
("iif_lines", 1),
|
("iif_lines", 1),
|
||||||
("iif_changes", 1),
|
("iif_changes", 1),
|
||||||
|
("iif_line_ending", 1),
|
||||||
|
("setting", 1),
|
||||||
|
("role_account", 1),
|
||||||
|
("tax_summary", 1),
|
||||||
("period", 6),
|
("period", 6),
|
||||||
("day", 1),
|
("day", 1),
|
||||||
("calendar_year", 1),
|
("calendar_year", 1),
|
||||||
@@ -162,17 +166,19 @@ pub(crate) fn every_bookspec_example_holds() {
|
|||||||
// of BS-arap-2 (documents-kept-apart), -7, -8, -9, -10 (compare-exactly),
|
// of BS-arap-2 (documents-kept-apart), -7, -8, -9, -10 (compare-exactly),
|
||||||
// -11 (recovery-movement), -12 (net-of-expected-discount), -13
|
// -11 (recovery-movement), -12 (net-of-expected-discount), -13
|
||||||
// (net-against-the-deposit) and -14 (apportion-across-the-lines),
|
// (net-against-the-deposit) and -14 (apportion-across-the-lines),
|
||||||
// BS-prepaid-2's equal-months and BS-ledger-20's refuse (each option's
|
// BS-prepaid-2's equal-months, BS-prepaid-4's cent rule and BS-ledger-20's
|
||||||
// example, so no allow-list grows), BS-entry-6's check-only-when-posting
|
// refuse (each option's example, so no allow-list grows), BS-entry-6's
|
||||||
// and BS-ledger-17's reversal-needs-its-own (wanderbooks refuses a line on
|
// check-only-when-posting and BS-ledger-17's reversal-needs-its-own
|
||||||
// a header as it is added, and a reversal needs no evidence of its own),
|
// (wanderbooks refuses a line on a header as it is added, and a reversal
|
||||||
// and BS-period-4's allow-partial-overlap, BS-1099-2's
|
// needs no evidence of its own), BS-format-5's file place, -6's one
|
||||||
// carry-the-last-amount and BS-partner-8's nowhere (wanderbooks nests
|
// fiscal year, -8's closes-written and -4's platform line ending,
|
||||||
// periods, refuses a year whose threshold it does not know, and keeps
|
// BS-ledger-21's round-per-account, BS-period-4's allow-partial-overlap,
|
||||||
// the full TIN outside the books).
|
// 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(),
|
||||||
16,
|
22,
|
||||||
"the sixteen unpicked-option examples: {skipped:?}"
|
"the twenty-two unpicked-option examples: {skipped:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ pub(crate) use std::path::{Path, PathBuf};
|
|||||||
pub(crate) use chrono::{Datelike, NaiveDate};
|
pub(crate) use chrono::{Datelike, NaiveDate};
|
||||||
pub(crate) use ledger_core::calendar::{PeriodDefaults, period_defaults};
|
pub(crate) use ledger_core::calendar::{PeriodDefaults, period_defaults};
|
||||||
pub(crate) use ledger_core::parties::{Basis, MoneyAccounts};
|
pub(crate) use ledger_core::parties::{Basis, MoneyAccounts};
|
||||||
pub(crate) use ledger_core::settings::{Company, Source};
|
pub(crate) use ledger_core::settings::{Change, Company, Source};
|
||||||
pub(crate) use ledger_core::tax_capital::TaxCapitalRow;
|
pub(crate) use ledger_core::tax_capital::TaxCapitalRow;
|
||||||
pub(crate) use ledger_core::{
|
pub(crate) use ledger_core::{
|
||||||
AccountType, AssetId, BillFields, CashFlowParams, CashFlowSection, CashFlowStatement, CloseTo,
|
AccountType, AssetId, BillFields, CashFlowParams, CashFlowSection, CashFlowStatement, CloseTo,
|
||||||
@@ -55,8 +55,8 @@ pub(crate) use ledger_core::{
|
|||||||
InstrumentId, InstrumentKind, InvoiceFields, Ledger, LedgerError, MemberCapital, MemberClose,
|
InstrumentId, InstrumentKind, InvoiceFields, Ledger, LedgerError, MemberCapital, MemberClose,
|
||||||
Money, NewAsset, NewSchedule, PartyId, PartyMember, PartyShare, PaymentAccounts,
|
Money, NewAsset, NewSchedule, PartyId, PartyMember, PartyShare, PaymentAccounts,
|
||||||
ReconcilingKind, Role, ScheduleConvention, ScheduleId, ScheduleKind, Share, Side, Terms,
|
ReconcilingKind, Role, ScheduleConvention, ScheduleId, ScheduleKind, Share, Side, Terms,
|
||||||
TinFacts, TinType, VendorId, W9Facts, cash_flow, members_equity, profit_and_loss_for_period,
|
TinFacts, TinType, VendorId, W9Facts, cash_flow, control_account, members_equity,
|
||||||
trial_balance_as_of, vendor_1099_report,
|
profit_and_loss_for_period, tax_summary, 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 ledger_vault::{Tin, Vault};
|
||||||
@@ -74,6 +74,7 @@ pub(crate) use books::*;
|
|||||||
pub(crate) use check::check;
|
pub(crate) use check::check;
|
||||||
pub(crate) use common::*;
|
pub(crate) use common::*;
|
||||||
pub(crate) use queries::assets::*;
|
pub(crate) use queries::assets::*;
|
||||||
|
pub(crate) use queries::book::*;
|
||||||
pub(crate) use queries::commands::*;
|
pub(crate) use queries::commands::*;
|
||||||
pub(crate) use queries::dates::*;
|
pub(crate) use queries::dates::*;
|
||||||
pub(crate) use queries::documents::*;
|
pub(crate) use queries::documents::*;
|
||||||
|
|||||||
@@ -110,10 +110,14 @@ impl Books<'_> {
|
|||||||
let mut m = JsonMap::new();
|
let mut m = JsonMap::new();
|
||||||
let mut total = Decimal::ZERO;
|
let mut total = Decimal::ZERO;
|
||||||
for (d, amount) in &plan {
|
for (d, amount) in &plan {
|
||||||
m.insert(d.to_string(), Value::String(figure(*amount)));
|
// The plan's own amounts are already whole units of the
|
||||||
|
// currency (BS-prepaid-1, -4): a yen schedule's month is 333,
|
||||||
|
// not 333.00, and a dollar schedule's 33.33. Printed as they
|
||||||
|
// stand, never padded to the cent.
|
||||||
|
m.insert(d.to_string(), Value::String(amount.to_string()));
|
||||||
total += *amount;
|
total += *amount;
|
||||||
}
|
}
|
||||||
m.insert("total".to_string(), Value::String(figure(total)));
|
m.insert("total".to_string(), Value::String(total.to_string()));
|
||||||
Ok(Value::Object(m))
|
Ok(Value::Object(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
use crate::*;
|
||||||
|
|
||||||
|
/// The engine's key for a bookspec setting key (`SETTING_KEYS`): the
|
||||||
|
/// engine's own settings carry the `company.` prefix. A key the schema
|
||||||
|
/// admits and this map lacks is a gap in the adapter, so it panics.
|
||||||
|
pub(crate) fn engine_setting_key(bookspec_key: &str) -> &'static str {
|
||||||
|
match bookspec_key {
|
||||||
|
"fiscal_year_start" => "company.fiscal_year_start",
|
||||||
|
other => panic!("the adapter maps no engine key for the bookspec setting {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Books<'_> {
|
||||||
|
/// A `setting` query (BS-ledger-9): the value the books keep, with who
|
||||||
|
/// decided it and when. The books hold their settings in the journal
|
||||||
|
/// (wanderbooks' pick, facts-in-the-books), so a replay reaches them.
|
||||||
|
pub(crate) fn answer_setting(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
|
let rule = RuleId::new(Area::Ledger, 9);
|
||||||
|
let key = q.key.as_deref().ok_or_else(|| self.missing("key"))?;
|
||||||
|
let recorded = self
|
||||||
|
.l()
|
||||||
|
.settings()
|
||||||
|
.get(engine_setting_key(key))
|
||||||
|
.ok_or_else(|| {
|
||||||
|
Refusal::new(rule.clone(), format!("no setting {key:?} in the books"))
|
||||||
|
})?;
|
||||||
|
let value = match &recorded.value {
|
||||||
|
Value::String(s) => s.clone(),
|
||||||
|
other => other.to_string(),
|
||||||
|
};
|
||||||
|
Ok(json_figures([
|
||||||
|
("value".to_string(), value),
|
||||||
|
("decided_by".to_string(), recorded.source.decided_by.clone()),
|
||||||
|
(
|
||||||
|
"decided_on".to_string(),
|
||||||
|
recorded.source.decided_on.to_string(),
|
||||||
|
),
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `role_account` query (BS-ledger-18): the account a control role
|
||||||
|
/// posts to, read from the books' own journaled assignment.
|
||||||
|
pub(crate) fn answer_role_account(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
|
let rule = RuleId::new(Area::Ledger, 18);
|
||||||
|
let role = q.role.as_deref().ok_or_else(|| self.missing("role"))?;
|
||||||
|
let control = control_account(role)
|
||||||
|
.ok_or_else(|| Refusal::new(rule.clone(), format!("{role:?} is no control role")))?;
|
||||||
|
let account = self
|
||||||
|
.l()
|
||||||
|
.role_account(control)
|
||||||
|
.and_then(|id| self.l().chart().get(id))
|
||||||
|
.map(|a| a.code.clone())
|
||||||
|
.unwrap_or_else(|| "unassigned".to_string());
|
||||||
|
Ok(json_figures([("account".to_string(), account)]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `tax_summary` query (BS-ledger-21): each category's deductible
|
||||||
|
/// amount, as `tax::tax_summary` figures it (one rounding, on the
|
||||||
|
/// category's exact total: wanderbooks' pick, round-once-on-the-total).
|
||||||
|
pub(crate) fn answer_tax_summary(&self, q: &Query) -> Result<Value, Refusal> {
|
||||||
|
let rule = RuleId::new(Area::Ledger, 21);
|
||||||
|
let (from, to) = self.q_period(q)?;
|
||||||
|
let summary = tax_summary(self.l(), from, to, None).map_err(|e| engine_refusal(rule, e))?;
|
||||||
|
let mut out = JsonMap::new();
|
||||||
|
for line in summary
|
||||||
|
.income
|
||||||
|
.iter()
|
||||||
|
.chain(&summary.cost_of_goods)
|
||||||
|
.chain(&summary.deductions)
|
||||||
|
.chain(&summary.separately_stated)
|
||||||
|
{
|
||||||
|
out.insert(line.category.clone(), Value::String(figure(line.tax)));
|
||||||
|
}
|
||||||
|
Ok(Value::Object(out))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check one `setting` expectation (BS-ledger-9): the value, who decided it
|
||||||
|
/// and when, as the books keep them.
|
||||||
|
pub(crate) fn check_setting(b: &Books<'_>, x: &Expect) {
|
||||||
|
let ex = b.ex;
|
||||||
|
undated(ex, x);
|
||||||
|
exactly(
|
||||||
|
ex,
|
||||||
|
x,
|
||||||
|
&["decided_by", "decided_on", "value"]
|
||||||
|
.map(String::from)
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
let got = b
|
||||||
|
.answer(&x.query())
|
||||||
|
.unwrap_or_else(|e| panic!("{}: setting refused ({})", ex.id, e.reason));
|
||||||
|
let got = got.as_object().expect("a setting answers figures");
|
||||||
|
for (k, want) in x.figures(&ex.id) {
|
||||||
|
assert_eq!(
|
||||||
|
got.get(k).and_then(Value::as_str),
|
||||||
|
Some(want.as_str()),
|
||||||
|
"{}: setting {k}",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check one `role_account` expectation (BS-ledger-18): the code the role's
|
||||||
|
/// account has in the books.
|
||||||
|
pub(crate) fn check_role_account(b: &Books<'_>, x: &Expect) {
|
||||||
|
let ex = b.ex;
|
||||||
|
undated(ex, x);
|
||||||
|
exactly(ex, x, &["account".to_string()].into());
|
||||||
|
let got = b
|
||||||
|
.answer(&x.query())
|
||||||
|
.unwrap_or_else(|e| panic!("{}: role_account refused ({})", ex.id, e.reason));
|
||||||
|
let got = got.as_object().expect("a role account answers figures");
|
||||||
|
for (k, want) in x.figures(&ex.id) {
|
||||||
|
assert_eq!(
|
||||||
|
got.get(k).and_then(Value::as_str),
|
||||||
|
Some(want.as_str()),
|
||||||
|
"{}: role_account {k}",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check one `tax_summary` expectation (BS-ledger-21): each category's
|
||||||
|
/// deductible amount, by category key.
|
||||||
|
pub(crate) fn check_tax_summary(b: &Books<'_>, x: &Expect) {
|
||||||
|
let ex = b.ex;
|
||||||
|
let (from, to) = period(ex, x);
|
||||||
|
assert!(
|
||||||
|
from <= to,
|
||||||
|
"{}: tax_summary from {from} after to {to}",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
let got = b
|
||||||
|
.answer(&x.query())
|
||||||
|
.unwrap_or_else(|e| panic!("{}: tax_summary refused ({})", ex.id, e.reason));
|
||||||
|
let got = got.as_object().expect("a tax summary answers figures");
|
||||||
|
for (k, want) in x.figures(&ex.id) {
|
||||||
|
assert_eq!(
|
||||||
|
got.get(k).and_then(Value::as_str),
|
||||||
|
Some(want.as_str()),
|
||||||
|
"{}: tax_summary {k}",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,29 @@ impl Books<'_> {
|
|||||||
.collect(),
|
.collect(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
"iif_line_ending" => {
|
||||||
|
// The file's own bytes: every line break is CR LF
|
||||||
|
// (wanderbooks' pick, cr-lf), every one a bare LF, or a mix
|
||||||
|
// of the two, which is neither. The engine has no notion of
|
||||||
|
// a host, so the example's `setup.host_line_ending` is not
|
||||||
|
// read here.
|
||||||
|
let text = iif.text.as_str();
|
||||||
|
let lf = text.matches('\n').count();
|
||||||
|
let crlf = text.matches("\r\n").count();
|
||||||
|
let ending = if lf == 0 {
|
||||||
|
"none"
|
||||||
|
} else if lf == crlf {
|
||||||
|
"cr-lf"
|
||||||
|
} else if crlf == 0 {
|
||||||
|
"lf"
|
||||||
|
} else {
|
||||||
|
"mixed"
|
||||||
|
};
|
||||||
|
Ok(json_figures([(
|
||||||
|
"line_ending".to_string(),
|
||||||
|
ending.to_string(),
|
||||||
|
)]))
|
||||||
|
}
|
||||||
_ => Ok(Value::Array(
|
_ => Ok(Value::Array(
|
||||||
iif.changes
|
iif.changes
|
||||||
.iter()
|
.iter()
|
||||||
@@ -53,7 +76,7 @@ impl Books<'_> {
|
|||||||
|
|
||||||
/// The formats appendix's queries, and the test (another crate's) that
|
/// The formats appendix's queries, and the test (another crate's) that
|
||||||
/// checks them against the engine.
|
/// checks them against the engine.
|
||||||
pub(crate) const FORMAT_QUERIES: [(&str, &str); 2] = [
|
pub(crate) const FORMAT_QUERIES: [(&str, &str); 3] = [
|
||||||
(
|
(
|
||||||
"iif_lines",
|
"iif_lines",
|
||||||
"ledger-package the_bookspec_iif_example_matches_the_engine",
|
"ledger-package the_bookspec_iif_example_matches_the_engine",
|
||||||
@@ -62,6 +85,10 @@ pub(crate) const FORMAT_QUERIES: [(&str, &str); 2] = [
|
|||||||
"iif_changes",
|
"iif_changes",
|
||||||
"ledger-package the_bookspec_iif_example_matches_the_engine",
|
"ledger-package the_bookspec_iif_example_matches_the_engine",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"iif_line_ending",
|
||||||
|
"ledger-core the_runner_reports_every_claimed_rule_green",
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// A refused format query (BS-format-10): the appendix and the day, no
|
/// A refused format query (BS-format-10): the appendix and the day, no
|
||||||
@@ -98,6 +125,16 @@ pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
|
|||||||
assert_eq!(r.len(), 3, "{}: iif_changes row {r:?}", ex.id);
|
assert_eq!(r.len(), 3, "{}: iif_changes row {r:?}", ex.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
("iif_line_ending", Values::Figures(f)) => {
|
||||||
|
assert!(
|
||||||
|
matches!(
|
||||||
|
f.get("line_ending").map(String::as_str),
|
||||||
|
Some("cr-lf" | "lf")
|
||||||
|
),
|
||||||
|
"{}: iif_line_ending is cr-lf or lf: {f:?}",
|
||||||
|
ex.id
|
||||||
|
);
|
||||||
|
}
|
||||||
(q, _) => panic!("{}: {q}: values of the wrong shape", ex.id),
|
(q, _) => panic!("{}: {q}: values of the wrong shape", ex.id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub(crate) mod assets;
|
pub(crate) mod assets;
|
||||||
|
pub(crate) mod book;
|
||||||
pub(crate) mod commands;
|
pub(crate) mod commands;
|
||||||
pub(crate) mod dates;
|
pub(crate) mod dates;
|
||||||
pub(crate) mod documents;
|
pub(crate) mod documents;
|
||||||
@@ -93,6 +94,9 @@ impl Books<'_> {
|
|||||||
"invoice_numbers" => self.answer_invoice_numbers(q),
|
"invoice_numbers" => self.answer_invoice_numbers(q),
|
||||||
"draft_state" => self.answer_draft_state(q),
|
"draft_state" => self.answer_draft_state(q),
|
||||||
"evidence" => self.answer_evidence(q),
|
"evidence" => self.answer_evidence(q),
|
||||||
|
"setting" => self.answer_setting(q),
|
||||||
|
"role_account" => self.answer_role_account(q),
|
||||||
|
"tax_summary" => self.answer_tax_summary(q),
|
||||||
"run" => self.answer_run(q),
|
"run" => self.answer_run(q),
|
||||||
"disposal" => self.answer_disposal(q),
|
"disposal" => self.answer_disposal(q),
|
||||||
"depreciation_schedule" => self.answer_depreciation_schedule(q),
|
"depreciation_schedule" => self.answer_depreciation_schedule(q),
|
||||||
@@ -127,7 +131,7 @@ impl Books<'_> {
|
|||||||
.map(|a| Value::String(format!("{} {}", a.code, a.name)))
|
.map(|a| Value::String(format!("{} {}", a.code, a.name)))
|
||||||
.collect(),
|
.collect(),
|
||||||
)),
|
)),
|
||||||
"iif_lines" | "iif_changes" => self.answer_iif(q),
|
"iif_lines" | "iif_changes" | "iif_line_ending" => self.answer_iif(q),
|
||||||
"rename_account" | "add_account" | "set_tax_category" => self.answer_command(q),
|
"rename_account" | "add_account" | "set_tax_category" => self.answer_command(q),
|
||||||
other => Err(Refusal::new(
|
other => Err(Refusal::new(
|
||||||
RuleId::new(Area::Ledger, 1),
|
RuleId::new(Area::Ledger, 1),
|
||||||
|
|||||||
@@ -332,7 +332,17 @@ appendix: the file line by line and its changes, derived by hand);
|
|||||||
(`iif_declares_accounts_by_role_and_balances_every_transaction`,
|
(`iif_declares_accounts_by_role_and_balances_every_transaction`,
|
||||||
`iif_without_as_of_is_as_of_today_and_ties_to_the_trial_balance`),
|
`iif_without_as_of_is_as_of_today_and_ties_to_the_trial_balance`),
|
||||||
`mcp_journeys.rs` (`mcp_import_export`,
|
`mcp_journeys.rs` (`mcp_import_export`,
|
||||||
`the_default_period_never_shortens_the_iif_or_the_package`).
|
`the_default_period_never_shortens_the_iif_or_the_package`); bookspec
|
||||||
|
examples `format-cr-lf-on-an-lf-platform` and
|
||||||
|
`format-platform-line-ending-on-an-lf-platform` (BS-format-4),
|
||||||
|
`format-docnum-is-the-entry-id` and `format-docnum-is-the-files-place`
|
||||||
|
(BS-format-5), `format-everything-through-as-of-spans-years` and
|
||||||
|
`format-one-fiscal-year-holds-its-year` (BS-format-6),
|
||||||
|
`format-closes-left-out` and `format-closes-written` (BS-format-8) and
|
||||||
|
`format-no-customer-or-vendor-name` (BS-format-9), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`; the line ending is asked by
|
||||||
|
the iif_line_ending query (the adapter's answer_iif), which reads the file's own bytes: cr-lf when every line break is CR LF, lf when every one is a bare LF, mixed when it is neither. The engine has no notion of a host, so the adapter does not use an example's host_line_ending setup.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
@@ -191,12 +191,15 @@ 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`; bookspec example
|
`ledger-store` replay of `role.assigned`; bookspec examples
|
||||||
`ledger-a-role-on-a-header-or-wrong-typed-account-is-refused` (BS-ledger-19,
|
`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
|
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`
|
role on a postable revenue account are refused through `Store::assign_role`
|
||||||
and `Ledger::check_assign_role`'s `ControlAccountMismatch`, and the chart is
|
and `Ledger::check_assign_role`'s `ControlAccountMismatch`, and the chart is
|
||||||
as it was), run by
|
as it was) and `ledger-a-role-assignment-is-a-fact-in-the-books`
|
||||||
|
(BS-ledger-18, the option picked: the receivables role assigned to 1300 is
|
||||||
|
journaled by `Store::assign_role`, read back by the `role_account` query
|
||||||
|
from the books alone, and found again by the store's replay), run by
|
||||||
`every_bookspec_example_holds` and
|
`every_bookspec_example_holds` and
|
||||||
`the_runner_reports_every_claimed_rule_green`.
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
@@ -235,7 +238,12 @@ per check, 2,000 by hand, with posts between records and every record
|
|||||||
checked to change no figure or entry;
|
checked to change no figure or entry;
|
||||||
`the_fiscal_year_stays_under_closed_periods`); `ledger-cli`
|
`the_fiscal_year_stays_under_closed_periods`); `ledger-cli`
|
||||||
`tests/spec_kept.rs`; Lean `Step.record_changes_no_figure`,
|
`tests/spec_kept.rs`; Lean `Step.record_changes_no_figure`,
|
||||||
`Reachable.records`; fuzz `fuzz_settings_replay`.
|
`Reachable.records`; fuzz `fuzz_settings_replay`; bookspec example
|
||||||
|
`ledger-a-setting-is-a-fact-in-the-books` (the option picked: the owner's
|
||||||
|
fiscal-year change is journaled by `Store::change_settings` with who decided
|
||||||
|
it and when, read back by the setting query, and the trial balance before
|
||||||
|
and after is the same), run by `every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
@@ -317,14 +325,22 @@ bookspec `examples/rename-changes-no-amount.toml`.
|
|||||||
**Pick:** warn versus refuse: CHOICE (Pub. 583: "the law does not require any specific kind of records"; the owner, 2026-10-20: warn by default, header accounts exempt, the first company set to refuse at the P3 cutover). A category's deductible amount rounds once, on the category total: CHOICE (the owner, 2026-11-07, D-67). The arithmetic is `kernel::deductible_amount`, so Kani proves the one rounding and the bridge carries it to `Decimal`.
|
**Pick:** warn versus refuse: CHOICE (Pub. 583: "the law does not require any specific kind of records"; the owner, 2026-10-20: warn by default, header accounts exempt, the first company set to refuse at the P3 cutover). A category's deductible amount rounds once, on the category total: CHOICE (the owner, 2026-11-07, D-67). The arithmetic is `kernel::deductible_amount`, so Kani proves the one rounding and the bridge carries it to `Decimal`.
|
||||||
|
|
||||||
**Enforced:** `kernel::deductible_amount` (`tax::tax_summary`'s one
|
**Enforced:** `kernel::deductible_amount` (`tax::tax_summary`'s one
|
||||||
rounding). **Checked:** `ledger-core`
|
rounding; the bookspec `tax_summary` query answers its lines by category).
|
||||||
|
**Checked:** `ledger-core`
|
||||||
`tests/tax.rs` (the rounding: `a_category_rounds_its_deductible_amount_once_not_per_account`,
|
`tests/tax.rs` (the rounding: `a_category_rounds_its_deductible_amount_once_not_per_account`,
|
||||||
`a_category_rounds_once_across_different_percents`); Kani
|
`a_category_rounds_once_across_different_percents`); Kani
|
||||||
`deductible_amount_rounds_once`, `deductible_amount_refuses_overflow`;
|
`deductible_amount_rounds_once`, `deductible_amount_refuses_overflow`;
|
||||||
bridge `deductible_amount_agrees`; Lean `bookspec/lean/Bookspec/Deductible.lean`
|
bridge `deductible_amount_agrees`; Lean `bookspec/lean/Bookspec/Deductible.lean`
|
||||||
(`Deductible.near`, `Deductible.tie_away_pos`, `Deductible.tie_away_neg`, `Deductible.sign`, `Deductible.neg`, `Deductible.of_sum`,
|
(`Deductible.near`, `Deductible.tie_away_pos`, `Deductible.tie_away_neg`, `Deductible.sign`, `Deductible.neg`, `Deductible.of_sum`,
|
||||||
`Deductible.per_account_differs`, `Deductible.scale_books`, `Deductible.scale_percents`: the one rounding, at any
|
`Deductible.per_account_differs`, `Deductible.scale_books`, `Deductible.scale_percents`: the one rounding, at any
|
||||||
number of accounts and any sizes); bookspec `examples/tax-category-required.toml`.
|
number of accounts and any sizes); bookspec `examples/tax-category-required.toml`
|
||||||
|
and the two BS-ledger-21 examples
|
||||||
|
`ledger-a-categorys-deductible-amount-rounds-once` (the option picked:
|
||||||
|
two accounts of 1.01 at 50% give 1.01, the exact sum rounded once) and
|
||||||
|
`ledger-a-categorys-deductible-amount-rounds-per-account` (the other option:
|
||||||
|
0.51 + 0.51 = 1.02), whose `tax_summary` query is `tax::tax_summary`, run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,19 @@ Rules: B-16.
|
|||||||
`daily_plans_pin_month_end_clamping`,
|
`daily_plans_pin_month_end_clamping`,
|
||||||
`prop_daily_plan_sums_exactly_and_lands_on_month_ends`,
|
`prop_daily_plan_sums_exactly_and_lands_on_month_ends`,
|
||||||
`prop_monthly_even_plan_is_unchanged`; `ledger-cli`
|
`prop_monthly_even_plan_is_unchanged`; `ledger-cli`
|
||||||
`mcp_daily_schedule`.
|
`mcp_daily_schedule`; bookspec examples
|
||||||
|
`schedule-daily-deferred-revenue`,
|
||||||
|
`schedule-daily-small-first-and-last-month`,
|
||||||
|
`schedule-equal-months-give-each-month-the-same-share` (each names no
|
||||||
|
convention, so it takes the pick, and starts mid-month where daily and
|
||||||
|
equal months differ; the equal-months one also names BS-prepaid-3's
|
||||||
|
start-on-any-day), `schedule-equal-months-start-on-the-first`,
|
||||||
|
`prepaid-a-new-yen-schedule-rounds-to-whole-yen` (BS-prepaid-4's minor
|
||||||
|
unit: 333, 333 and 334 yen) and
|
||||||
|
`prepaid-a-yen-schedule-under-the-cent-rule-keeps-cents` (the other
|
||||||
|
option: 333.33, 333.33 and 333.34), run by
|
||||||
|
`every_bookspec_example_holds` and
|
||||||
|
`the_runner_reports_every_claimed_rule_green`.
|
||||||
|
|
||||||
### Product rules
|
### Product rules
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user