Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Modelling Multi-Godown Stock for Indian Wholesalers: A Practical Inventory Data Model

If you build inventory software for wholesalers and distributors in India, you will meet the same request in almost every project: "We have two godowns and a shop counter, and the stock never matches." The usual first de

If you build inventory software for wholesalers and distributors in India, you will meet the same request in almost every project: "We have two godowns and a shop counter, and the stock never matches." The usual first design, a quantity column on the items table, breaks the moment stock lives in more than one place. Here is a data model that has held up well for multi-location stock, with notes on the India-specific details that tend to surface late.

Stop storing stock, start storing movements

The single most useful decision is to treat stock as a ledger. Instead of updating a number, record every movement and derive the balance.

CREATE TABLE locations (
  id BIGINT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,       -- 'Main godown', 'Shop counter'
  kind VARCHAR(20) NOT NULL         -- 'godown', 'counter', 'transit'
);

CREATE TABLE stock_movements (
  id BIGINT PRIMARY KEY,
  item_id BIGINT NOT NULL,
  location_id BIGINT NOT NULL,
  batch_id BIGINT NULL,
  qty DECIMAL(14,3) NOT NULL,       -- positive in, negative out
  reason VARCHAR(20) NOT NULL,      -- 'purchase', 'sale', 'transfer_out', 'transfer_in', 'adjustment', 'return'
  ref_type VARCHAR(30) NOT NULL,    -- 'invoice', 'grn', 'transfer', 'stock_count'
  ref_id BIGINT NOT NULL,
  created_by BIGINT NOT NULL,
  created_at TIMESTAMP NOT NULL
);

Balance at a location is SUM(qty) grouped by item, location and batch. Every number on a report can now be traced back to a document and a user, which is exactly what the owner asks for when a count goes wrong.

Transfers are two rows, not one

A transfer from godown to counter writes a negative row at the source and a positive row at the destination, linked by the same transfer document. If goods spend a day on a tempo, use a transit location in between. That way stock is never "missing", it is somewhere you can name.

Batches and expiry belong on the movement

FMCG, pharma and agri-input distributors need batch numbers, manufacturing and expiry dates. Keep them in a batches table and reference batch_id from each movement. Picking logic (first-expiry-first-out) then becomes a query over positive balances ordered by expiry, rather than special-case code in the billing screen.

Units: buy in cases, sell in pieces

Wholesalers often purchase in cartons and sell in boxes or pieces. Store every movement in the smallest unit and keep conversion factors per item. Convert only for display and printing. Mixing units inside the ledger is one of the most common causes of stock that looks right on screen and wrong on the floor.

Performance without giving up the ledger

Summing millions of movements on every screen load gets slow. Keep a stock_balances table updated in the same database transaction as each movement, and treat it as a cache that can be rebuilt from the ledger at any time. Run a nightly job that compares the two and alerts on any difference.

Physical counts as adjustments

When staff do a stock count, do not overwrite balances. Record the counted figure, calculate the difference and post it as an adjustment movement with the count sheet as the reference.

The India-specific bits to plan early

  • GST invoices reduce stock, but so do delivery challans for goods sent on approval. Model both.
  • HSN codes and tax rates belong to the item, but keep a history, because rates change.
  • Many teams still export to Tally. Design your document numbers and ledgers so that export is clean.

Getting the ledger right on day one saves months of reconciliation later. At Nexpro Softwares Private Limited in Bhubaneswar, we have been building business software since 2018, and this pattern sits under most of the stock systems we build. If you want to see how it translates into a full product for traders and distributors, here is our page on inventory management software development.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.