Skip to content

Tutorial: Billing → Sales flow → Xero

Narrative scenario for developers: what fires when money is recorded against services and how that relates to Application, Billing, Sales Invoice, and Xero code paths.

DocType / areaRole in this scenario
ApplicationCustomer incorporation / service context; linked from Billing via business rules
BillingCustom billing record; after_inserttasks.handle_billing (see Billing flow)
Sales InvoiceERPNext standard; Xero sync helpers may create/update SI lines
Xero (OAuth / tenant / invoice tables)Settings and sync state — see Xero integration and Xero tenant
api/xero.py / Xero APISales Invoice optionalEmail templatestasks.handle_billingBillingDesk userapi/xero.py / Xero APISales Invoice optionalEmail templatestasks.handle_billingBillingDesk userSI + Xero depend on product flow and sync jobsSave new Billing Paidafter_insertPayment success email
  1. leekimerp/hooks.pyBilling after_insert
  2. leekimerp/tasks.pyhandle_billing, send_payment_success_email
  3. leekimerp/api/xero.py — webhooks, invoice create/update
  4. DocType referenceBilling, Xero Invoice, etc.

After changing Billing, tasks, or Xero code, validate on staging:

StepCheck
1Create a Billing record that matches your test scenario; confirm handle_billing runs without traceback.
2Confirm expected email side effects (templates, recipients) per send_payment_success_email and related helpers.
3If Sales Invoice is created or updated, open the SI and verify tax, company, and customer links.
4For Xero: trigger or wait for sync; verify invoice appears in correct Xero tenant with matching totals (allow for rounding rules).
5Inspect Error Log for 15 minutes after test — no new recurring errors.
FailureExpected behavior
Xero API downERP should not corrupt SI; sync may retry or mark error — confirm actual implementation in api/xero.py and related DocTypes.
Duplicate webhookHandlers should be idempotent — no duplicate ledger lines (Xero integration).
Email misconfigurationBilling may succeed while mail fails — check Mandrill/email queue DocTypes.
  • Site name, Company, Billing name, Sales Invoice name (if any), Xero invoice id.
  • UTC timestamp of event; Stripe/Xero dashboard event ids if applicable.
  • Relevant Error Log traceback (redact PII).