Cost sales first-in-first-out per branch instead of at an average #7
Reference in New Issue
Block a user
Delete Branch "fix/fifo-cost-of-goods"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cost of goods sold used each product's average buying price across the whole business. Ten jerrycans bought at KES 100 and ten at KES 140, with 15 sold, cost KES 1,800 instead of the KES 1,700 actually paid for those units. A branch that bought dearer was costed like one that bought cheaper, and stock moved between branches lost its cost.
What changes
src/lib/server/costing.tsreplays the stock ledger in order, keeping cost layers per branch and product:The Reports page and CSV show the method ("FIFO per branch") and a new Stock losses card; the net profit card says it deducts stock losses.
Each report replays the business's whole stock history. That is fast at pilot volumes; a business with years of history would want stored cost layers (noted in
docs/PILOT_READINESS.md).Testing
npm test: 83 tests pass, 7 new intests/costing.test.ts:tests/followups.test.tschanged from 33 (average) to 30 (oldest stock first).No migration or deploy step.
🤖 Generated with Claude Code