Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 36 ยท Projects and Practice

Project: An Order-to-Cash Simulator

Build a small ERP-style order-to-cash simulator in Python: customers, stock, credit check, orders, shipments, invoices and payments, with ledger postings and reconciliation tests.

In this project you build a miniature ERP core in Python and run a complete order-to-cash cycle through it: a customer order, a credit check, a stock reservation, a shipment, an invoice and finally a payment. Along the way you will meet the same ideas real systems implement: master data, document flow, status transitions, double-entry postings and reconciliation.

It is a stand-in, not any vendor's product: real ERP systems are far larger, and the code here is only meant to teach the concepts. Everything runs in your browser on this page.

The plan

The flow we model

Order Customer, items, credit check.
Delivery Reduce stock, record cost.
Invoice Receivable and revenue posted.
Payment Cash in, receivable cleared.

Each step changes documents, stock and the ledger.

1 / 2

Step 1: Master data and stock

Start with the objects the process needs: customers (with credit limits), products (with price and cost) and stock.

Python Step 1: master data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 2: A ledger with double-entry postings

Accounting is the backbone of every ERP: each business event posts balanced entries (debits equal credits) to ledger accounts. We use five accounts: cash, accounts receivable, inventory, revenue and cost of goods sold (COGS).

Python Step 2: a tiny ledger

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 3: The order-to-cash engine

Now combine the pieces. Each method enforces a rule and posts to the ledger:

  • create_order checks the credit limit (existing balance plus the new order) and stock availability.
  • ship reduces stock, posts COGS debit / inventory credit.
  • invoice posts receivable debit / revenue credit and increases the customer balance.
  • receive_payment posts cash debit / receivable credit and reduces the customer balance.
Python Step 3: the full cycle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check the story the numbers tell: the sale of 3 pumps and 10 valves is worth 1,800, costing 1,100, for a profit of 700. Stock fell by the shipped quantities, receivable went up on invoicing and back to zero on payment, and cash moved by the 1,800 received. Cash shows -2,100 because the opening entry paid for the 3,900 of starting stock from cash; after the 1,800 payment the balance is still 2,100 below zero.

Step 4: Reconciliation checks

Real ERP projects verify that sub-ledgers (stock, customer balances) agree with the general ledger. Add automatic checks to the engine and run them after the business events. Copy the engine above into the editor below (it is repeated here in compact form so this example runs on its own).

Python Step 4: reconciliation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If a check fails after you modify the code, you have found exactly the kind of inconsistency that migration and integration testing look for (data migration and cleansing).

Extensions to try

  1. Partial shipments: allow shipping part of an order and keep it open.
  2. Credit notes and returns: reverse the invoice and put goods back into stock.
  3. Sales tax: post tax payable separately from revenue.
  4. Payment terms: add due dates and an overdue report.
  5. Audit trail: record who changed which document and when.
  6. Approval workflow: require approval above a value threshold.
  7. Integration: accept orders as JSON messages with an idempotency key (integration patterns and APIs).
  8. KPIs: compute DSO and gross margin from the ledger (KPIs, dashboards and business reports).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which posting happens when goods are shipped in our simulator?

    Shipping consumes stock: the cost of the goods moves from inventory to cost of goods sold.
  2. 2. Why does the ledger reject an unbalanced posting?

    Balanced postings keep the books consistent; an unbalanced entry signals a bug.
  3. 3. What does the reconciliation 'receivable ledger equals sum of customer balances' prove?

    Control accounts must match their sub-ledgers, otherwise some posting skipped a step.
  4. 4. Which control stops a large order from a risky customer?

    The credit check compares the existing balance plus the new order value with the limit.

Summary

  • Order to cash links order, delivery, invoice and payment with stock and ledger effects.
  • Double-entry postings must balance; each document posts a defined set of entries.
  • Business rules such as credit limits and stock checks belong at order creation.
  • Reconciliation between sub-ledgers and the general ledger finds errors early.
  • Extend the simulator to practise returns, taxes, approvals and KPIs.

Next: Project: Lead Scoring and Pipeline Tracker