At the spinning mill, an export order was a nervous thing. A buyer abroad would confirm 20 tonnes of 30s combed yarn, the bank would issue a Letter of Credit (LC), and from then on every date and every dollar had to match that LC exactly. Ship a day after the LC's latest shipment date, or invoice 6% over the amount when the LC allows 5%, and the bank simply refuses to pay.
Before ERPNext, the commercial team checked all of this by hand, with Excel and a highlighter. After ERPNext, the system refused to save a Sales Order that broke the LC's rules.
This episode covers both halves: how ERPNext Selling works as standard, and how we bolted on Export LC checks the safe way.

Keywords
- Quotation: A priced offer to a customer. Posts nothing to the ledgers.
- Sales Order (SO): The customer's confirmed order. Reserves stock and checks credit.
- Delivery Note (DN): Goods leaving the warehouse. Posts to the Stock Ledger.
- Sales Invoice (SI): The bill. Posts to the General Ledger.
- Payment Entry: Money received against the invoice.
- Price List / Item Price: Where default rates come from.
- Incoterm + Named Place: Who pays for shipping and insurance, and up to which point (FOB, CFR, CIF...).
- Letter of Credit (LC): A bank's promise to pay the exporter if the shipping documents match the LC's terms.
Character Mapping
- Quotation: The sales executive's offer letter.
- Sales Order: The signed contract, pinned on the commercial office board.
- Delivery Note: The gate pass on the truck.
- Sales Invoice: The commercial invoice sent to the buyer's bank.
- Export LC: The bank's rulebook clipped to the front of the contract file.
doc_eventshook: The strict commercial manager who checks the rulebook before anyone signs.
1. The Standard Flow, and What Each Step Writes
The official flow is Quotation β Sales Order β Delivery Note β Sales Invoice β Payment Entry. Each document is created from the previous one with the Create button, which maps items, rates, taxes and terms forward (we saw get_mapped_doc in Episode 3).
| Document | When you submit it | Ledger / quantity effect |
|---|---|---|
| Quotation | The offer is final | Nothing posted |
| Sales Order | The order is confirmed | Reserved Qty goes up; credit limit checked |
| Delivery Note | The goods ship | Stock Ledger Entry (stock down); Reserved Qty down |
| Sales Invoice | The customer is billed | GL Entry: Debtors up, Sales income up |
| Payment Entry | Money arrives | GL Entry: Bank up, Debtors down |
Two details trip people up:
- Submitting a Sales Order doesn't move stock. It only promises it (Reserved Qty). Stock physically leaves on the Delivery Note.
- A Sales Invoice can also be made directly from a Sales Order, skipping the Delivery Note, if your settings allow it.
Selling Settings: The Rules of the Road
In Selling Settings β Transaction, two checkboxes decide how strict the flow is:
- "Is Sales Order required to create Sales Invoice or Delivery Note?"
- "Is Delivery Note required to create Sales Invoice?"
For export we turned both on: no shipment without a contract, and no invoice without a shipment. Other useful options include "Maintain same rate throughout sales cycle" (so nobody quietly changes the price between order and invoice) and "Allow multiple Sales Orders against a customer's Purchase Order".
2. Quotation and Sales Order: Prices, Currency, Incoterms
Step 1: Rates come from a Price List. Each item's rate is fetched from the Item Price in the selected Price List. For export we kept a USD price list. When the order currency differs from the company currency, ERPNext stores an exchange rate on the document, so the accounts later post in both currencies.
Step 2: Record the Incoterm. Sales Orders have Incoterm and Named Place fields, e.g. FOB, Chattogram Port or CFR, Istanbul. That one field settles a lot of arguments about who pays for freight.
Step 3: Submit and watch the status. A submitted Sales Order moves through statuses like To Deliver and Bill β To Bill β Completed as Delivery Notes and Invoices are made against it. It can also be put On Hold or Closed.
Credit Limits

ERPNext looks for a credit limit in this order: the Customer's Credit & Overdue Limits table (one row per company), then the Customer Group, then the Company. Open Sales Orders count against the limit, and Sales Invoices are checked against outstanding receivables.
Two levers for exceptions:
- "Bypass credit limit check at sales order" on the Customer skips the check at the order stage only.
- The Credit Manager role (set in Accounts Settings β Credit Limits) can approve and submit a blocked transaction.
For LC-backed export orders, the bank carries the payment risk, so we set the bypass for those buyers. That's exactly the kind of decision you should talk through with the finance team, not make in code.
3. Developer Section: Adding Export LC Checks Without Touching Core
ERPNext has no built-in "Export LC" document. Here's how we added one entirely inside our custom app (mill_erp), so bench update never breaks it.

Piece 1: A Custom DocType, "Export LC"
Fields: lc_no, bank, customer, currency, lc_amount, tolerance_percent, expiry_date, latest_shipment_date. (Next episode shows exactly how to build a DocType like this.)
Piece 2: A Custom Field on Sales Order
A Link field export_lc β Export LC, added through Customize Form and exported to our app as a fixture, so it's created on every site where the app is installed. (Fixtures get their own episode later in the series.)
Piece 3: doc_events in hooks.py
Instead of editing ERPNext's sales_order.py, we subscribe to its events:
# mill_erp/hooks.py
doc_events = {
"Sales Order": {
"validate": "mill_erp.selling.export_lc.validate_sales_order_lc",
},
"Delivery Note": {
"before_submit": "mill_erp.selling.export_lc.validate_shipment_date",
},
}# mill_erp/selling/export_lc.py
import frappe
from frappe import _
from frappe.utils import flt, getdate
def validate_sales_order_lc(doc, method=None):
if not doc.get("export_lc"):
return
lc = frappe.get_cached_doc("Export LC", doc.export_lc)
if lc.customer != doc.customer:
frappe.throw(_("Export LC {0} belongs to {1}, not {2}.").format(lc.name, lc.customer, doc.customer))
if lc.currency != doc.currency:
frappe.throw(_("Order currency {0} must match LC currency {1}.").format(doc.currency, lc.currency))
if getdate(lc.expiry_date) < getdate(doc.transaction_date):
frappe.throw(_("Export LC {0} expired on {1}.").format(lc.name, lc.expiry_date))
# Every submitted order on this LC, plus this one, must fit inside amount + tolerance.
used = frappe.db.sql(
"""select coalesce(sum(grand_total), 0) from `tabSales Order`
where export_lc = %s and docstatus = 1 and name != %s""",
(doc.export_lc, doc.name),
)[0][0]
allowed = flt(lc.lc_amount) * (1 + flt(lc.tolerance_percent) / 100)
if flt(used) + flt(doc.grand_total) > allowed:
frappe.throw(_("Orders on LC {0} would total {1}, above the allowed {2}.").format(
lc.name, flt(used) + flt(doc.grand_total), allowed))
def validate_shipment_date(doc, method=None):
orders = {row.against_sales_order for row in doc.items if row.against_sales_order}
for so in orders:
lc_name = frappe.db.get_value("Sales Order", so, "export_lc")
if not lc_name:
continue
latest = frappe.db.get_value("Export LC", lc_name, "latest_shipment_date")
if latest and getdate(doc.posting_date) > getdate(latest):
frappe.throw(_("LC {0} allows shipment until {1}. This Delivery Note is dated {2}.").format(
lc_name, latest, doc.posting_date))Why this design works:
validateruns on every save of the Sales Order, so problems appear while the user is still typing, not at month end.before_submiton the Delivery Note is the last chance to stop a late shipment before stock leaves.- The Delivery Note finds its orders through
against_sales_order, the back-link ERPNext's mapper fills in. frappe.throwstops the save and shows the message. Nothing gets half-written.
π Explain It Like You're 5
You sell lemonade to the kid next door. First you say, "One cup is 10 taka" (Quotation). They say, "Yes, I'll take two!" (Sales Order). You hand them two cups (Delivery Note), give them a little bill (Sales Invoice), and they pay you (Payment Entry).
But their mom gave them a note: "Only 20 taka, and only before dinner." That note is the Letter of Credit, and you check it before you pour!
π― Debugging Cheat Sheet
| Symptom | Likely cause | Where to look |
|---|---|---|
| Can't create a Delivery Note without an order | "Sales Order required" is on in Selling Settings | Selling Settings β Transaction |
| Rate changed between order and invoice | "Maintain same rate" is off | Selling Settings β Pricing |
| Sales Order blocked by credit limit | Outstanding + open orders over the limit | Customer β Credit & Overdue Limits; Credit Manager role |
| Stock didn't go down after submitting the SO | Expected: only the Delivery Note moves stock | Stock Ledger, filtered by voucher |
| Wrong currency amounts on the invoice | Exchange rate on the source document | conversion_rate field on the SO |
| Custom validation never fires | Wrong dotted path or method name in doc_events | hooks.py, then bench restart |
| LC check blocks an amended order | The old cancelled order is still counted | Filter docstatus = 1 only, as above |
Key Takeaways for Interviews
- Quotation β SO β DN β SI β Payment: only the DN touches stock, and only the SI and Payment touch the GL.
- Selling Settings make the flow strict or loose: order required, delivery required, same rate.
- Credit limits come from Customer, then Group, then Company, with a per-customer SO bypass and a Credit Manager override.
- Customize with hooks, not edits: a custom DocType, a fixture custom field, and
doc_eventsgive you business rules that survive upgrades. - Pick the right event:
validatefor every save,before_submitas the final gate.
π Official Sources
Everything here is checked against Frappe's own documentation:
- Sales Order
- Quotation
- Delivery Note
- Selling Settings
- Credit Limit
- Projected Quantity (Reserved Qty)
- Hooks (doc_events)
Next episode, we build a DocType from scratch: the Mixing Plan, with a child table of cotton lots and a rule that the blend must add up to exactly 100%.