How to handle per-order credit control (not customer-level) in ERPNext?

Hi everyone,

I’m working on ordering system built on ERPNext, and I’m facing a limitation with how credit is handled.

Currently, ERPNext applies credit at the customer level, where the system checks:

  • Total outstanding invoices

  • Against the customer’s credit limit

However, in my use case, I need more granular control:

Requirements:

  1. Ability to use or not use credit per Sales Order / Invoice

  2. Support mixed scenarios:

    • Some orders on credit

    • Some orders prepaid (no credit usage)

  3. Track reserved credit at Sales Order level (before invoicing)

  4. Maintain a proper credit usage ledger / audit trail

  5. Support scheduled / recurring B2B orders, where future commitments should also block credit

Problem:
ERPNext:

  • Only tracks credit at invoice level (outstanding amount)

  • Does not support per-order credit toggling

  • Does not account for future/scheduled orders

What I’m considering:

  • Creating a custom Credit Ledger Doctype

  • Adding a use_credit flag on Sales Order / Invoice

  • Reserving credit at order stage

  • Releasing/adjusting on invoice/payment

Questions:

  1. Has anyone implemented per-order credit control in ERPNext?

  2. Is there a recommended way to handle credit reservation before invoicing?

  3. Would extending the existing credit limit logic be better than building a custom ledger?

  4. Any best practices for handling hybrid (credit + prepaid) flows?

Would really appreciate guidance or references if someone has solved a similar B2B use case.

Thanks!