Hey everyone,
I’ve been helping a few e-commerce clients get their books set up in Beancount, and inventory tracking for COGS (Cost of Goods Sold) is always one of the trickiest parts. Figured I’d share what I’ve learned and see how others are handling this.
The COGS Formula
The fundamental formula we need to track is:
COGS = Beginning Inventory + Purchases + Direct Costs - Ending Inventory
Sounds simple, right? But in plain text accounting, you need to actually structure your accounts to capture each piece correctly.
My Recommended Account Structure
Here’s what I set up for product-based businesses:
; Inventory accounts
Assets:Inventory:RawMaterials
Assets:Inventory:FinishedGoods
Assets:Inventory:PackagingSupplies
; COGS expense accounts
Expenses:COGS:ProductCost
Expenses:COGS:ShippingIn
Expenses:COGS:PackagingMaterials
; Purchase tracking
Expenses:Purchases:Inventory
Recording a Purchase
When inventory arrives:
2026-02-15 * "Supplier Co" "Widget inventory purchase - 100 units @ $15"
Assets:Inventory:FinishedGoods 1500.00 USD
Assets:Bank:Checking -1500.00 USD
Recording a Sale (with COGS)
This is the key part - when you sell, you need two transactions:
2026-02-18 * "Customer" "Sold 10 widgets @ $25"
Assets:Bank:Checking 250.00 USD
Income:Sales:Products -250.00 USD
2026-02-18 * "COGS" "Cost basis for 10 widgets sold"
Expenses:COGS:ProductCost 150.00 USD
Assets:Inventory:FinishedGoods -150.00 USD
Choosing an Inventory Valuation Method
There are three common approaches:
-
FIFO (First In, First Out) - Oldest inventory sells first. Best for perishables and matches how most physical inventory actually moves.
-
LIFO (Last In, First Out) - Newest inventory sells first. Can provide tax advantages in inflationary periods (though not accepted for IFRS).
-
Weighted Average Cost - Simplifies calculations for non-perishables where exact lot tracking isn’t practical.
For most of my small business clients using Beancount, I recommend FIFO since it aligns with physical reality and is accepted everywhere.
Questions for the Community
- How are you handling lot tracking in Beancount for inventory that has varying purchase prices?
- Anyone using the built-in cost basis tracking for inventory (not just investments)?
- What queries do you run to calculate your month-end COGS automatically?
Would love to hear what’s working for others!