Fixed assets, fully featured: tags, serials, acquisition links, label sheets, the fixed asset register, and an Assets section in the viewer; fix a flaky verify
- core: asset tags (generated PREFIX-0001 or the human's own; unique ignoring case; never reused by another asset) and serial numbers (rules.md B-24); a journaled link from an asset to the entry that acquired it (posted, unreversed, debiting the cost account); fixed_asset_register(as_of), reconciled to the GL (unposted depreciation, unregistered cost) - store: asset.tagged, asset.serial_set, asset.acquisition_linked journaled, replayed, projected (schema v9); differs_from now also compares control roles and tag history - config: [books] asset_tag_prefix, default the company's initials without legal-form words - import: Avery 5160/8160 label sheets with QR codes (geometry vendored from Avery, docs/spec/sources/avery-5160.md); the register as XLSX and PDF - mcp: register_asset tags (and links) automatically; books.label_asset, books.asset_labels; asset tools take a tag; books.show asset / assets page / register report; export fixed_asset_register (json, csv, xlsx, pdf) and in the CPA package - viewer: Assets page (register, reconciliation), asset page (identity, schedule posted vs not, entries, documents), Fixed asset register report, global search by tag/serial/description, journal text, needs-attention items - fix: verify compared snapshot amounts as strings; a zero total summed in hash-map order could print "0" or "0.00", so agreeing books failed verify at random. Now by value (regression test) - tests: spec-blind suites for tags, register, prefix, store, MCP; label and register PDF/XLSX tests; viewer tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GWVo7x3UHw5kwCUaWxiejX
This commit is contained in:
1 parent
4e96b5f54d
commit
cd085108c1
53 files changed
+7872
-104
No files matched your search
@@ -108,6 +108,58 @@ pub struct BooksSettings {
|
||||
/// statement treats as investing (loans the company makes, investments
|
||||
/// it buys: ASC 230-10-20). Registered fixed assets need not be listed.
|
||||
pub investing_accounts: Vec<String>,
|
||||
/// `[books] asset_tag_prefix`: the prefix of generated asset tags
|
||||
/// ("FL" for "FL-0001"). Unset: [`BooksSettings::asset_tag_prefix`]
|
||||
/// derives it from the company name.
|
||||
pub asset_tag_prefix: Option<String>,
|
||||
}
|
||||
|
||||
impl BooksSettings {
|
||||
/// The prefix generated asset tags use: `[books] asset_tag_prefix`, or
|
||||
/// else the initials of the company name's words, legal-form words
|
||||
/// (LLC, Inc, Corp, ...) left out, at most 8 ("Fernhill Labs LLC" →
|
||||
/// "FL"); "FA" (fixed asset) when the name gives none.
|
||||
pub fn asset_tag_prefix(&self) -> String {
|
||||
if let Some(p) = &self.asset_tag_prefix {
|
||||
return p.clone();
|
||||
}
|
||||
const FORMS: &[&str] = &[
|
||||
"llc",
|
||||
"l",
|
||||
"c",
|
||||
"inc",
|
||||
"incorporated",
|
||||
"corp",
|
||||
"corporation",
|
||||
"co",
|
||||
"company",
|
||||
"ltd",
|
||||
"limited",
|
||||
"llp",
|
||||
"lp",
|
||||
"pllc",
|
||||
"pc",
|
||||
"pa",
|
||||
"the",
|
||||
"and",
|
||||
"of",
|
||||
];
|
||||
let initials: String = self
|
||||
.company
|
||||
.name
|
||||
.split(|c: char| !c.is_ascii_alphanumeric())
|
||||
.filter(|w| !w.is_empty() && !FORMS.contains(&w.to_ascii_lowercase().as_str()))
|
||||
.filter_map(|w| w.chars().next())
|
||||
.filter(char::is_ascii_alphabetic)
|
||||
.map(|c| c.to_ascii_uppercase())
|
||||
.take(8)
|
||||
.collect();
|
||||
if initials.is_empty() || self.company.name == Company::default().name {
|
||||
"FA".to_string()
|
||||
} else {
|
||||
initials
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -149,6 +201,7 @@ struct BooksSection {
|
||||
financing_accounts: Vec<String>,
|
||||
#[serde(default)]
|
||||
investing_accounts: Vec<String>,
|
||||
asset_tag_prefix: Option<String>,
|
||||
}
|
||||
|
||||
/// The return a federal tax classification files (docs/spec/sources/
|
||||
@@ -444,6 +497,21 @@ pub fn parse(text: &str) -> Result<BooksSettings, String> {
|
||||
cash_accounts: codes("cash_accounts", raw.books.cash_accounts)?,
|
||||
financing_accounts: codes("financing_accounts", raw.books.financing_accounts)?,
|
||||
investing_accounts: codes("investing_accounts", raw.books.investing_accounts)?,
|
||||
asset_tag_prefix: match raw.books.asset_tag_prefix {
|
||||
Some(p)
|
||||
if !p.is_empty()
|
||||
&& p.len() <= 8
|
||||
&& p.chars().all(|c| c.is_ascii_alphanumeric()) =>
|
||||
{
|
||||
Some(p)
|
||||
}
|
||||
Some(p) => {
|
||||
return Err(format!(
|
||||
"[books] asset_tag_prefix {p:?}: 1 to 8 letters or digits"
|
||||
));
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1125,3 +1125,104 @@ fn inv7_profile_keeps_simple_values_of_every_type() {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------- [books] asset_tag_prefix
|
||||
//
|
||||
// Spec: `BooksSettings::asset_tag_prefix` doc ("`[books] asset_tag_prefix`,
|
||||
// or else the initials of the company name's words, legal-form words (LLC,
|
||||
// Inc, Corp, ...) left out, at most 8 ("Fernhill Labs LLC" → "FL"); "FA"
|
||||
// (fixed asset) when the name gives none"), docs/mcp-interface.md
|
||||
// (books.register_asset), and the parse refusal "1 to 8 letters or digits".
|
||||
|
||||
fn prefix_for_name(name: &str) -> String {
|
||||
ok(&company_kv("name", name)).asset_tag_prefix()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asset_tag_prefix_explicit_setting_wins() {
|
||||
let s = ok("[company]\nname = \"Fernhill Labs LLC\"\n[books]\nasset_tag_prefix = \"LAB\"\n");
|
||||
assert_eq!(s.asset_tag_prefix.as_deref(), Some("LAB"));
|
||||
assert_eq!(s.asset_tag_prefix(), "LAB");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asset_tag_prefix_accepts_one_to_eight_letters_or_digits() {
|
||||
for p in ["A", "7", "FL", "WL2026", "ABCDEFGH", "12345678"] {
|
||||
let s = ok(&books_kv("asset_tag_prefix", p));
|
||||
assert_eq!(s.asset_tag_prefix(), p, "{p:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asset_tag_prefix_refuses_other_forms() {
|
||||
for p in [
|
||||
"",
|
||||
"ABCDEFGHI",
|
||||
"FL-",
|
||||
"W L",
|
||||
"W_L",
|
||||
"FL.",
|
||||
"ÉL",
|
||||
" FL",
|
||||
"FL/1",
|
||||
] {
|
||||
refused(&books_kv("asset_tag_prefix", p));
|
||||
}
|
||||
// Not a string.
|
||||
refused("[books]\nasset_tag_prefix = 12\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asset_tag_prefix_unset_is_none() {
|
||||
assert_eq!(ok("").asset_tag_prefix, None);
|
||||
assert_eq!(ok("[books]\n").asset_tag_prefix, None);
|
||||
}
|
||||
|
||||
/// The doc's example.
|
||||
#[test]
|
||||
fn asset_tag_prefix_default_is_company_initials_without_legal_form() {
|
||||
assert_eq!(prefix_for_name("Fernhill Labs LLC"), "FL");
|
||||
assert_eq!(prefix_for_name("Acme Inc"), "A");
|
||||
assert_eq!(prefix_for_name("Acme Widgets Corp"), "AW");
|
||||
assert_eq!(prefix_for_name("Blue Sky Ventures"), "BSV");
|
||||
}
|
||||
|
||||
/// Initials are uppercase.
|
||||
#[test]
|
||||
fn asset_tag_prefix_default_is_uppercase() {
|
||||
assert_eq!(prefix_for_name("fernhill labs LLC"), "FL");
|
||||
}
|
||||
|
||||
/// At most 8 initials.
|
||||
#[test]
|
||||
fn asset_tag_prefix_default_takes_at_most_eight_initials() {
|
||||
assert_eq!(
|
||||
prefix_for_name("Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet"),
|
||||
"ABCDEFGH"
|
||||
);
|
||||
}
|
||||
|
||||
/// "FA" when the name gives none: only legal-form words, or the default
|
||||
/// (unnamed) company.
|
||||
#[test]
|
||||
fn asset_tag_prefix_default_falls_back_to_fa() {
|
||||
assert_eq!(ok("").asset_tag_prefix(), "FA");
|
||||
assert_eq!(prefix_for_name("Unnamed company"), "FA");
|
||||
assert_eq!(prefix_for_name("LLC"), "FA");
|
||||
assert_eq!(prefix_for_name("Inc"), "FA");
|
||||
}
|
||||
|
||||
proptest! {
|
||||
/// Whatever the name, the default is a prefix the setting itself would
|
||||
/// accept: 1 to 8 ASCII letters or digits, uppercase.
|
||||
#[test]
|
||||
fn prop_default_asset_tag_prefix_is_a_valid_setting(name in "[ -~]{1,60}") {
|
||||
let Ok(s) = parse(&company_kv("name", &name)) else { return Ok(()); };
|
||||
let p = s.asset_tag_prefix();
|
||||
prop_assert!((1..=8).contains(&p.len()), "{:?} -> {:?}", name, p);
|
||||
prop_assert!(p.chars().all(|c| c.is_ascii_alphanumeric()), "{:?} -> {:?}", name, p);
|
||||
prop_assert_eq!(p.to_ascii_uppercase(), p.clone());
|
||||
let back = ok(&books_kv("asset_tag_prefix", &p));
|
||||
prop_assert_eq!(back.asset_tag_prefix(), p);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user