Overdue invoices never reach the ladder on live ERPNext (webhook does not fire) #50

Closed
opened 2026-09-30 10:03:38 +00:00 by sharang · 0 comments
Owner

Problem

On the live ERPNext (v15), the sales_invoice.overdue webhook never fires. ERPNext marks invoices Overdue in the daily scheduler job erpnext.controllers.accounts_controller.update_invoice_status, which runs a bulk UPDATE ... SET status='Overdue' through the query builder. That write skips document events (on_update_after_submit), so the Frappe Webhook breakpilot-sales_invoice.overdue is never triggered.

As a result, on production the ladder path active → warning → restricted (14 d) → halted (30 d) for unpaid invoices does not happen. A customer who never pays stays active. On staging only the erpmock fired this event, so gate 04 did not catch it.

Found on 2026-09-30 during the SEPA trial run on prod (bp-smoketest).

Fix

Run it from Reconcile (every 15 min), which already walks every tenant that has an ErpCustomerID:

  • query Sales Invoice with customer = <ErpCustomerID>, docstatus = 1, outstanding_amount > 0 and due_date < today (fields name, due_date, outstanding_amount);
  • days_overdue = today (Europe/Berlin) − the oldest due_date;
  • apply the same rungs as the webhook handler (restrictAfterDays / haltAfterDays, never move backwards, ignore demo/halted/archived). Share the code with the EventInvoiceOverdue case;
  • write the audit entry with source reconcile:invoice_overdue:<invoice>.

Return to active is already handled by payment_entry.submit, and that event does fire. As a safety net, reconcile should also move warning/restricted back to active when no overdue invoice is left, e.g. after a payment reconciliation (Zahlungsabgleich), which fires no event.

Keep the webhook: it's harmless, and it would help if a later ERPNext version fires events on that update.

ERPNext permission (manual)

The API user platform-registry@breakpilot.com has the roles Sales User and Stock User. Neither Sales Invoice nor Subscription has a Sales User permission row, so reconcile already gets a 403 on Subscription today. Needed in Rollenberechtigungen-Manager, read only, level 0:

  • Abonnement (Subscription): Vertriebsbenutzer (Sales User)
  • Ausgangsrechnung (Sales Invoice): Vertriebsbenutzer (Sales User)

Document both in erpsetup output as a check (GET returns 403 → report "missing permission").

Tests

  • erpmock: GET /api/resource/Sales Invoice with filters
  • server: reconcile with one invoice 1 / 15 / 31 days overdue → warning / restricted / halted; paid → back to active
## Problem On the live ERPNext (v15), the `sales_invoice.overdue` webhook never fires. ERPNext marks invoices Overdue in the daily scheduler job `erpnext.controllers.accounts_controller.update_invoice_status`, which runs a bulk `UPDATE ... SET status='Overdue'` through the query builder. That write skips document events (`on_update_after_submit`), so the Frappe Webhook `breakpilot-sales_invoice.overdue` is never triggered. As a result, on production the ladder path **active → warning → restricted (14 d) → halted (30 d)** for unpaid invoices does not happen. A customer who never pays stays `active`. On staging only the erpmock fired this event, so gate 04 did not catch it. Found on 2026-09-30 during the SEPA trial run on prod (bp-smoketest). ## Fix Run it from `Reconcile` (every 15 min), which already walks every tenant that has an `ErpCustomerID`: - query `Sales Invoice` with `customer = <ErpCustomerID>`, `docstatus = 1`, `outstanding_amount > 0` and `due_date < today` (fields `name`, `due_date`, `outstanding_amount`); - `days_overdue` = today (Europe/Berlin) − the oldest `due_date`; - apply the same rungs as the webhook handler (`restrictAfterDays` / `haltAfterDays`, never move backwards, ignore demo/halted/archived). Share the code with the `EventInvoiceOverdue` case; - write the audit entry with source `reconcile:invoice_overdue:<invoice>`. Return to `active` is already handled by `payment_entry.submit`, and that event does fire. As a safety net, reconcile should also move `warning`/`restricted` back to `active` when no overdue invoice is left, e.g. after a payment reconciliation (Zahlungsabgleich), which fires no event. Keep the webhook: it's harmless, and it would help if a later ERPNext version fires events on that update. ## ERPNext permission (manual) The API user `platform-registry@breakpilot.com` has the roles Sales User and Stock User. Neither **Sales Invoice** nor **Subscription** has a Sales User permission row, so reconcile already gets a 403 on Subscription today. Needed in Rollenberechtigungen-Manager, **read only**, level 0: - Abonnement (Subscription): Vertriebsbenutzer (Sales User) - Ausgangsrechnung (Sales Invoice): Vertriebsbenutzer (Sales User) Document both in `erpsetup` output as a check (GET returns 403 → report "missing permission"). ## Tests - erpmock: `GET /api/resource/Sales Invoice` with filters - server: reconcile with one invoice 1 / 15 / 31 days overdue → warning / restricted / halted; paid → back to active
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: platform/tenant-registry#50