Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
paths: - "apps/erp/app/modules/accounting/" - "apps/erp/app/routes/x+/fixed-asset+/" - "apps/erp/app/routes/x+/depreciation-run+/**" - "apps/erp/app/routes/x+/accounting+/fleet.tsx" - "packages/database/supabase/migrations/fixed-asset" - "packages/database/supabase/migrations/fleet-bridge" - "packages/database/supabase/migrations/asset-transfer" - "packages/database/supabase/migrations/job-to-asset" - "apps/erp/app/modules/accounting/accounting.service.ts" - "apps/erp/app/modules/shared/shared.service.ts" - "apps/erp/app/modules/sales/sales.service.ts" - "apps/erp/app/modules/purchasing/purchasing.service.ts" - "packages/database/supabase/migrations/rental-agreements" - "packages/database/supabase/migrations/lease-enum" - "packages/database/supabase/migrations/lessor-schedule"
Fixed Asset Lifecycle
Fixed assets are acquired, depreciated, and disposed through the accounting
module. They integrate with purchasing (acquisition via PO receipt / purchase
invoice), sales (disposal via shipment / sales invoice), production (a job that
completes to an asset) and inventory (a serialized unit capitalized from stock
or returned to it). All GL postings flow through journal / journalLine.
journalEntrySourceType is 'Asset Depreciation' for depreciation runs,
'Asset Disposal' for the manual scrap, 'Asset Transfer' for every
inventory ↔ asset move and job → asset completion, and 'Lease' for a
sales-type lease's commencement and residual return (below) and for a lessee lease's
purchase option exercise (Acquire, path 5); the two-step sale reuses the
document source types ('Sales Shipment' / 'Sales Invoice') and manual
registration uses 'Manual'. 'Asset Transfer' is representation: "journal",
defaultEnabled: false in the accounting-sync policy
(packages/ee/src/accounting/core/models.ts), like 'Revenue Recognition'
and 'Lease'.
Schema lives in these migrations (newest wins):
20260524143826_fixed-asset-enums.sql, 20260524143827_fixed-assets.sql,
20260525084319_seed-fixed-asset-classes.sql,
20260717031529_split-asset-gain-loss-disposal-accounts.sql,
20261006220301_fleet-rental-lease-enums.sql, 20261006220401_fleet-bridge.sql,
20261006220501_rental-agreements.sql (rentals, the sales-type lease schedule and the
fleetAssets view), 20261006221601_complete-job-to-asset.sql and
20261008163615_fixed-asset-cost-adjustment.sql (the Cost Adjustment / Manual
transfer enum values). Design:
.ai/specs/implemented/2026-09-22-revenue-recognition-rentals-and-contracts.md Part I §2 and §4.
Tables (current schema)
fixedAsset— master record. Key columns:fixedAssetId(readable),fixedAssetClassId,name,serialNumber,status(fixedAssetStatus),depreciationMethod,usefulLifeMonths,residualValuePercent,acquisitionCost,acquisitionDate,depreciationStartDate,accumulatedDepreciation,accumulatedTaxDepreciation,assetLifetimeUsage(Units of Production),locationId,disposalDate,disposalMethod,saleProceeds. Tax columns:taxDepreciationMethod,taxUsefulLifeMonths,taxResidualValuePercent,macrsPropertyClass,macrsConvention,bonusDepreciationPercent. Fleet bridge (20261006220401):itemId(FKitem),trackedEntityId(FKtrackedEntity; partial unique indexfixedAsset_trackedEntity_live_idxon(companyId, trackedEntityId)whilestatus <> 'Disposed'),quantity NUMERIC NOT NULL DEFAULT 1(CHECKquantity = 1— v1 is one serialized unit per asset),workCenterId(FKworkCenter,ON DELETE SET NULL),outOfServiceSince/outOfServiceReason(CHECK: both set or both null).fixedAssetClass— classification + GL account mappings. Seven NOT NULL account FKs:assetAccountId,accumulatedDepreciationAccountId,depreciationExpenseAccountId,writeOffAccountId,writeDownAccountId,gainOnDisposalAccountId,lossOnDisposalAccountId(20260717031529renameddisposalAccountId→lossOnDisposalAccountIdand added the gain column, backfilled to the loss account where no gain account resolved).isConstructionInProgress BOOLEAN NOT NULL DEFAULT falsemarks a CIP class. Also default depreciation/tax settings. Seeded with Buildings / Machinery & Equipment / Vehicles, plus (20261006220401for existing companies,packages/database/src/seed-data.tsfor new ones) Rental Fleet (Straight Line, 60 months, 20 % residual, asset1370 Rental Fleet, accumulated1380 Accumulated Depreciation – Rental Fleet) and Construction in Progress (isConstructionInProgress = true, asset1390 Construction in Progress, accumulated 1330, 120 months, 0 %); both use 6310 / 6320 / 4140 for expense / write-off / write-down / loss / gain. The three accounts are seeded once per company group under theProperty, Plant & Equipmentgroup.fixedAssetTransfer— the inventory ↔ asset document.transferId(sequencetable = 'fixedAssetTransfer', prefixFAT, size 6),type(fixedAssetTransferType),sourceType(fixedAssetTransferSourceType),fixedAssetId,itemId,trackedEntityId,jobId,fromClassId,locationId(NOT NULL),storageUnitId,quantity,transferDate,inServiceDate,amount,accumulatedDepreciation,journalId,statusCHECKIN ('Draft','Posted'),postedAt,postedBy. Every v1 writer creates the row and posts it in the same transaction; the status column only keeps the document shape open for a reviewed Draft later.fixedAssetCipCost— append-only cost ledger of an asset under construction:sourceTypeCHECKIN ('Purchase Invoice','Receipt','Job', 'Manual'),sourceDocumentId,sourceDocumentLineId,jobId,amount,costDate,journalId. Capitalization sums these rows, not the asset'sacquisitionCost.fleetAssets(view,SECURITY_INVOKER) —fixedAssetwhereitemId IS NOT NULL, joined toitem(itemReadableId,itemName,thumbnailPath),fixedAssetClass(className,isConstructionInProgress),trackedEntity(trackedEntityReadableId) andworkCenter(workCenterName), withnetBookValueand a derivedfleetStatus: Disposed +disposalMethod 'Transfer to Inventory'→Returned to Stock; any other Disposed →Sold;Under Construction;outOfServiceSinceset →In Maintenance; elseAvailable.20261006220501_rental-agreements.sqlrecreated it with aLEFT JOIN LATERALon the newest LIVErentalAgreementLineof the asset (status IN ('Pending','On Rent'), joined to itsrentalAgreement) and exposes that line'srentalAgreementId,customerId,customerLocationId. Full precedence: Disposed + Transfer to Inventory →Returned to Stock; other Disposed →Sold;Under Construction; live lineOn Rent→On Rent;outOfServiceSinceset →In Maintenance; live linePending→Reserved; elseAvailable. So a unit on rent that is also out of service reads On Rent, and a reserved unit out of service reads In Maintenance. A Draft agreement's lines are alreadyPending(the column default), so a draft RESERVES its units; the partial unique indexrentalAgreementLine_asset_live_idxkeeps one live line per asset.job.fixedAssetClassId/job.fixedAssetId— the Make to Asset target; CHECKjob_asset_target_check(num_nonnulls(...) <= 1). Thejobsview was DROP + CREATEd (it selectsj.*).depreciationRun— period batch.depreciationRunId,periodEnd,statusCHECKIN ('Draft','Posted'),postedAt,postedBy.depreciationRunLine— one row per asset per MONTH the run covers (FAM's depreciation history record):periodEnd(the month; nullable so older backups restore — readers fall back to the run'speriodEnd),amount,taxAmount,journalId(that month's journal) anddeferredTaxJournalId(that month's deferred tax journal, migration20261006221701).fixedAssetDisposal— disposal record:disposalMethod,disposalDate,saleProceeds,netBookValueAtDisposal,gainLoss,journalId.fixedAssetUsageLog— Units of Production input:periodStart,periodEnd(unique per asset),unitsProduced.receiptFixedAssetLine/shipmentFixedAssetLine— link receipt/shipment to PO/SO line (serialNumber, received/shipped flags).
There are no Postgres functions/triggers for depreciation or disposal — all
calculation and posting is application-level (see below). The one SQL path is
the job → asset branch inside complete_job_to_inventory (Make to Asset).
Enums
fixedAssetStatus:Draft,Active,Fully Depreciated,Disposed,Under Construction(20261006220301)depreciationMethod:Straight Line,Declining Balance,Units of ProductiontaxDepreciationMethod:Straight Line,Declining Balance,MACRSdisposalMethod:Sale,Scrapping,Transfer to Inventory(20261006220301; onlypost-asset-transferwrites the third — the UIdisposalMethodsarray still lists the first two)fixedAssetTransferType:Capitalization,Return to Inventory,Cost AdjustmentfixedAssetTransferSourceType:Inventory,Job,Construction in Progress,ManualjournalEntrySourceType,journalLineDocumentType,itemLedgerDocumentTypeeach gainedAsset TransfermacrsPropertyClass:3,5,7,10,15,20,27.5,39macrsConvention:Half-Year,Mid-Quarter
Line-type integration
purchaseOrderLine, salesOrderLine, salesInvoiceLine, purchaseInvoiceLine
each have an assetId FK → fixedAsset(id), with 'Fixed Asset' as a line-type
enum value (CHECK: only Fixed Asset lines have non-NULL assetId). The
*Lines views LEFT JOIN fixedAsset and expose assetReadableId + assetName.
Code
- Models/validators:
apps/erp/app/modules/accounting/accounting.models.ts— enum arrays (fixedAssetStatusesincl.Under Construction,fleetStatuses,depreciationMethods,taxDepreciationMethods,disposalMethods) and validatorsfixedAssetClassValidator,fixedAssetValidator,fixedAssetRegisterValidator(acquisitionCost/Date, accumulatedDepreciation, depreciationStartDate),depreciationRunValidator(periodEnd only),fixedAssetDisposalValidator(disposalDate only),fixedAssetUsageLogValidator, and the fleet bridge:fixedAssetCapitalizeValidator(fixedAssetClassId, itemId, trackedEntityId, locationId, storageUnitId?, transferDate, name?),fixedAssetReturnToInventoryValidator(transferDate, locationId, storageUnitId?),fixedAssetAttachJobValidator(jobId),fixedAssetCapitalizeCipValidator(toClassId, inServiceDate),fixedAssetOutOfServiceValidator(reason).fixedAssetCapitalizeValidatoralso takescost?+offsetAccountId?(a unit carried at zero), andfixedAssetAdjustCostValidator(amount, offsetAccountId?, locationId, transferDate) backs Adjust Cost. - Service:
accounting.service.ts—getFixedAsset(s),insert/update/deleteFixedAsset,getFixedAssetsListForSale(status Active/Fully Depreciated), class CRUD,insert/getDepreciationRun(s),getDepreciationRunLines,getAssetDepreciationHistory,getFixedAssetDisposal, usage-log helpers. NoteupsertFixedAssetis deprecated — use insert/update. Fleet section (// -- Fleet --):getFleetAssets(thefleetAssetsview; search on name / fixedAssetId / serialNumber / itemReadableId,fleetStatusfilter),getUnderConstructionAssets(statusUnder Construction),getFixedAssetTransfers,getFixedAssetCipCosts,getWorkCenterCapitalCost(every non-Disposed asset with thatworkCenterId, withnetBookValueand, for Straight Line assets with a useful life,monthlyDepreciation = round(cost × (1 − residual %) / usefulLifeMonths)),setFixedAssetOutOfService,returnFixedAssetToService,invokeAssetTransfer(invokePosting(…, postAssetTransfer, { as }): the caller holds the transfer's permission, andupdate: accountingwhen a capitalization enters its own cost). - What a run should hold:
buildDepreciationRunLines()(accounting.service.ts) — every Active asset no OTHER run of the period covers, depreciated from the last run posted before the period, Units of Production summing the usage logged since. New, Repeat, Recalculate (replaceDepreciationRunLines, keeps the run's id and number, deletes a run left empty), Post and the period close check all use it. New and the close page's Create Run create throughcreateDepreciationRun, which refuses "Nothing to depreciate for this period" instead of leaving an empty run. The close task (autoCheckKey 'draft-depreciation') fails while a new run would hold lines (getPeriodRunPreview; empty when a later period is posted) or a Draft run ends in the period. Post refuses a Draft whose lines no longer match it (depreciationRunLinesMatch,accounting.utils.ts— an asset disposed, added or re-valued since), and any run when a LATER period is already posted (laterPostedRunId: those months are in it, so posting would count them twice).buildDepreciationLinescalculates each month on its own with the accumulated book and tax depreciation carried forward; the month arithmetic (addOneMonth,getMonthsBetween) runs on@internationalized/dateCalendarDate— the old JSDateversion skipped the month after every 31-day month and shifted MACRS years west of UTC. - Posting:
postDepreciationRundates each line's journal by its month (resolveRunPostingPeriods: the month's own period, the run's when that month is Closed), updates each asset ONCE with the sum of its months, and posts one deferred tax journal per month. No run may end after the company's current month (futureRunPeriodError). - Reverse Run (
reverseDepreciationRun, route$depreciationRunId.reverse) — latest posted run only (refuses when a later period is posted, or an asset on it has been Disposed since): reverses every month's journal and deferred tax journal (reverseRunJournals), takes the amounts back off accumulated book and tax depreciation (tax only for lines that carry ataxAmount— decided from the posted lines, not the current setting), returns a Fully Depreciated asset above its residual to Active, and returns the run to Draft. A plain journal reversal of anAsset Depreciationjournal is refused. - Server transactions (Kysely): building blocks in
accounting.service.ts—postDisposal(),postDepreciationRun()andpostAssetRegistration()build journals and update asset rows.postAssetRegistrationtakes an optionalstatus("Active" | "Under Construction", default Active) and, forUnder ConstructionwithacquisitionCost > 0, also inserts afixedAssetCipCostrow (sourceType 'Manual',journalId) so a later capitalization sweeps it. - Calc utils:
accounting.utils.ts—acquisitionLines(),buildDepreciationLines(),getNextPeriodEnd(), MACRS data. - Shared line builders:
apps/erp/app/modules/shared/shared.service.ts—buildCapitalizationLines(Dr asset / Cr the account the value came from) andbuildReturnToInventoryLines(Dr inventory NBV / Dr accumulated depreciation when non-zero / Cr asset at cost); every amountround()ed, every setassertBalanced, a cost that rounds to ≤ 0 throws. - UI:
accounting/ui/FixedAssets/—FixedAssetForm(has a Work Center picker,workCenterId),AssetClassForm,FixedAssetRegisterForm,FixedAssetDisposalForm,FixedAssetCapitalizeForm,FixedAssetReturnToInventoryForm,FixedAssetAdjustCostForm,FixedAssetAttachJobForm,FixedAssetCapitalizeCipForm,FixedAssetOutOfServiceForm,FixedAssetCipCosts(the "Construction in Progress" card on the asset page, rendered for a CIP-class asset),FleetAssetsTable,FleetStatus(its own colour map — fleet status has no entry inpackages/utils/src/status-colors.ts;FIXED_ASSET_STATUS_COLOR_MAPdoes includeUnder Construction), tables, status badges. The asset page also lists the asset's transfers and showsWork Center/Out of Service Sincedetail rows. - Routes:
routes/x+/fixed-asset+/$fixedAssetId.{tsx,register,dispose,sell,purchase,details,delete,capitalize,return-to-inventory,adjust-cost,attach-job,out-of-service},routes/x+/fixed-asset+/capitalize.tsx(no id: capitalize a stock unit);routes/x+/depreciation-run+/$depreciationRunId.{tsx,post,repeat,recalculate,reverse,delete}; list/new atroutes/x+/accounting+/{fixed-assets,asset-classes,depreciation-runs}*; the fleet register atroutes/x+/accounting+/fleet.tsx(nav: Accounting → Fixed Assets → Assets / Fleet, and Accounting → Closing → Depreciation,useAccountingSubmodules). - Postings (ported from server functions to module building blocks):
postReceiptandpostShipment(inventory.service.ts),postPurchaseInvoice(acquisition, CIP-aware) andpostSalesInvoice(disposal) (invoicing.service.ts),postAssetTransfer(transfers,accounting.service.ts). - Outside the module: production
production.models.ts(jobValidatorcarriesfixedAssetClassId/fixedAssetId, refined to at most one: "A job completes to a fixed-asset class or to one asset under construction, not both"),ui/Jobs/JobForm.tsx(Complete To: Inventory / Fixed Asset Class / Asset Under Construction;x+/job+/new.tsxpre-fills the class from?fixedAssetClassId=),ui/Jobs/JobHeader.tsx(the complete dialog hides the location / bin pickers and says "Completes to fixed asset class …" or "Sweeps cost to asset …"),routes/x+/job+/$jobId.status.tsx(release gate, below); inventoryui/Inventory/InventoryStorageUnits.tsx(row action Capitalize as Fixed Asset); resourcesroutes/x+/resources+/work-centers.$id.tsx+ui/WorkCenters/WorkCenterForm.tsx(read-only Capital Cost panel).
Lifecycle
Acquire (Draft → Active, or → Under Construction). Four paths set
acquisitionCost, depreciationStartDate (if unset), and flip status; a
fifth (5, a lessee lease's purchase option) inserts the asset already Active:
Manual: create asset (Draft), then
$fixedAssetId.registeraction withfixedAssetRegisterValidator, which callsregisterFixedAsset(accounting.server.ts). For every company it posts an acquisition journal viapostAssetRegistration()inside one Kysely transaction (Provisional before the accounting cutover, with no period and no dimension check; Posted after it) (sourceType'Manual', descriptionAsset Registration: <readableId>) and only then flips the asset (journal first, so no capitalized asset exists without a GL entry; the whole transaction rolls back on failure). The lines come fromacquisitionLines():- No prior depreciation (
accumulatedDepreciation = 0) — two lines: DebitassetAccountId(gross cost) / CreditaccountDefault.retainedEarningsAccount(owner equity) at cost. - Mid-life capitalization (
accumulatedDepreciation > 0) — three lines, so the GL asset/contra balances match the subledger's net book value instead of overstating the asset at gross: DebitassetAccountId(gross cost) / CreditfixedAssetClass.accumulatedDepreciationAccountId(opening accum depreciation) / CreditretainedEarningsAccountfor NBV only (cost − accumulatedDepreciation).
The route resolves
registeredStatusfrom the class: a CIP class registers toUnder Construction(and the server writes the CIP cost row), any other class toActive.- No prior depreciation (
Via posting:
post-receipt/post-purchase-invoiceprocess Fixed Asset PO lines, incrementacquisitionCost, and post DebitassetAccountId/ Credit GRNI (receipt) or payables (invoice). A Draft asset flips toActive, or toUnder Constructionwhen its classisConstructionInProgress— thendepreciationStartDatestays null and the cost is also appended as afixedAssetCipCostrow (sourceType 'Receipt'/'Purchase Invoice',sourceDocumentId/sourceDocumentLineId,journalId). Voiding the document deletes its CIP rows and backs the amount out ofacquisitionCost; it is refused with "Asset was capitalized; reverse the capitalization first" once the asset has leftUnder Construction.Make (job → asset): a job with
fixedAssetClassIdcompletes into one new asset per unit; see Make to Asset below.Capitalize from stock:
post-asset-transfercapitalizeconsumes anAvailableserialized unit into a new (or a Draft) asset at its carrying cost — or, for a unit carried at zero, at the cost the user enters; see post-asset-transfer below.Exercise a lessee lease's purchase option for one leased asset:
post-leasepurchase(apps/erp/app/modules/purchasing/purchasing.service.ts; lease page → the asset in the explorer → its page → Exercise Purchase Option,x+/lease+/$id.$lineId.purchase.tsx,update: purchasing). Refused for a Short-Term asset (and an open-ended lease, whose assets all are), an exercise date before the commencement, and a Construction in Progress class ("Choose an in-service fixed asset class"). An asset with nopurchaseOptionAmountcan be taken only whenownershipTransfers: on the lease's end date, at price 0 (ownership passes for nothing); with neither, it is refused ("has no purchase option"). In ONE transaction it posts a'Lease'journal (purchaseLines,purchasing.service.ts): Dr the class'sassetAccountIdatassetCost = ROU cost − accumulated ROU amortization + price − carrying liability(refused below zero), Dr accumulated ROU amortization, Dr lease liability (carrying, plus a Pending option row the schedule already counted as paid), Cr ROU asset (cost), Cr lease liability (the price, billed later as aPurchase OptionleasePaymentrow whose Lease invoice line debits the liability — or nothing, when an option row was already invoiced at that price). Then it INSERTS a newfixedAssetdirectly withstatus 'Active',quantity 1, the leased asset'sserialNumber, the asset's location (else the lease's),acquisitionCost = assetCost,acquisitionDate = depreciationStartDate =the exercise date, and the class's method, useful life and residual; nofixedAssetCipCostrow and no accumulated depreciation.leaseLine.fixedAssetIdand the asset'sleaseEvent(typePurchase) point at it; the asset becomesPurchased, and the lease too when it was its last active asset. See purchasing AGENTS → Leases.
Adjust Cost (post-capitalization). An asset that came onto the books for
less than it cost — a Make to Asset job with no WIP creates it at 0 — is raised
by post-asset-transfer adjustCost (asset menu → Adjust Cost,
$fixedAssetId.adjust-cost.tsx). Raise only; lowering is a write-down. The
next depreciation run catches a Straight Line asset up on the months it took
at the old cost (see Depreciate).
Make to Asset. The branch lives inside complete_job_to_inventory
(20261006221601_complete-job-to-asset.sql, forked from the guarded definition in
20260925121735_rpc-function-guards.sql), so every
completion path (ERP route, API/MCP, the sync_finish_job_operation trigger)
gets it. v_asset_target is 'asset' when job.fixedAssetId is set, 'class'
when job.fixedAssetClassId is, else null (the ordinary receipt). Guards, all
raised before anything moves: a job with a salesOrderLineId ("A job linked to
a sales order line cannot complete to a fixed asset"); a class target with a
non-serial item at any quantity ("A job that completes to a fixed asset class
needs a serialized item", 20261006221601 — every asset it makes is a fleet unit,
and Return to Inventory / capitalization follow the serial); an asset target
with a non-serial item completing anything but exactly 1 ("Make to Asset needs a
serialized item or a quantity of one"); a fixedAssetId whose class is not CIP ("Job … targets fixed
asset … which is not in a Construction in Progress class"); fewer unconsumed
serial units than the quantity being completed. The item rule is
makeToAssetItemError (production.models.ts): x+/job+/new.tsx and
$jobId.details.tsx return it as a field error on the item when the job is
saved, x+/job+/update.tsx refuses a property-panel item change with it, and $jobId.status.tsx runs it with the sales order line gate when a
job goes Ready.
'class': onefixedAssetper unit (fixedAssetIdfromget_next_sequence('fixedAsset'), name<item name> <serial | jobId>,itemId,trackedEntityId,serialNumber, the class's method / life / residual,acquisitionDate = depreciationStartDate = company_today,locationId= the job's, statusActive, orUnder Constructionfor a CIP class) plus one PostedfixedAssetTransfereach (type 'Capitalization',sourceType 'Job',jobId). Serial units are taken in the receipt's order (shop-floor-finishedAvailablefirst, then byreadableId), skipping any unit already carryingattributes['Fixed Asset']; each goesConsumedwith that attribute and a'Capitalize'trackedActivity(sourceDocument 'Fixed Asset', input = the unit). After the WIP journal,acquisitionCost= accumulated WIP ÷ units and the transfers getamount+journalId.'asset': no new asset; the accumulated WIP becomes onefixedAssetCipCostrow (sourceType 'Job') and one transfer (quantity= the units completed), and the asset'sacquisitionCostgrows by it (status stays / becomesUnder Construction).- Either way the units never enter stock: no
itemLedger,costLedger,pickMethodoritemCostwrite; the WIP discharge posts Dr classassetAccountId(descriptionFixed Asset) / Cr WIP as an'Asset Transfer'journal, both lines stilldocumentId = jobIdso the per-job WIP balance nets to zero for a re-completion; aFixedAssetClassdimension is stamped when active. Every company writes the asset cost; before the accounting cutover the journal is Provisional. Partial completions create assets for the units received so far. Covered bypackages/database/supabase/tests/job-completion-to-asset.test.sql.
Construction in progress is hidden. CONSTRUCTION_IN_PROGRESS_ENABLED = false (accounting.models.ts) keeps it out of the app until it returns with
projects: getFixedAssetClasses / getFixedAssetClassesList drop CIP classes
(so no class list or picker offers one and no asset reaches Under Construction
from the UI), the asset page's isCipClass is false (no Attach Job, Capitalize
or CIP cost card), the status filters use visibleFixedAssetStatuses /
visibleFleetStatuses, and JobForm offers Complete To → Asset Under
Construction only for a saved job that already targets an asset. Everything
below is built and live server-side; flip the constant to bring it back.
Construction in progress. A CIP class (isConstructionInProgress) is a
holding account: its assets sit at Under Construction, are skipped by
depreciation runs (depreciation-runs.new selects status = 'Active'), and
accumulate fixedAssetCipCost rows from (1) Fixed Asset PO lines (path 2
above), (2) jobs — Attach Job (post-asset-transfer attachJob) or a job
created with Complete To = Asset Under Construction, both swept by the
completion branch, and (3) registration / stock capitalization into the class
('Manual' rows). Capitalize (post-asset-transfer capitalizeCip) moves
the asset into an in-service class at inServiceDate. The asset page offers
Attach Job while the asset is Draft or Under Construction and Capitalize
while Under Construction; $fixedAssetId.attach-job lists jobs with no
salesOrderLineId, no asset target and status not in Completed / Cancelled /
Closed; $fixedAssetId.capitalize offers only non-CIP classes.
post-asset-transfer (postAssetTransfer in accounting.service.ts, ported
from the server function, with its zod contract and pure helpers). One fixedAssetTransfer
document per call, created and Posted in ONE transaction; the function's permissions are keyed by
type: create: accounting for capitalize / return / attachJob /
capitalizeCip, update: accounting for adjustCost, and a capitalize
that carries an entered cost additionally requires update: accounting (recosting puts a number of the user's own on the books); business failures are 400
InvalidInputErrors with the message the app shows, a record the
caller's company does not own is a 404. Every action writes its journal for every
company: Provisional before the accounting cutover (no period), Posted after it. Journals
are sourceType 'Asset Transfer', lines documentType 'Asset Transfer', with
Location / FixedAssetClass / Item dimensions. Four payload variants:
capitalize(fixedAssetClassId,itemId,trackedEntityId,locationId,storageUnitId?,transferDate,name?,fixedAssetId?= a Draft asset to fill,cost?+offsetAccountId?for a unit carried at zero): the unit must belong to the item, beAvailable, have no live asset and net on-hand at the location (resolveCapitalizationStock: the bin with the highest positive net wins; a picked unit has rows in more than one bin). Creates the asset (or fills the Draft under the samestatus = 'Draft'race guard as registration) withquantity 1,serialNumber= the unit'sreadableId,acquisitionDate = transferDate,depreciationStartDate = transferDate(null for a CIP class), statusActive(Under Constructionfor a CIP class); relieves the unit through the shared adjustment path (itemLedger−1,entryType 'Negative Adjmt.', cost-layer consumption at carrying cost, no variance journal); posts Dr class asset / Cr the replenishment inventory account for that cost. The cost is decided by the pureresolveCapitalizationCost(accounting.service.ts): a unit that carries a cost moves at it, and an enteredcostis refused (" is carried in inventory at a cost…"); a unit whose carrying cost rounds to 0 takes the enteredcostinstead and the journal creditsoffsetAccountId(descriptionCapitalized Cost; always required, an active non-group account of the company group —getOffsetAccount,shared.service.ts, which returns the account's class sobuildCapitalizationLinessigns the credit by it: Retained Earnings is Equity, credited +x); with neither it is REFUSED — " has no cost in inventory… Enter what it cost, or set a unit cost…" — and the transaction rolls back. The entered value never touches the cost ledger: inventory relieved the unit at 0, and the value comes from the offset account, not from stock; writes a'Manual'CIP row for a CIP class; sets the entityConsumedwithattributes['Fixed Asset']and a'Capitalize'activity. Transfer:type 'Capitalization',sourceType 'Inventory'. Entry points: the inventory storage-unit row action andx+/fixed-asset+/capitalize.tsx(defaults the class to the one namedRental Fleet, hides CIP classes, shows the exact cost the transfer will book; when it is 0 the form asks for an Acquisition Cost and an Offset Account defaulting toaccountDefault.retainedEarningsAccount). That cost comes from thepreviewAssetCapitalizationbody (accounting.service.ts,{ trackedEntityId },view: accounting; ERP wrappergetCapitalizationCost): the samecalculateCOGSrelief in a transaction that always rolls back, so it matches the posted amount for every costing method — the unit's own layer, a layer at net book value, the average, or the item's unit cost when FIFO finds no layer. The item's unit cost alone was wrong whenever those differ.return(fixedAssetId,locationId,storageUnitId?,transferDate): asset must beActiveorFully Depreciated(RETURNABLE_ASSET_STATUSES) and its entityConsumed; the route additionally requiresitemIdand nooutOfServiceSince. NBV =acquisitionCost − accumulatedDepreciation.itemLedger+1 ('Positive Adjmt.') with a cost layer at NBV stamped with the unit (costLedger.trackedEntityId, so the unit is later sold at that NBV — seeinventory-system.md), journal frombuildReturnToInventoryLineswhen cost > 0, asset →DisposedwithdisposalMethod 'Transfer to Inventory'plus afixedAssetDisposalrow at NBV, entity back toAvailablewith theFixed Assetattribute removed and a'Return to Inventory'activity. Transfer:type 'Return to Inventory',sourceType 'Inventory',amount= NBV,accumulatedDepreciationrecorded.attachJob(fixedAssetId,jobId): asset's class must be CIP and its status Draft / Under Construction; the job must not be inCLOSED_JOB_STATUSES(Completed / Cancelled / Closed), must have nosalesOrderLineIdand no asset target. Setsjob.fixedAssetId(guarded on the job still having no target) and sweeps the job's current WIP balance: Dr CIP asset / Cr WIP ('Asset Transfer', both linesdocumentId = jobId, the transfer indocumentLineReference), onefixedAssetCipCostrow ('Job') and one transfer (sourceType 'Job'), asset →Under ConstructionwithacquisitionCost += balance(nothing is swept when the balance is 0; before the accounting cutover the balance is read from the job's Provisional WIP lines). An unset asset location is filled from the job.capitalizeCip(fixedAssetId,toClassId,inServiceDate): asset must beUnder Constructionin a CIP class, target must not be CIP, and the asset needs a location (its own, else the latest attached job's). Posts Dr target class asset / Cr CIP asset for ΣfixedAssetCipCost, then setsfixedAssetClassId= target,acquisitionCost= the sum,acquisitionDate = depreciationStartDate = inServiceDate, statusActive(guarded onstatus = 'Under Construction'). Transfer:type 'Capitalization',sourceType 'Construction in Progress',fromClassId,inServiceDate.adjustCost(fixedAssetId,amount> 0,offsetAccountId?,locationId,transferDate): asset must beActiveorFully Depreciated(ADJUSTABLE_ASSET_STATUSES, re-checked underFOR UPDATEin the transaction). Posts Dr classassetAccountId/ CroffsetAccountId(descriptionCapitalized Cost). The offset account is always required: the validator types it optional, butgetOffsetAccount(shared.service.ts) refuses a missing one and anything but an active posting account of the company group.acquisitionCost += amount, and the status fromstatusAfterCostAdjustment(Fully Depreciated → Active when NBV is above residual again). Fills an unset asset location fromlocationId(the route asks for one only when the asset has none). Transfer:type 'Cost Adjustment',sourceType 'Manual',accumulatedDepreciationrecorded. The route defaults the offset account to Retained Earnings.
Fleet register. x+/accounting+/fleet.tsx renders getFleetAssets with
the derived status (see the view); Build for Fleet (needs
create: production) opens path.to.newJob?fixedAssetClassId=<the class named "Rental Fleet", else the first non-CIP class>. Row menu: View Asset, Rent (only
fleetStatus = 'Available', needs create: sales; opens
path.to.newRentalAgreement?fixedAssetId=, which creates the Draft agreement
with that unit as its first line), Take Out of Service / Return to Service,
Return to Inventory (rows with an itemId that are on the books).
Rentals. A rental agreement (sales module, documented in
apps/erp/app/modules/sales/AGENTS.md → Rentals) rents fleet units. Each
line's accounting treatment (lessorClassification) is set at activation:
Rental / Sale / Financing (ASC 842 operating / sales-type / direct
financing lease; Financing has no input). A Rental line posts no journal at activation, the asset stays Active and keeps
depreciating, and only the derived fleet status changes (Reserved → On Rent →
Available again, or In Maintenance when the rental receipt line's Take out of
service box is ticked — returnRentalUnit (sales.service.ts)
sets outOfServiceSince = returnedAt and the reason). A unit goes On Rent when a
rental shipment posts (post-shipment, source 'Rental Agreement') and comes back
when a rental receipt posts (post-receipt); neither writes an itemLedger row or a
journal for a Rental line. Posting the receipt sets fixedAsset.locationId to the
receipt's location. Release unit (post-rental-agreement release) ends a
Pending unit that never left the yard and does not move it. See
apps/erp/app/modules/sales/AGENTS.md → Rentals → Deliver and return. post-rental-agreement activate accepts a unit
whose fleetStatus is Available, or Reserved by the same agreement, and
whose asset status is Active / Fully Depreciated; In Maintenance is
refused with " is out of service: ". Posting a rental shipment
refuses an out-of-service unit with the same message. Return to Inventory is refused while the unit is on a
live rental line: post-asset-transfer returnToInventory checks for a
rentalAgreementLine with status IN ('Pending','On Rent') inside its
transaction and throws "Asset is on rent|reserved on rental agreement
<RA…>; return it from the agreement first". The fleet table hides the
Return to Inventory menu item for On Rent and Reserved rows, and Take Out of
Service for On Rent rows; postAssetTransfer and the route stay the gates.
Sales-type leases dispose the fleet asset. A line classified Sale
(a sales-type lease) at activation (post-rental-agreement commenceSalesTypeLines) is sold to the
lease at ACTIVATION, not delivery: the asset goes Disposed,
disposalMethod 'Sale', disposalDate = company today, saleProceeds = the
net investment, guarded on status IN ('Active','Fully Depreciated') (a
concurrent change refuses with " changed status while the agreement was
being activated"), plus a fixedAssetDisposal row (netBookValueAtDisposal
= C = cost − accumulated depreciation, gainLoss = selling profit, journalId
= the commencement journal). The 'Lease' journal (Provisional before the
accounting cutover; pure
builder buildCommencementLines, sales.service.ts) is: Dr Net
Investment in Leases NI, Dr COGS C − PVres, Dr class
accumulatedDepreciationAccountId accumulated depreciation / Cr Lease
Revenue PVpay, Cr class assetAccountId at cost; no gain/loss or
clearing account is used (the selling profit is Lease Revenue less COGS). The
tracked entity goes Consumed (attribute Fixed Asset removed, Rental Agreement + Customer added, a Lease Commencement activity). The derived
fleetStatus then reads Sold (any Disposed asset not returned to stock)
while the rental line is still On Rent. Commencement is fleet-only: activation
refuses a line without a fleet unit, so the spec's from-stock commencement has
no entry point in v1.
Residual return capitalizes a NEW Rental Fleet asset. Returning a
Sale line on a rental receipt at or after endDate with residualDestination: "Fleet"
(returnResidual) inserts a new fixedAsset at the receipt's location (new fixedAssetId from the
sequence) in the non-CIP class named "Rental Fleet" (else the class the unit
left at commencement; neither → "No Rental Fleet asset class to return the
unit into; create one or return the unit to inventory") with acquisitionCost
= the closing net investment (netInvestmentAt, sales.service.ts: the
closingNetInvestment of the last rentalLeaseScheduleLine dated on or
before returnedAt — the closing target at or after endDate — or
initialNetInvestment when the line has no schedule; read off the schedule,
NOT off posted principal, so an unposted final month is neither overstated
nor lost),
acquisitionDate / depreciationStartDate = today, the class's method /
life / residual, status Active, the same itemId / trackedEntityId /
serial; a Posted fixedAssetTransfer (type Capitalization, sourceType
Inventory, amount = closing); 'Lease' journal Dr class assetAccountId /
Cr Net Investment in Leases (skipped when closing is 0);
the entity stays Consumed with Fixed Asset = the new asset and a
Capitalize activity. The disposed original is untouched (the live-serial
unique index ignores Disposed rows). residualDestination: "Inventory"
instead books bookAdjustment +1 at the receipt's location at fixedUnitCost = closing and Dr the
item's inventory account. Schedule lines and Planned Interest rows dated on or
before the return STAY and post through later recognition runs (that is what
brings Net Investment in Leases to zero: initial NI + Σ interest − Σ rent −
closing = 0); only unposted ones dated after the return are deleted, and only
a Draft run holding Interest rows dated after the return blocks it. A return
dated after company today is refused ("The return date cannot be in the
future"), and a Sale line's billing is not re-cut by a return.
Purchase option exercise derecognizes the rest. Posting a Sale
line's Purchase Option invoice line (post-sales-invoice,
purchaseOptionSettlement in invoicing.service.ts) credits NI by the option
and settles the difference to the schedule's closing balance (the last
rentalLeaseScheduleLine's closingNetInvestment): shortfall Dr
costOfGoodsSoldAccount / Cr NI, excess Dr NI / Cr leaseRevenueAccount,
on the option line's journal line reference so VOID reverses it. No asset is
created — the unit is the customer's.
Out of service. outOfServiceSince / outOfServiceReason are set together
by setFixedAssetOutOfService (date = company today) and cleared together by
returnFixedAssetToService; both through $fixedAssetId.out-of-service.tsx
(update: accounting; a plain POST takes the asset out with the form's reason
through fixedAsset.takeOutOfService, POST ?intent=return returns it through
fixedAsset.returnToService). The loader and the operation refuse an asset
already out of service or Disposed (outOfServiceRefusal). Accounting is untouched: the asset stays Active and
keeps depreciating; only the fleet status reads In Maintenance, and Return to
Inventory is blocked until the asset is back in service. A unit On Rent
cannot be taken out of service: the loader and the operation both refuse it
(getOnRentLineForAsset, sales.service.ts, read with the service role
scoped to company + asset — an accountant may lack sales_view, and under RLS
that read as "not on rent"; a failed read refuses) with "The asset is on rent on
<RA…>; return it from the agreement and take it out of service there" — the
agreement's Return form has the out-of-service box for exactly that.
Work-center link. fixedAsset.workCenterId is a picker on the asset form
and a detail row on the asset page; work-centers.$id.tsx loads
getWorkCenterCapitalCost and WorkCenterForm renders a read-only Capital
Cost panel (asset id → NBV, per-asset monthly depreciation for Straight Line
assets, totals). Machine rates are still typed by hand.
Depreciate. Manual, in two steps — no scheduled/cron job exists:
Cost adjustment catch-up. buildDepreciationRunLines passes
costAdjusted (the asset has a Posted Cost Adjustment transfer) to
buildDepreciationLines, which adds straightLineShortfall — what the CURRENT
cost would have accumulated on a straight line from the start through the
month before the run, less what was accumulated, never negative — to the
asset's first month (book, and tax when the tax method is Straight Line),
capped at what is left. It is stateless: once posted the shortfall is zero,
and Reverse Run brings it back. Declining Balance and table MACRS correct
themselves (remaining value over remaining life / cumulative minus taken);
Units of Production does not catch up. Gated on the adjustment so a mid-life
registration with an opening accumulated balance is never re-derived.
depreciation-runs.newcalls the service functioncreateDepreciationRun, which calls the building blockcreateDepreciationRun(), which builds the lines withbuildDepreciationRunLines()and inserts adepreciationRun(Draft) + onedepreciationRunLineper asset per month. With no lines it creates nothing.$depreciationRunId.post→ the service functionpostDepreciationRun→ the building blockpostDepreciationRun(): locks the runFOR UPDATEand refuses anything but a Draft, re-reads the lines and locks the assets inside the transaction (RunOutOfDateErrorwhen they no longer match what the operation checked), then per asset per month posts DebitdepreciationExpenseAccountId/ CreditaccumulatedDepreciationAccountId(sourceType: 'Asset Depreciation'; a month with a zero book amount posts no journal), adds toaccumulatedDepreciationin SQL (+ tax / deferred-tax lines when enabled via company settings), sets runPosted, flips asset toFully Depreciatedwhen NBV hits residual.
Dispose (Active / Fully Depreciated → Disposed). GAAP: remove cost + accum
depreciation, recognize proceeds, and book the net gain/(loss) = proceeds −
NBV to a distinct non-operating line — never comingled with revenue. Carbon
uses gainOnDisposalAccountId / lossOnDisposalAccountId for that gain/loss
and writeOffAccountId as a disposal clearing / holding account in the
two-step (ship → invoice) flow.
- Manual scrap:
$fixedAssetId.dispose→disposeFixedAsset(Active or Fully Depreciated only) →postDisposal()(hardcodesScrapping). NBV =acquisitionCost − accumulatedDepreciation; proceeds = 0, so the entire NBV is a loss. Posts Debit accumulated depreciation, DebitlossOnDisposalAccountIdfor the full NBV loss, Credit asset at cost (sourceType: 'Asset Disposal'), applies location/class dimensions, writesfixedAssetDisposal(gainLoss = −NBV), setsDisposed. - Via posting (two-step sale):
post-shipment(asset physically leaves): Debit accumulated depreciation, DebitwriteOffAccountId(disposal clearing) for NBV — a balance-sheet holding, not a P&L loss — Credit asset at cost. WritesfixedAssetDisposalwithsaleProceeds = 0,gainLoss = 0(unknown until invoiced) and setsDisposed. No interim P&L impact.post-sales-invoice(proceeds recognized): Debit AR for proceeds, CreditwriteOffAccountIdfor NBV (clears the clearing account back to zero), then books the explicit gain/loss — CreditgainOnDisposalAccountIdfor a gain, DebitlossOnDisposalAccountIdfor a loss. Updates the disposal rowgainLoss = proceeds − NBV. Over a completed cyclewriteOffAccountIdnets to zero and the gain/loss accounts carry only the gain/loss.- Direct sales invoice (no prior shipment) posts the combined single-step
disposal: Debit accum depreciation, Credit asset at cost, Debit AR for
proceeds, and the gain/loss to the gain / loss accounts (no clearing
round-trip),
disposalMethod 'Sale'.
- Return to inventory (
post-asset-transferreturn, above):DisposedwithdisposalMethod 'Transfer to Inventory', no gain/loss — the unit goes back to stock at NBV and is sold later like any other stock.
Gotchas
- Tax depreciation / deferred-tax lines only post when
companySettings.assetTaxDepreciationEnabledis true. - Register posts an acquisition journal (Dr
assetAccountId/ CrretainedEarningsAccount) for every company, then flips status. Before the accounting cutover the journal is Provisional, has no period, and a missing Location / FixedAssetClass dimension does not block it. writeOffAccountIdis the disposal clearing / holding account (parks NBV between shipment and invoice, nets to zero);gainOnDisposalAccountId/lossOnDisposalAccountIdcarry the net gain/(loss).writeDownAccountIdremains unused (reserved for impairment).- Depreciation is entirely manual — there is no Inngest/cron job that advances
periods; users must create and post each
depreciationRun.Under Constructionassets are skipped (notActive); out-of-service assets are not. disposalMethod(Sale/Scrapping/Transfer to Inventory) is set by the posting flow / asset column;fixedAssetDisposalValidatoritself only carriesdisposalDate.- A CIP class's own method / life / residual never run: capitalization starts
depreciation at
inServiceDateunder the in-service class. OnlyfixedAssetCipCostrows are capitalized — cost that reaches a CIP asset without a row (there is no such path today) would be silently dropped. fixedAssetTransfer.statusis alwaysPostedin practice; do not build a Draft-review UI on the column without adding the poster.- A fleet asset's unit must be serialized:
fixedAsset.quantityis CHECKed to 1 andcomplete_job_to_inventoryrefuses a non-serial item for any class job. Assets made before20261006221601by a single-unit untracked job have notrackedEntityId, andpost-asset-transferneeds one to return a unit to inventory. - Any Disposed asset that was not returned to stock reads
Sold(a scrapped fleet unit too). Reservedmeans "named on a live Pending line", which includes every line of a DRAFT agreement. Cancelling an agreement deletes its Pending lines (the line status enum has no Cancelled), which is what frees the unit.- A
Rentalline (operating lease) never changesfixedAsset.status. ItslocationIdchanges only when a rental receipt posts: the unit is then at the receipt's location. While it is out, custody is the agreement'scustomerLocationId, exposed onfleetAssets. ASaleline (sales-type lease) disposes the asset at activation (above), and a residual return creates a different asset row rather than reviving the old one.