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
File diff suppressed because it is too large.
Load diff
@@ -194,10 +194,18 @@ fn assets(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
|
||||
return;
|
||||
}
|
||||
let mut go = None;
|
||||
widgets::titled_card(
|
||||
let (register, _) = widgets::titled_card(
|
||||
ui,
|
||||
"Fixed assets",
|
||||
|_| {},
|
||||
|ui| {
|
||||
widgets::link(
|
||||
ui,
|
||||
RichText::new(format!("Asset register {}", icon::ARROW_RIGHT))
|
||||
.font(theme::regular(12.5))
|
||||
.color(p.accent),
|
||||
)
|
||||
.clicked()
|
||||
},
|
||||
|ui| {
|
||||
for a in &assets {
|
||||
// What has actually been posted, so this ties to the balance
|
||||
@@ -228,11 +236,11 @@ fn assets(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if widgets::link(
|
||||
ui,
|
||||
RichText::new(&a.description).font(theme::semibold(13.5)),
|
||||
RichText::new(b.asset_label(a.id)).font(theme::semibold(13.5)),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
go = Some(a.cost_account);
|
||||
go = Some(a.id);
|
||||
}
|
||||
ui.label(
|
||||
RichText::new(format!(
|
||||
@@ -271,7 +279,10 @@ fn assets(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
|
||||
},
|
||||
);
|
||||
if let Some(id) = go {
|
||||
shell.go(Route::Account(id));
|
||||
shell.go(Route::Asset(id));
|
||||
}
|
||||
if register {
|
||||
shell.go(Route::Assets);
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,19 @@ pub fn detail(ui: &mut Ui, b: &Books, e: &EntryInfo, shell: &mut Shell<'_>) {
|
||||
shell.go(Route::Entry(r));
|
||||
}
|
||||
}
|
||||
if let Some(&asset) = b.entry_assets.get(&e.id) {
|
||||
ui.add_space(4.0);
|
||||
if widgets::link(
|
||||
ui,
|
||||
RichText::new(format!("{} {}", icon::PACKAGE, b.asset_label(asset)))
|
||||
.color(p.accent),
|
||||
)
|
||||
.on_hover_text("Open this fixed asset")
|
||||
.clicked()
|
||||
{
|
||||
shell.go(Route::Asset(asset));
|
||||
}
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
|
||||
// Facts.
|
||||
|
||||
@@ -23,6 +23,8 @@ pub struct Event {
|
||||
pub icon: &'static str,
|
||||
pub text: String,
|
||||
pub route: Option<Route>,
|
||||
/// A second place it's about (the asset of a depreciation entry).
|
||||
pub also: Option<Route>,
|
||||
}
|
||||
|
||||
fn s<'a>(p: &'a Value, k: &str) -> &'a str {
|
||||
@@ -58,7 +60,32 @@ pub fn describe(b: &Books, line: &JournalLine) -> Option<Event> {
|
||||
let id = p.get("id").and_then(|v| v.as_u64()).unwrap_or(0);
|
||||
let entry_id = p.get("entry_id").and_then(|v| v.as_u64());
|
||||
let att = p.get("attachment_id").and_then(|v| v.as_u64()).unwrap_or(0);
|
||||
let ev = |icon, text: String, route: Option<Route>| Some(Event { icon, text, route });
|
||||
let ev = |icon, text: String, route: Option<Route>| {
|
||||
Some(Event {
|
||||
icon,
|
||||
text,
|
||||
route,
|
||||
also: None,
|
||||
})
|
||||
};
|
||||
let asset_id = p.get("asset_id").and_then(|v| v.as_u64());
|
||||
let asset = |id: Option<u64>| {
|
||||
id.map(|a| {
|
||||
b.ledger
|
||||
.get_asset(a)
|
||||
.map(|x| x.description.clone())
|
||||
.unwrap_or_else(|| format!("asset {a}"))
|
||||
})
|
||||
.unwrap_or_default()
|
||||
};
|
||||
let with_asset = |icon, text: String| {
|
||||
Some(Event {
|
||||
icon,
|
||||
text,
|
||||
route: entry_id.map(Route::Entry),
|
||||
also: asset_id.map(Route::Asset),
|
||||
})
|
||||
};
|
||||
match line.line_type.as_str() {
|
||||
"entry.created" | "entry.line_added" | "entry.line_class_set" => None,
|
||||
"store.created" => ev(icon::BOOK_OPEN, "Books created".into(), None),
|
||||
@@ -223,17 +250,45 @@ pub fn describe(b: &Books, line: &JournalLine) -> Option<Event> {
|
||||
"asset.registered" => ev(
|
||||
icon::PACKAGE,
|
||||
format!("Registered asset {}", s(p, "description")),
|
||||
Some(Route::Company),
|
||||
Some(Route::Asset(id)),
|
||||
),
|
||||
"asset.depreciation_posted" => ev(
|
||||
"asset.tagged" => {
|
||||
let tag = s(p, "tag");
|
||||
let text = match p.get("previous_tag").and_then(|v| v.as_str()) {
|
||||
Some(old) => format!("Retagged {} from {old} to {tag}", asset(asset_id)),
|
||||
None => format!("Tagged {} {tag}", asset(asset_id)),
|
||||
};
|
||||
ev(icon::TAG, text, asset_id.map(Route::Asset))
|
||||
}
|
||||
"asset.serial_set" => {
|
||||
let text = match p.get("serial").and_then(|v| v.as_str()) {
|
||||
Some(serial) => format!("Serial number of {} set to {serial}", asset(asset_id)),
|
||||
None => format!("Serial number of {} cleared", asset(asset_id)),
|
||||
};
|
||||
ev(icon::BARCODE, text, asset_id.map(Route::Asset))
|
||||
}
|
||||
"asset.depreciation_posted" => with_asset(
|
||||
icon::TREND_DOWN,
|
||||
"Depreciation posted".into(),
|
||||
entry_id.map(Route::Entry),
|
||||
format!(
|
||||
"Depreciation posted: {} {} ({})",
|
||||
asset(asset_id),
|
||||
s(p, "period"),
|
||||
amount(p)
|
||||
),
|
||||
),
|
||||
"asset.disposed" => ev(
|
||||
"asset.disposed" => with_asset(
|
||||
icon::TRASH,
|
||||
"Asset disposed".into(),
|
||||
entry_id.map(Route::Entry),
|
||||
format!(
|
||||
"Disposed {} on {} for {}",
|
||||
asset(asset_id),
|
||||
s(p, "date"),
|
||||
p.get("proceeds")
|
||||
.and_then(|v| v.get("amount"))
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|a| a.parse().ok())
|
||||
.map(fmt::dollars)
|
||||
.unwrap_or_default()
|
||||
),
|
||||
),
|
||||
"schedule.registered" => ev(
|
||||
icon::CALENDAR,
|
||||
@@ -310,6 +365,7 @@ pub fn describe_any(b: &Books, line: &JournalLine) -> Event {
|
||||
icon: icon::PENCIL_SIMPLE,
|
||||
text: format!("Drafted #{id} {}", s(p, "description")),
|
||||
route: Some(Route::Entry(id)),
|
||||
also: None,
|
||||
},
|
||||
"entry.line_added" => {
|
||||
let amount = p
|
||||
@@ -332,6 +388,7 @@ pub fn describe_any(b: &Books, line: &JournalLine) -> Event {
|
||||
),
|
||||
),
|
||||
route: Some(Route::Entry(id)),
|
||||
also: None,
|
||||
}
|
||||
}
|
||||
"entry.line_class_set" => {
|
||||
@@ -350,12 +407,14 @@ pub fn describe_any(b: &Books, line: &JournalLine) -> Event {
|
||||
.map_or(0, |i| i + 1)
|
||||
),
|
||||
route: Some(Route::Entry(id)),
|
||||
also: None,
|
||||
}
|
||||
}
|
||||
t => Event {
|
||||
icon: icon::DOT,
|
||||
text: t.to_string(),
|
||||
route: None,
|
||||
also: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -510,7 +569,7 @@ fn detail(ui: &mut Ui, b: &Books, line: &JournalLine, shell: &mut Shell<'_>) {
|
||||
fact(ui, "Previous", &line.prev);
|
||||
let own = ledger_store::journal::sha256_hex(line.to_canonical().as_bytes());
|
||||
fact(ui, "This hash", &own);
|
||||
if let Some(r) = &ev.route {
|
||||
for r in ev.route.iter().chain(&ev.also) {
|
||||
ui.add_space(6.0);
|
||||
if ui
|
||||
.button(format!(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! One module per screen.
|
||||
|
||||
pub mod accounts;
|
||||
pub mod assets;
|
||||
pub mod cash;
|
||||
pub mod company;
|
||||
pub mod documents;
|
||||
@@ -52,6 +53,8 @@ pub fn show(ui: &mut Ui, b: &Books, route: &Route, shell: &mut Shell<'_>) {
|
||||
Route::Reports(kind) => reports::show(ui, b, *kind, shell),
|
||||
Route::Accounts => accounts::show_chart(ui, b, shell),
|
||||
Route::Account(id) => accounts::show_account(ui, b, *id, shell),
|
||||
Route::Assets => assets::show_register(ui, b, shell),
|
||||
Route::Asset(id) => assets::show_asset(ui, b, *id, shell),
|
||||
Route::Documents => documents::show(ui, b, None, shell),
|
||||
Route::Document(id) => documents::show(ui, b, Some(*id), shell),
|
||||
Route::Company => company::show(ui, b, shell),
|
||||
|
||||
@@ -943,6 +943,119 @@ fn aging(rows: Vec<ledger_core::AgingRow>, as_of: NaiveDate) -> Table {
|
||||
t
|
||||
}
|
||||
|
||||
/// The fixed asset register on `as_of`: ledger-core's
|
||||
/// `fixed_asset_register`, laid out, with its reconciliation to the
|
||||
/// general ledger and what that says (the Assets page's notices).
|
||||
fn asset_register(b: &Books, as_of: NaiveDate) -> Table {
|
||||
let r = b.asset_register(as_of);
|
||||
let mut t = Table::new(vec![
|
||||
"Cost".into(),
|
||||
"Accumulated".into(),
|
||||
"Book value".into(),
|
||||
]);
|
||||
if r.rows.is_empty() {
|
||||
t.note(format!(
|
||||
"No fixed asset was in service by {}.",
|
||||
fmt::date(as_of)
|
||||
));
|
||||
return t;
|
||||
}
|
||||
t.section("Assets");
|
||||
for x in &r.rows {
|
||||
let label = match &x.tag {
|
||||
Some(tag) => format!("{tag} · {}", x.description),
|
||||
None => format!("{} (no tag)", x.description),
|
||||
};
|
||||
let mut detail = Vec::new();
|
||||
if let Some(s) = &x.serial {
|
||||
detail.push(format!("serial {s}"));
|
||||
}
|
||||
detail.push(format!("in service {}", fmt::date(x.in_service)));
|
||||
detail.push(fmt::count(x.useful_life_months as usize, "month", "months"));
|
||||
if !x.salvage.is_zero() {
|
||||
detail.push(format!("salvage {}", fmt::dollars(x.salvage)));
|
||||
}
|
||||
let cells = match x.disposed {
|
||||
Some(_) => {
|
||||
detail.push(format!(
|
||||
"{}; cost {}",
|
||||
super::assets::status_text(x.disposed),
|
||||
fmt::dollars(x.cost)
|
||||
));
|
||||
vec![Cell::none(), Cell::none(), Cell::none()]
|
||||
}
|
||||
None => vec![
|
||||
Cell::of(x.cost),
|
||||
Cell::of(x.accumulated),
|
||||
Cell::of(x.book_value),
|
||||
],
|
||||
};
|
||||
t.rows.push(Row {
|
||||
kind: Kind::Line,
|
||||
label,
|
||||
detail: detail.join(" · "),
|
||||
cells,
|
||||
});
|
||||
}
|
||||
t.row(
|
||||
Kind::Grand,
|
||||
"Total held",
|
||||
vec![
|
||||
Cell::of(r.total_cost),
|
||||
Cell::of(r.total_accumulated),
|
||||
Cell::of(r.total_book_value),
|
||||
],
|
||||
);
|
||||
t.section("Reconciliation to the books");
|
||||
let start = b.kpis.first_entry.unwrap_or(as_of).min(as_of);
|
||||
let held: Vec<_> = r
|
||||
.rows
|
||||
.iter()
|
||||
.filter_map(|x| b.ledger.get_asset(x.asset_id))
|
||||
.collect();
|
||||
// One account behind a figure drills down to it.
|
||||
let only = |ids: Vec<AccountId>| -> Option<Drill> {
|
||||
let mut ids = ids;
|
||||
ids.sort_unstable();
|
||||
ids.dedup();
|
||||
(ids.len() == 1).then(|| Drill {
|
||||
account: ids[0],
|
||||
start,
|
||||
end: as_of,
|
||||
})
|
||||
};
|
||||
let cost_drill = only(held.iter().map(|a| a.cost_account).collect());
|
||||
let accum_drill = only(held.iter().map(|a| a.accum_depr_account).collect());
|
||||
t.row(
|
||||
Kind::Line,
|
||||
"In the books",
|
||||
vec![
|
||||
Cell {
|
||||
value: Some(r.ledger_cost),
|
||||
drill: cost_drill,
|
||||
},
|
||||
Cell {
|
||||
value: Some(r.ledger_accumulated),
|
||||
drill: accum_drill,
|
||||
},
|
||||
Cell::of(r.ledger_cost - r.ledger_accumulated),
|
||||
],
|
||||
);
|
||||
t.row(
|
||||
Kind::Subtotal,
|
||||
"Register less books",
|
||||
vec![
|
||||
Cell::of(-r.unregistered_cost()),
|
||||
Cell::of(r.unposted_depreciation()),
|
||||
Cell::of(-r.unregistered_cost() - r.unposted_depreciation()),
|
||||
],
|
||||
);
|
||||
for n in super::assets::notices(b, &r) {
|
||||
t.note(n.text);
|
||||
}
|
||||
t
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The page.
|
||||
|
||||
@@ -959,7 +1072,11 @@ const GROUPS: [(&str, &[ReportKind]); 3] = [
|
||||
),
|
||||
(
|
||||
"Ledgers",
|
||||
&[ReportKind::TrialBalance, ReportKind::GeneralLedger],
|
||||
&[
|
||||
ReportKind::TrialBalance,
|
||||
ReportKind::GeneralLedger,
|
||||
ReportKind::FixedAssetRegister,
|
||||
],
|
||||
),
|
||||
(
|
||||
"Tax and aging",
|
||||
@@ -1042,7 +1159,10 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke
|
||||
let p = pal(ui.ctx());
|
||||
let point_in_time = matches!(
|
||||
kind,
|
||||
ReportKind::TrialBalance | ReportKind::ArAging | ReportKind::ApAging
|
||||
ReportKind::TrialBalance
|
||||
| ReportKind::ArAging
|
||||
| ReportKind::ApAging
|
||||
| ReportKind::FixedAssetRegister
|
||||
) || (kind == ReportKind::BalanceSheet
|
||||
&& shell.state.reports.columns == Columns::Total);
|
||||
let splittable = matches!(
|
||||
@@ -1231,6 +1351,7 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke
|
||||
Some(t)
|
||||
}
|
||||
ReportKind::TrialBalance => Some(trial_balance(b, e)),
|
||||
ReportKind::FixedAssetRegister => Some(asset_register(b, e)),
|
||||
ReportKind::MembersEquity => Some(owners_equity(b, s, e)),
|
||||
ReportKind::TaxSummary => {
|
||||
let mut t = tax(b, s, e);
|
||||
@@ -1922,6 +2043,7 @@ mod tests {
|
||||
tables.push(("equity", owners_equity(&b, s, e)));
|
||||
tables.push(("tax", tax(&b, s, e)));
|
||||
tables.push(("ar", aging(b.ledger.ar_aging(e), e)));
|
||||
tables.push(("assets", asset_register(&b, e)));
|
||||
tables.push(("gl", gl_table(&general_ledger(&b.ledger, s, e).unwrap())));
|
||||
let keep = std::env::var_os("PDF_DIR").map(std::path::PathBuf::from);
|
||||
for (name, t) in tables {
|
||||
|
||||
Reference in new issue
Block a user