Raw cotton arrives at a spinning mill in bales of about 200 kg each, by the truckload. Every shipment is a lot, and no two lots are the same: one has longer fibres, another is a little damp, a third carries more trash. If a damp lot slips into the blowroom unchecked, an entire day's yarn can fail its strength test.
So the mill's stores had three jobs: buy the right cotton on time, check every lot before accepting it, and know exactly how much of each lot was left and what it was worth. In ERPNext, that's the Buying and Stock modules working together.

Keywords
- Material Request (MR): An internal "we need this" note from stores or production.
- Purchase Order (PO): The order sent to the supplier.
- Purchase Receipt (PR): Goods received into a warehouse. Posts to the Stock Ledger.
- Purchase Invoice (PI): The supplier's bill. Posts to the General Ledger.
- Batch: A group of units that share properties (a cotton lot, a dye lot, an expiry date).
- Quality Inspection (QI): A checklist of readings that accepts or rejects incoming goods.
- Bin: ERPNext's running totals per item per warehouse (actual, ordered, reserved...).
- Valuation method: How stock is priced: FIFO or Moving Average.
Character Mapping
- Material Request: The storekeeper's note to the purchase officer.
- Purchase Order: The purchase officer's order to the cotton supplier.
- Quality Inspection: The lab technician with the micronaire tester at the gate.
- Purchase Receipt: The gate entry that puts bales into the store.
- Batch: The lot tag stapled to every bale.
- Bin: The storekeeper's tally board on the wall.
1. Procure to Pay, Step by Step
Step 1: Material Request. Stores (or a reorder rule, below) raise a request for raw cotton. Requested Qty goes up.
Step 2: Purchase Order. Purchasing turns the request into a PO for a supplier. Ordered Qty goes up, Requested Qty comes down. (For bigger buys you can add Request for Quotation and Supplier Quotation in between.)
Step 3: Quality Inspection. The lab tests the arriving lot. If inspection is required, the receipt can't be submitted until it's done.
Step 4: Purchase Receipt. The bales enter the warehouse. Actual Qty goes up, a Stock Ledger Entry is written, and each lot is recorded as a Batch.
Step 5: Purchase Invoice and Payment. The supplier's bill posts to the GL (Creditors up), and the Payment Entry settles it.
Automatic Reorder
On each Item you can set a reorder level and reorder quantity per warehouse. Turn on automatic Material Requests in Stock Settings, and ERPNext raises an MR for every item that falls below its level, then emails users with the Purchase Manager role. For a mill that consumes cotton around the clock, this kept us from ever discovering an empty store on a Monday morning.
2. Cotton Lots as Batches, with a Quality Gate

Batches
Tick Has Batch No on the raw cotton Item, and every receipt must say which batch (lot) each row belongs to. We added custom fields on Batch for the fibre properties the mill cares about: micronaire, staple_length, trash_percent and moisture.
Those fields are what the Mixing Plan from Episode 6 fetches with fetch_from. The blend recipe always uses the lot's real, inspected numbers.
Quality Inspection
Enable quality inspection on the Item, and attach a Quality Inspection Template with the parameters and limits:
| Parameter | Type | Acceptance |
|---|---|---|
| Micronaire | Numeric | Minimum 3.5 / Maximum 4.9 |
| Moisture % | Numeric | Maximum 8.0 |
| Trash % | Numeric | Maximum 3.0 |
| Colour grade | Non-numeric | Must equal "Middling" |
Readings outside the range are Rejected automatically on save. You can also use formula-based criteria, or mark a row Manual Inspection to decide yourself. Accepted bales go to the Raw Cotton Store. Rejected ones go to a rejected warehouse and back to the supplier.
3. Warehouses, the Bin, and Projected Qty
We modelled the mill floor as a warehouse tree: Raw Cotton Store โ Blowroom (WIP) โ Finished Yarn โ Rejected. Stock moves between them with Stock Entries.
For every item in every warehouse, ERPNext keeps a Bin with running totals, so it never has to add up the whole ledger just to answer "how much do we have?". The most useful number is Projected Qty:
Projected Qty = Actual + Planned + Requested + Ordered โ Reserved โ Reserved for Production โ Reserved for Subcontracting โ Reserved for Production Plan
In plain words: what we have, plus what's coming, minus what's already promised. Reorder decisions should look at projected qty, not just actual.
From bench --site mill.localhost console:
frappe.db.get_value(
"Bin",
{"item_code": "RAW-COTTON-BR", "warehouse": "Raw Cotton Store - SML"},
["actual_qty", "ordered_qty", "reserved_qty", "projected_qty"],
as_dict=True,
)
# Stock of one lot (batch) in a warehouse
from erpnext.stock.doctype.batch.batch import get_batch_qty
get_batch_qty(batch_no="LOT-BR-0007", warehouse="Raw Cotton Store - SML")4. FIFO vs Moving Average

Cotton prices swing with every season, so how stock is valued matters for the mill's profit numbers. ERPNext supports two methods, set per Item (the default comes from Stock Settings). Here's the example from Frappe's own blog post:
Buy 10 units at $12, then 5 units at $15, then sell 12.
- FIFO (First In, First Out): The oldest stock leaves first. The 12 sold are 10 ร $12 plus 2 ร $15. What's left: 3 ร $15 = $45.
- Moving Average: Every receipt re-blends the rate: (10 ร 12 + 5 ร 15) รท 15 = $13. What's left: 3 ร $13 = $39.
| FIFO | Moving Average | |
|---|---|---|
| Stock value when prices rise | Higher (recent, pricier stock remains) | Lower (blended) |
| Matches physical flow | Yes, for perishable or lot-based goods | Not exactly |
| Negative stock allowed | No | Yes (value treated as zero until positive) |
| Simplicity | Tracks layers ("queues") | One rate per item |
One more thing the blog points out: back-dated entries force ERPNext to recalculate the valuation of every later transaction. On a busy mill with thousands of stock movements, that repost can take a while. It's a good reason to keep stock entries on time.
๐ Explain It Like You're 5
You collect marbles in a jar. When you run low, you tell Dad (Material Request), Dad orders more from the shop (Purchase Order), and before you drop them in the jar you check each one isn't cracked (Quality Inspection).
Every bag gets a sticker saying which shop it came from (Batch). And your little notebook always says how many marbles you have, how many are coming, and how many you promised your friend (Projected Qty)!
๐ฏ Debugging Cheat Sheet
| Symptom | Likely cause | Where to look |
|---|---|---|
| Can't submit Purchase Receipt | Quality Inspection required but missing | Item's inspection setting; create the QI |
| "Batch No is mandatory" | Item has Has Batch No on | Pick or create the lot's Batch |
| No automatic Material Requests | Reorder levels missing, or auto MR off | Item reorder table; Stock Settings |
| Stock balance looks wrong | Draft (unsubmitted) receipts or entries | Stock Ledger by voucher, docstatus |
| Valuation changed after an old entry | Back-dated entry triggered a repost | Repost Item Valuation list |
| "Insufficient stock" on a Stock Entry | Projected looks fine but actual is short | Bin actual_qty vs projected_qty |
| Mixing Plan fetches empty micronaire | Custom fields on Batch not filled | Batch form; Quality Inspection readings |
Key Takeaways for Interviews
- Procure to Pay: MR โ PO โ (QI) โ PR โ PI โ Payment. Each step moves a different quantity (requested, ordered, actual).
- Batches track lot-level properties, and custom fields on Batch let manufacturing use real quality data.
- Quality Inspection templates enforce acceptance limits at receipt, before bad material enters the store.
- Projected Qty = have + coming โ promised. Reorder on projected, not actual.
- FIFO vs Moving Average gives different values from the same transactions, and back-dated entries trigger reposting.
๐ Official Sources
Everything here is checked against Frappe's own documentation and blog:
- Material Request
- Purchase Order
- Purchase Receipt
- Quality Inspection
- Batch
- Auto creation of Material Request
- Projected Quantity
- Frappe blog: Inventory Valuation Method, FIFO vs Moving Average
Next episode, we go back inside the code: the document lifecycle, covering validate, before_submit, on_submit, on_cancel and friends, and exactly when each one runs.