Deleting a working module: replacing an order book with a status transition
A sales module built thirteen days earlier was removed because it modelled an order lifecycle the business does not have, replaced by Sold as a terminal locking status with admin-only return that reactivates the container it came from, and a remembered-but-uncounted former pallet so history survives without the stock claim.
What was done
A working sales module built thirteen days earlier — customers, orders, line items, fulfilment — was removed, because the business sells in bulk to trade buyers and has no order lifecycle to model; every screen in it asked for information nobody had. Sold became a stock status instead, reachable from a lot, a single device in the table, or an asset pallet sold as one unit, with the sale price captured at sell time (which is what made the finance reports possible the same day) and a Sold page that is an archive rather than a workflow. Two rules keep the stock counts honest. Selling is terminal and locks the asset, and only an admin can return it. A sold device leaves its pallet, because an open pallet must not keep claiming stock that has physically gone, but the allocation is moved to sold_from_pallet_id rather than discarded, so the record of where the device sat survives and nothing counts it. Returning clears both links and reopens the pallet or lot the device comes back into, otherwise the container still says it has gone while holding live stock.
BEFORE SELL AFTER SELL
pallet_id ---+ pallet_id = null
| sold_from_pallet_id --+
v v
+--------------+ +--------------+
| PALLET 0043 | | PALLET 0043 |
| counts it | | remembers it |
| claims stock | | no claim |
+--------------+ +--------------+
return, admin only: clears both links and reopens
the pallet or lot the device comes back intoHistory without the stock claim.
Status
Shipped, 25 July 2026.
Supersedes 2026-07-12-sales-costing-and-sessions.md.
The problem
The sales module built thirteen days earlier modelled an order book: customers, orders, line items, fulfilment. The business does not have one. Stock goes to trade buyers in bulk, and what has to be recorded is a status transition — this has left, on this date, for this price — not an order lifecycle.
Every screen in the sales module asked for information nobody had.
What was built
Sold as a status, not a module. Customers and Sales pages were removed entirely.
- Sell from anywhere it makes sense: a whole lot from its status, a single device from the table, an asset pallet as one unit.
- A Sold page with hierarchy groups, bulk selection, filters and CSV export — an archive, not a workflow.
- Sale price captured at sell time, which is what made the Reports finance analytics possible the same day.
The two rules that make it safe
Selling is terminal, and locks. A sold asset leaves active inventory and
cannot be edited. Only an admin can return it (return_sold is admin-grade and
is in no default permission set).
Returning reactivates what it came from. A device returned from a sale reactivates its shipped pallet or sold lot — otherwise the device comes back to a container that still says it has gone, and the stock counts disagree with each other.
A sold device leaves its pallet, but the pallet is remembered. Clearing the
allocation is necessary — an open pallet must not keep claiming stock that has
physically gone — but it destroys the only record of where the device sat. So
sold_from_pallet_id keeps the history without the claim, and nothing counts
it. later surfaced it on the register.
Why it matters
This is the clearest case in the project of deleting a working feature because it modelled the wrong world. The sales module was not broken; it was answering a question the business does not ask.
The costing built alongside it survived, because profit per device is a real question. The order management did not.
What was deliberately not built
No invoicing inside the Sold workflow. Invoicing arrived separately in August and was then deliberately unhooked from the pallet when it turned out not to belong there either.
Open questions
None outstanding.
The code
The sell transition: the pallet link moves from the counted column to the remembered one in the same update.
await this.assets.update(id, {
stockStatus: AssetStockStatus.SOLD,
soldAt: new Date(),
soldById: user.userId,
salePrice: salePrice != null && salePrice >= 0 ? salePrice : null,
// A sold device has physically left the building, so it leaves its
// pallet too -- otherwise the pallet's device count claims stock that
// is gone. Where it sat is kept as history on sold_from_pallet_id,
// which nothing counts, so the record survives without the claim.
soldFromPalletId: before.palletId ?? before.soldFromPalletId ?? null,
palletId: null,
movedToPalletAt: null,
movedToPalletById: null,
});apps/api/src/assets/assets.service.ts — an excerpt, trimmed to the technique it illustrates.
Not shown. The permission check and the admin-grade definition behind return_sold were left out as an access control still in use; the excerpt stops at the data transition. No customer or buyer names, no sale prices, and not the pallet-sold or lot-reopen services around it.
A published copy. Commit references and internal identifiers have been removed and the operator is not named; the engineering, the counts and the stated limits are unchanged.