test(core): the adapter runs a platform's payout, an asset's tag and the K-1's tax-basis note through the engine
The bookspec schema gained a `payout` event, a `tag_asset` event, an `asset_tag` query and a note on the tax-basis property line (BS-revenue-1, BS-asset-3, BS-partner-17). The adapter runs each through the engine and rebuilds none of it: a payout goes through `payouts::payout_plan`, which refuses unless gross less fee is the deposit to the cent, and its plan's lines post as one entry; a tag goes through `Store::set_asset_tag`, which refuses a tag of a wrong form and one another asset holds or ever held; the tax-basis line's note is `Note::PrepaidAtBook` read off the worksheet. The engine's InvalidPayout, InvalidAssetTag and AssetTagTaken are worded as the examples word them. Thirteen examples were added and every one the engine's picks reach passes: five are for options wanderbooks did not pick (no-tags, every-prepaid-is-cash, every-prepaid-is-property, left-open, whole-payment-to-each) and are skipped, so the skipped count is 22 + 5 = 27 and 112 of 139 run. A prepaid contract credited straight to capital is property (1,500.00 each) and a service paid through Due to Members is cash (1,000.00 each); the contract enters the tax capital at its book amount with the note; a 1,000.00 check naming Dana Studio at 600.00 counts 600.00 toward Dana's 1099. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e45c62348a
commit
a87e2d0a7a
8 files changed
+138
-11
No files matched your search
@@ -32,6 +32,7 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
||||
"depreciation_schedule",
|
||||
"register_row",
|
||||
"asset_basis",
|
||||
"asset_tag",
|
||||
],
|
||||
);
|
||||
only(x.schedule.is_some(), "schedule", &["schedule_plan"]);
|
||||
@@ -130,6 +131,7 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
||||
"register_row" => check_register_row(b, x),
|
||||
"register_totals" => check_register_totals(b, x),
|
||||
"asset_basis" => check_asset_basis(b, x),
|
||||
"asset_tag" => check_asset_tag(b, x),
|
||||
"k1_tax_basis" => check_k1_tax_basis(b, x),
|
||||
"k1_reconciliation" => check_k1_reconciliation(b, x),
|
||||
"balances" => check_balances(ex, l, x),
|
||||
|
||||
@@ -187,6 +187,16 @@ pub(crate) fn refusal(e: &LedgerError) -> String {
|
||||
LedgerError::ControlAccountMismatch { .. } => "role_account_mismatch",
|
||||
// A 1099 threshold for a year the books do not know (BS-1099-2).
|
||||
LedgerError::RuleNotKnown { .. } => "unknown_1099_year",
|
||||
// A platform's payout whose deposit is not gross less fee
|
||||
// (BS-revenue-1): `payout_plan` refuses it for no other reason that
|
||||
// the examples name.
|
||||
LedgerError::InvalidPayout(why) if why.starts_with("payout doesn't reconcile") => {
|
||||
"payout_does_not_reconcile"
|
||||
}
|
||||
// A tag of a wrong form, and one another asset holds or ever held
|
||||
// (BS-asset-3).
|
||||
LedgerError::InvalidAssetTag { .. } => "asset_tag_invalid",
|
||||
LedgerError::AssetTagTaken { .. } => "asset_tag_taken",
|
||||
other => return format!("another refusal: {other}"),
|
||||
}
|
||||
.to_string()
|
||||
|
||||
@@ -26,11 +26,13 @@ impl Books<'_> {
|
||||
("discard_draft", e.discard_draft.is_some()),
|
||||
("assign_role", e.assign_role.is_some()),
|
||||
("set_setting", e.set_setting.is_some()),
|
||||
("payout", e.payout.is_some()),
|
||||
("tag_asset", e.tag_asset.is_some()),
|
||||
];
|
||||
match kinds.iter().filter(|(_, given)| *given).collect::<Vec<_>>()[..] {
|
||||
[(kind, _)] => kind,
|
||||
_ => 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, assign_role or set_setting",
|
||||
"{} 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, set_setting, payout or tag_asset",
|
||||
self.ex.id
|
||||
),
|
||||
}
|
||||
@@ -43,7 +45,10 @@ impl Books<'_> {
|
||||
// An entry of the example's own words: dated and described. A
|
||||
// disposal is dated; the other commands date their own entries,
|
||||
// and every command describes its own.
|
||||
let own = matches!(kind, "lines" | "reverses" | "close" | "bill" | "invoice");
|
||||
let own = matches!(
|
||||
kind,
|
||||
"lines" | "reverses" | "close" | "bill" | "invoice" | "payout"
|
||||
);
|
||||
let dated = own
|
||||
|| matches!(
|
||||
kind,
|
||||
@@ -198,7 +203,10 @@ impl Books<'_> {
|
||||
let ex = self.ex.id.as_str();
|
||||
let kind = self.event_kind(n, e);
|
||||
let what = format!("{ex} event {n}");
|
||||
let own = matches!(kind, "lines" | "reverses" | "close" | "bill" | "invoice");
|
||||
let own = matches!(
|
||||
kind,
|
||||
"lines" | "reverses" | "close" | "bill" | "invoice" | "payout"
|
||||
);
|
||||
let head = self.store.head();
|
||||
let first = self.l().next_entry_id();
|
||||
let result = self.apply_event(n, e);
|
||||
@@ -412,6 +420,47 @@ impl Books<'_> {
|
||||
"{what}: wanderbooks has no draft reversal: it picks reversal-evidence-is-originals (BS-ledger-17), under which a reversal posts at once"
|
||||
),
|
||||
))),
|
||||
// A platform's payout (BS-revenue-1): the engine's own plan of its
|
||||
// lines (`payout_plan`, which refuses unless gross - fee equals the
|
||||
// deposit to the cent), posted as one entry. The plan is made
|
||||
// before anything is journaled, so a refused payout leaves nothing.
|
||||
"payout" => {
|
||||
let p = e.payout.as_ref().expect("checked: a payout");
|
||||
let line = |account: &str, amount: &str| ledger_core::PayoutLine {
|
||||
account: self.id(account),
|
||||
amount: exact(amount, what),
|
||||
class: None,
|
||||
};
|
||||
let payout = ledger_core::Payout {
|
||||
deposit_account: self.id(&p.deposit_account),
|
||||
deposit: exact(&p.deposit, what),
|
||||
revenue: vec![line(&p.revenue_account, &p.gross)],
|
||||
fees: match (&p.fee, &p.fee_account) {
|
||||
(Some(fee), Some(account)) => vec![line(account, fee)],
|
||||
_ => Vec::new(),
|
||||
},
|
||||
adjustments: Vec::new(),
|
||||
};
|
||||
let (plan, _) = ledger_core::payout_plan(&payout, self.store.ledger().chart())?;
|
||||
let entry = self.store.create_entry(day(), description)?;
|
||||
for (account, side, amount, _class) in plan {
|
||||
self.store
|
||||
.add_line(entry, account, side, Money::new(amount, self.currency))?;
|
||||
}
|
||||
if self.has_policy() {
|
||||
self.store.post_entry_checked(entry)
|
||||
} else {
|
||||
self.store.post_entry(entry)
|
||||
}
|
||||
}
|
||||
// A tag put on an asset (BS-asset-3): the engine's own command,
|
||||
// which refuses a tag of a wrong form and one another asset holds
|
||||
// or ever held.
|
||||
"tag_asset" => {
|
||||
let t = e.tag_asset.as_ref().expect("checked: a tag");
|
||||
let asset = self.asset(&t.asset, what);
|
||||
self.store.set_asset_tag(asset, &t.tag)
|
||||
}
|
||||
"post_draft" => {
|
||||
let p = e.post_draft.as_ref().expect("checked: a post");
|
||||
let entry = self.entry_of(p.entry, what);
|
||||
|
||||
@@ -115,12 +115,12 @@ pub(crate) fn every_bookspec_example_holds() {
|
||||
("cash_flow", 7),
|
||||
("trial_balance", 2),
|
||||
("profit_and_loss", 2),
|
||||
("vendor_1099_paid", 4),
|
||||
("vendor_1099_paid", 5),
|
||||
("vendor_1099", 10),
|
||||
("entry", 8),
|
||||
("balances", 4),
|
||||
("members_equity", 10),
|
||||
("k1", 3),
|
||||
("k1", 5),
|
||||
("party_part", 28),
|
||||
("party_totals", 23),
|
||||
("party_tin_last4", 5),
|
||||
@@ -145,7 +145,8 @@ pub(crate) fn every_bookspec_example_holds() {
|
||||
("register_row", 5),
|
||||
("register_totals", 1),
|
||||
("asset_basis", 6),
|
||||
("k1_tax_basis", 4),
|
||||
("asset_tag", 4),
|
||||
("k1_tax_basis", 5),
|
||||
("k1_reconciliation", 2),
|
||||
("project", 6),
|
||||
("aging", 4),
|
||||
@@ -175,10 +176,16 @@ pub(crate) fn every_bookspec_example_holds() {
|
||||
// BS-ledger-21's round-per-account, 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).
|
||||
// know, and keeps the full TIN outside the books), and X-H1e2's:
|
||||
// BS-asset-3's no-tags, BS-partner-15's every-prepaid-is-cash and
|
||||
// every-prepaid-is-property, BS-partner-17's left-open and BS-1099-5's
|
||||
// whole-payment-to-each (wanderbooks keeps asset tags, counts a contract
|
||||
// handed over as property and a vendor-paid service as cash, takes a
|
||||
// prepaid contract into the tax capital at its book amount with a note,
|
||||
// and counts only the payee's share of a shared entry).
|
||||
assert_eq!(
|
||||
skipped.len(),
|
||||
22,
|
||||
"the twenty-two unpicked-option examples: {skipped:?}"
|
||||
27,
|
||||
"the twenty-seven unpicked-option examples: {skipped:?}"
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
//! its accounts, fixed assets, schedules, parties, members, payees,
|
||||
//! payees' dated 1099 decisions and payment methods, every event (an
|
||||
//! entry, a reversal, a close, a bill, or a command that posts what is
|
||||
//! due: a depreciation run, a disposal, a schedule run or registration),
|
||||
//! due: a depreciation run, a disposal, a schedule run or registration, a
|
||||
//! platform's payout or an asset's tag),
|
||||
//! each accepted or refused as it says, with the parties, payee and
|
||||
//! payment method it is tagged with, and every change that posts no entry
|
||||
//! (a rename, a policy, an asset's correction). The books are the
|
||||
@@ -22,7 +23,7 @@
|
||||
//! `party_part`, `party_totals`, `party_tin_last4`, `period`, `day`,
|
||||
//! `calendar_year`, `account_names`, `uncategorized_accounts`, `run`,
|
||||
//! `disposal`, `depreciation_schedule`, `schedule_plan`, `register_row`,
|
||||
//! `register_totals`, `asset_basis`) are then checked value by value, and
|
||||
//! `register_totals`, `asset_basis`, `asset_tag`) are then checked value by value, and
|
||||
//! the commands it tries (`rename_account`, `add_account`,
|
||||
//! `set_tax_category`) accepted or refused on a copy of the books, each
|
||||
//! after the event it names (`after`) or the last; the formats appendix's
|
||||
|
||||
@@ -196,6 +196,19 @@ impl Books<'_> {
|
||||
]))
|
||||
}
|
||||
|
||||
/// The tag the asset carries, or `"none"` (BS-asset-3).
|
||||
pub(crate) fn answer_asset_tag(&self, q: &Query) -> Result<Value, Refusal> {
|
||||
let name = q.asset.as_deref().ok_or_else(|| self.missing("asset"))?;
|
||||
let a = self
|
||||
.l()
|
||||
.get_asset(self.asset(name, name))
|
||||
.expect("a registered asset");
|
||||
Ok(json_figures([(
|
||||
"tag".to_string(),
|
||||
a.tag.clone().unwrap_or_else(|| "none".to_string()),
|
||||
)]))
|
||||
}
|
||||
|
||||
pub(crate) fn answer_asset_basis(&self, q: &Query) -> Result<Value, Refusal> {
|
||||
let name = q.asset.as_deref().ok_or_else(|| self.missing("asset"))?;
|
||||
let a = self
|
||||
@@ -443,6 +456,25 @@ pub(crate) fn check_register_totals(b: &Books<'_>, x: &Expect) {
|
||||
named(ex, x, &what, &figures);
|
||||
}
|
||||
|
||||
/// Check one `asset_tag` expectation: the tag the asset carries now, or
|
||||
/// `"none"` (BS-asset-3); every value listed.
|
||||
pub(crate) fn check_asset_tag(b: &Books<'_>, x: &Expect) {
|
||||
let ex = b.ex;
|
||||
undated(ex, x);
|
||||
let name = x
|
||||
.asset
|
||||
.as_deref()
|
||||
.unwrap_or_else(|| panic!("{}: asset_tag names its asset", ex.id));
|
||||
let what = format!("{} asset_tag of {name}", ex.id);
|
||||
let a = b
|
||||
.l()
|
||||
.get_asset(b.asset(name, &what))
|
||||
.expect("a registered asset");
|
||||
exactly(ex, x, &BTreeSet::from(["tag".to_string()]));
|
||||
let got = a.tag.clone().unwrap_or_else(|| "none".to_string());
|
||||
assert_eq!(got, x.figures(&ex.id)["tag"], "{what}: tag");
|
||||
}
|
||||
|
||||
/// Check one `asset_basis` expectation: the asset's basis facts and the
|
||||
/// tax figures they give (BS-asset-4): `rule`,
|
||||
/// `contributor_adjusted_basis`, `fmv_at_contribution`, `tax_basis_723`,
|
||||
|
||||
@@ -104,6 +104,7 @@ impl Books<'_> {
|
||||
"register_row" => self.answer_register_row(q),
|
||||
"register_totals" => self.answer_register_totals(q),
|
||||
"asset_basis" => self.answer_asset_basis(q),
|
||||
"asset_tag" => self.answer_asset_tag(q),
|
||||
"period" => {
|
||||
let (from, to) = self.q_period(q)?;
|
||||
Ok(json_figures([
|
||||
|
||||
@@ -43,6 +43,10 @@ impl Books<'_> {
|
||||
format!("{name}.contributions_cash"),
|
||||
Value::String(figure(row.contributions_cash)),
|
||||
);
|
||||
m.insert(
|
||||
format!("{name}.contributions_property_note"),
|
||||
Value::String(property_note(&row.contributions_property).to_string()),
|
||||
);
|
||||
for (line, tax) in [
|
||||
("beginning", &row.beginning),
|
||||
("contributions_property", &row.contributions_property),
|
||||
@@ -173,6 +177,10 @@ pub(crate) fn check_k1_tax_basis(b: &Books<'_>, x: &Expect) {
|
||||
format!("{m}.contributions_cash"),
|
||||
figure(row.contributions_cash),
|
||||
);
|
||||
figures.insert(
|
||||
format!("{m}.contributions_property_note"),
|
||||
property_note(&row.contributions_property).to_string(),
|
||||
);
|
||||
for (line, tax) in [
|
||||
("beginning", &row.beginning),
|
||||
("contributions_property", &row.contributions_property),
|
||||
@@ -191,6 +199,23 @@ pub(crate) fn check_k1_tax_basis(b: &Books<'_>, x: &Expect) {
|
||||
named(ex, x, &what, &figures);
|
||||
}
|
||||
|
||||
/// The note a property line carries (BS-partner-17): `prepaid_at_book` when
|
||||
/// property contributed to a prepaid account with no fixed asset behind it
|
||||
/// was taken at its book amount for the preparer to confirm, `none` when the
|
||||
/// line carries no note.
|
||||
fn property_note(line: &ledger_core::tax_capital::TaxLine) -> &'static str {
|
||||
use ledger_core::tax_capital::Note;
|
||||
if line
|
||||
.notes
|
||||
.iter()
|
||||
.any(|n| matches!(n, Note::PrepaidAtBook { .. }))
|
||||
{
|
||||
"prepaid_at_book"
|
||||
} else {
|
||||
"none"
|
||||
}
|
||||
}
|
||||
|
||||
/// The causes `k1_reconciliation` reports, each member's every one.
|
||||
pub(crate) const RECONCILING_CAUSES: [&str; 5] = [
|
||||
"beginning",
|
||||
|
||||
Reference in new issue
Block a user