Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/docs/assets-and-losses.md
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 19 minutes ago History
assets-and-losses.md · 16.8 KB · 304 lines

Fixed Assets And Losses

packages/app-assets keeps a register of what the business owns and uses for more than a year, books its depreciation every month, records how each asset left the business and what that cost, and keeps one record for any loss — of stock, of equipment, of cash — with the evidence and an approval by somebody other than the person who reported it. packages/app-catalog adds the stock half: evaporation and shrinkage as loss reasons, and a count that says when a shortage is more than a product normally loses.

None of this is tax advice. The books carry book depreciation. Tax depreciation (MACRS tables, Section 179, bonus depreciation, tax conventions) is not computed here: the tax columns are data you fill in from your accountant's figures. Ask your accountant.

What it is

CollectionOne row isWho writes it
fixed_assetsan asset: cost basis, placed-in-service date, location, custodian, book method/life/salvage, tax method/life/salvagethe owner, through the record API or the form at /assets
asset_workmoney spent on an asset after it went into service, the decision (improvement or repair), the rule of thumb and a reasonthe owner
asset_disposalshow an asset left: sale, scrap, theft, casualty; proceeds, insurance, evidence. The gain or loss is computed and stamped by the books passthe owner records; the pass stamps
asset_tax_entriesa tax-year figure for one asset, typed from the accountantthe owner; never booked
loss_eventsany loss: what, when, how discovered, evidence, estimated and final amount, insurance claim and recovery, who reported, who approvedanybody records their own; a manager approves
ObjectDoes
system_asset_booksthe daily pass (06:35): books the whole register. Also a HANDLES reaction to register writes where the change dispatcher is on. POST = EVENT
action_asset_books`POST {asset_id? \
site_asset_schedule/assets/{id}: the register entry, the book schedule month by month beside what is on the books, the work, the disposal, the tax column
check_assetslocked checks: an asset is disposed only by a posted disposal; work and disposals fit the asset's dates and state; the rule of thumb agrees with the treatment
hook_loss_eventsstamps reported_by, approved_by, approved_at from the signed-in user, refuses the reporter's own approval; its locked check refuses an approved row whose approver is blank or is the reporter, for every writer

Pages: /assets, /assets/{id} (schedule), /assets/{id}/edit, /asset-work, /asset-disposals, /losses, /losses/{id}. The home page counts Losses to approve (attention.losses_to_approve), per viewer.

Setting up the books

Every journal is composed through object_finance.compose_posted_journal, in the asset's owner's books. Accounts come from the record first and from app_settings second. A missing account books nothing for that step and the pass says which key it needs (waiting[].needs); it never guesses.

SettingSideRecord override
assets.journal.cost_accountDR on capitalization and improvements, CR on disposalfixed_assets.asset_account_id
assets.journal.accumulated_accountCR monthly (a contra-asset), DR on disposalfixed_assets.accumulated_account_id
assets.journal.depreciation_accountDR monthly (expense)fixed_assets.expense_account_id
assets.journal.funding_accountCR on capitalization, improvements, repairs (cash, a card, a loan, payables)fixed_assets.funding_account_id, asset_work.paid_from_account_id
assets.journal.repair_accountDR for a repairasset_work.expense_account_id
assets.journal.proceeds_accountDR for sale proceedsasset_disposals.proceeds_account_id
assets.journal.insurance_receivable_accountDR for an insurance recoveryasset_disposals.insurance_account_id
assets.journal.gain_accountCR for a gain on disposal (income)
assets.journal.loss_account, assets.journal.<kind>_loss_accountDR for a loss on disposal (theft_loss_account, casualty_loss_account, ...)
losses.journal.loss_account, losses.journal.<kind>_accountDR for a loss event's own write-offloss_events.loss_account_id
losses.journal.recovery_accountCR for an insurance recovery booked from a loss event
inventory.journal.evaporation_account, inventory.journal.shrinkage_accountDR for those stock losses (falls back to the shrinkage account)

capitalization: booked_elsewhere on an asset (and booking: booked_elsewhere on work) says the purchase is already in the books — a bill paid straight to the asset account — so only depreciation is booked.

Depreciation

The schedule is derived, never stored (object_assets.book_schedule); the journals are what is stored.

  • Full-month convention. An asset depreciates for the whole month it is

placed in service and not at all for the month it is disposed of. A 60-month life is 60 journals.

  • Straight line spreads cost minus salvage over the life in whole cents:

month k books floor(base·k/life) − floor(base·(k−1)/life). 1,000 cents over 3 months is 333, 333, 334, and the last month lands exactly on salvage.

  • Declining balance books round(NBV × rate / life) a month (rate in

basis points: 20000 is double declining), switches to straight line over the remaining months when that is larger, and never goes below salvage. 10,000 over 4 months to a salvage of 1,000 at 200%: 5,000, 2,500, 1,250, 250.

  • none never depreciates (land).
  • One journal per asset-month, dated the last day of the month, marker

fixed_assets/{id}/depreciation/{YYYY-MM}: DR depreciation expense / CR accumulated depreciation. A month is booked on the first pass after it ends; as_of after today is refused.

  • Catch-up, not restatement. Each month books the schedule's running

total minus what the books already hold for the asset. An improvement recorded late, dated in a month already booked, is caught up in the next unbooked month; a depreciation journal reversed by hand is caught up the same way. Nothing posted is edited.

  • Closed periods. A month inside a closed period books on the first open

day, with occurred_on keeping the month end and period_review: pending (the "journals booked after their period closed" count).

  • Replays post nothing. fin_journals.generated_from is unique, inside

the write lock: the daily pass, the action, a reaction and a second click find the marker and stop.

Once an asset is in_service, its cost, dates, book terms and accounts are frozen (locked_when): they are what the posted journals were computed from. Location, custodian, tax columns and notes still change. A change of estimate (a new life, a new salvage) is a decision for your accountant, and is not modelled.

Improvements and repairs

Money spent on an asset after it went into service is one of two things, and the row records which and why: treatment, basis (the rule of thumb) and a one-sentence reason.

  • Improvement — capitalized: DR asset cost / CR paid-from, on its own

date, then depreciated from that month over life_months (blank: the asset's remaining book life, at least one month). The rules of thumb:

  • betterment — it makes the asset better than it was: more capacity,
more output, a material defect fixed that existed when it was bought;
  • restoration — it rebuilds or replaces a major part (an engine, a
roof), or returns a worn-out asset to like-new after its life ended;
  • adaptation — it puts the asset to a new or different use.
  • Repair — expensed now: DR repairs / CR paid-from. The rules of thumb:
  • routine maintenance — it keeps the asset in its ordinary operating
condition (a service, a paint job over worn panels, new tyres);
  • de minimis — the safe-harbor election to expense small purchases
under a per-item ceiling. The ceiling and the election are your
accountant's; nothing here enforces a number.
  • other — say why in the reason.

The check refuses an improvement resting on routine maintenance or de minimis, and a repair resting on a betterment, restoration or adaptation: a decision that contradicts its own reason. Work is refused before the asset went into service (that money is part of its cost), after its disposal, and in the future. A booked row is frozen except notes and evidence. These are rules of thumb, not tax advice.

Disposals

Record the facts on an asset_disposals row — date, kind, proceeds, insurance recovery, evidence (required_when for sale, theft, casualty) — and the books pass does the arithmetic once every month before the disposal is booked:

cost basis          = cost + booked improvements
accumulated         = depreciation on the books (through the month before)
net book value      = cost basis − accumulated
gain (loss)         = proceeds + insurance recovery − net book value

DR accumulated depreciation   accumulated
DR proceeds                   proceeds              (when > 0)
DR insurance receivable       insurance recovery    (when > 0)
DR loss on disposal           −gain                 (when a loss)
    CR asset cost                     cost basis
    CR gain on disposal               gain          (when a gain)

Worked: a press bought for 12,000.00 in January 2024, 48 months, no salvage (250.00 a month), sold 2025-07-15 for 7,000.00. January 2024 to June 2025 is 18 months, 4,500.00. NBV 7,500.00. Loss 500.00. The four numbers are stamped on the disposal (read-only), the journal is asset_disposals/{id}, and the asset becomes disposed, frozen whole.

A theft or a casualty waits until loss_event_id names an approved loss event: somebody other than the reporter has seen the evidence. One disposal per asset; partial disposals are not modelled.

Loss events

One record for any loss: kind (theft, damage, casualty, spoilage, evaporation, shrinkage, other), subject (inventory, equipment, other), what, when, how it was discovered, evidence (references, or files attached to the record), estimated and final amount, insurance claim and recovery.

  • Reported by one person, approved by another. reported_by,

approved_by and approved_at are stamped, never typed. The reporter's approval is a 403 at the hook and a refused write at the locked check for every writer (an import, a script, a storage-level object). Approving needs evidence_refs and final_amount_cents (required_when).

  • Approved is frozen, except the insurance claim's progress and notes.

Once insurance_status is paid, the recovery is frozen too.

  • What books what. The event is the evidence and the approval the numbers

trace back to; it books only what nothing else does:

  • inventory: the stock move (stock_move_id) books it — system_stock_books
or the count;
  • equipment: the asset disposal (whose loss_event_id points here);
  • anything else (a cash float): on approval, DR loss / CR
`write_off_account_id` for the final amount, marker `loss_events/{id}`;
  • an insurance recovery, once paid: DR insurance receivable / CR the
recovery account, marker `loss_events/{id}/recovery` — unless the
disposal's journal already carried it. A cheque is never counted twice.
  • Delete is refused (an owner_fallback deny): a mistaken report is

rejected, not removed.

Stock: litres, kilos, evaporation and shrinkage

Stock quantities were already decimal: stock_moves.quantity is a number folded with Decimal (object_stock), and products.unit names what one of it is. tests/test_stock_losses_and_decimals.py holds the claims to account: 100 L at 10.00 and 50.5 L at 13.00 average 11.01 a litre (165,650 / 150.5); a sale of 10.25 L is stamped at 11.01; 140.25 L remain; a count of 137.1 L is a 3.15 L shortage booked at 34.65.

  • stock_moves.reason gains evaporation and shrinkage: loss moves,

leaving a real location with no destination, each routable to its own account.

  • action_apply_count takes an optional reason (evaporation,

shrinkage) for a shortage; an overage cannot be a loss.

  • products.expected_loss_bps is the shortage a count normally finds, in

basis points of the book quantity. A shortage strictly above it comes back as expected_loss.above_expected and, where app-assets is installed, opens a reported loss event linked to the move, so it is counted until somebody else looks at it. Within the expectation nothing is opened.

Recipes

Each is a request to the record API or an object, as the signed-in owner (dan) unless it says otherwise; mgr has the manager role. To try them on a scratch box, use scripts.try_package.Sandbox from Python the way tests/test_assets_and_losses.py does: its Books helper creates a chart of accounts as dan and writes each setting above as admin (POST /collections/app_settings/records {"key": ..., "value": <account id>}), which is the setup every recipe below assumes.

Register an asset and book it.

POST /collections/fixed_assets/records
{"owner_id": "dan", "name": "Delivery van", "cost_cents": 3600000,
 "placed_in_service_on": "2025-01-10", "status": "in_service",
 "book_life_months": 60, "book_salvage_cents": 600000}

POST /objects/action_asset_books
{"asset_id": "<id>", "as_of": "2025-12-31"}

The answer lists each journal it posted (posted[].marker) and anything waiting with the reason. Run it again: posted: 0. The schedule is at /assets/<id>.

Record a repair and an improvement.

POST /collections/asset_work/records
{"owner_id": "dan", "asset_id": "<van>", "performed_on": "2025-04-12",
 "amount_cents": 180000, "description": "Paint job", "treatment": "repair",
 "basis": "routine_maintenance", "reason": "Repaints worn panels: ordinary condition"}

POST /collections/asset_work/records
{"owner_id": "dan", "asset_id": "<van>", "performed_on": "2025-08-20",
 "amount_cents": 720000, "description": "Engine rebuild", "treatment": "improvement",
 "basis": "restoration", "life_months": 36,
 "reason": "Rebuilt engine extends the van's life by three years"}

Report a theft and have it approved, then dispose of the asset.

POST /collections/loss_events/records            (as dan)
{"owner_id": "dan", "occurred_on": "2025-09-14", "kind": "theft",
 "subject": "equipment", "asset_id": "<laptop>", "what": "Laptop taken from the van",
 "how_discovered": "Van found unlocked", "evidence_refs": "police report 25-11873"}

PUT /collections/loss_events/records/<event>     (as mgr; dan gets 403)
{"status": "approved", "final_amount_cents": 170000}

POST /collections/asset_disposals/records        (as dan)
{"owner_id": "dan", "asset_id": "<laptop>", "disposed_on": "2025-09-14",
 "kind": "theft", "evidence_refs": "police report 25-11873", "loss_event_id": "<event>"}

Count a cask and record the evaporation.

POST /objects/action_apply_count
{"product_id": "<cask>", "location_id": "<store>", "counted_qty": "194.2",
 "counted_on": "2025-12-15", "reason": "evaporation"}

expected_loss.above_expected is true when the shortage is above the product's expected_loss_bps, and expected_loss.loss_event.id is the reported loss event waiting for approval.

A year, checked

tests/test_assets_and_losses.py::test_a_year_balances_and_every_number_traces_to_evidence_and_approval books 2025 for a small food business — opening capital, a van with a paint job (repair) and an engine rebuild (improvement), a stolen laptop, a freezer lost to a burst pipe with an insurance recovery, a spoiled batch of cheese, evaporation from a whisky cask found at a count — then checks the trial balance account by account against figures worked by hand, that it balances, that the balance sheet balances, that a replay posts nothing, and that every posted journal traces to a record: an asset, a piece of work with its reason and evidence, a disposal or stock move whose loss event is approved, with evidence, by somebody other than its reporter, or a hand entry with its reference.

What it does not do

Decisions left to the owner and the accountant, deliberately:

  • tax depreciation methods, conventions, Section 179 and bonus depreciation;
  • a change of estimate on an asset in service (new life, new salvage);
  • partial disposals, trade-ins, like-kind exchanges, impairment;
  • whether one person may both report and approve in a one-person business

(here they may not; a second signed-in person with the manager role is needed);

  • the de minimis ceiling and the capitalization threshold;
  • the insurer's cheque reaching the bank (DR cash / CR insurance receivable)

is the bank reconciliation's entry, not this package's.