fix(erp): webhook templates and usage datetimes for the live ERPNext #49

Merged
sharang merged 3 commits from fix/erp-live-templates into main 2026-09-30 08:43:18 +00:00
Owner

Found in the first sales-order test on the live ERPNext (bp-smoketest, SAL-ORD-2026-00006). Staging never showed it, because the ERPNext mock doesn't render Jinja and accepts any date.

1. Sales order webhook never sent

Frappe renders webhook bodies with only {"doc": <document as dict>, "utils": frappe.utils} (webhook.get_context). Two consequences:

  • doc.items is the dict's items() method, not the order lines. The render failed with TypeError: 'builtin_function_or_method' object is not iterable, and nothing was sent (Webhook Request Log).
  • The overdue template used frappe.utils.date_diff, but frappe isn't in the context either. It would have failed on the first overdue invoice.

Fix: doc["items"] and utils.date_diff(utils.nowdate(), doc.due_date). Checked: all four templates rendered with Frappe's own render_template and get_context on the live ERPNext against the submitted order, and each result is valid JSON with the expected fields.

2. erpsetup updates outdated webhooks

Before, it only checked whether a webhook existed. Now it compares body and condition and updates in place (same name, URL and secret; the dry run reports would update). Tested with a fake Frappe: no duplicate, one write.

3. Usage Records have been failing since go-live

MariaDB rejects occurred_at = 2026-09-30T06:03:53Z (Error Log: Incorrect datetime value). The client now sends YYYY-MM-DD HH:MM:SS in Europe/Berlin (the ERPNext system time zone; time/tzdata embedded because the image is distroless). The outbox kept retrying, so nothing is lost; the records land once prod runs the fix.

Rollout

  • ERPNext side (webhooks): after the merge, run erpsetup again from the new image with the admin key. The dry run should show 2× would update. No prod registry change is needed for this.
  • Registry side (usage): prod promotion with today's hotfix round.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

Found in the first sales-order test on the **live** ERPNext (bp-smoketest, `SAL-ORD-2026-00006`). Staging never showed it, because the ERPNext mock doesn't render Jinja and accepts any date. ## 1. Sales order webhook never sent Frappe renders webhook bodies with only `{"doc": <document as dict>, "utils": frappe.utils}` (`webhook.get_context`). Two consequences: - `doc.items` is the dict's `items()` method, not the order lines. The render failed with `TypeError: 'builtin_function_or_method' object is not iterable`, and nothing was sent (Webhook Request Log). - The **overdue** template used `frappe.utils.date_diff`, but `frappe` isn't in the context either. It would have failed on the first overdue invoice. **Fix:** `doc["items"]` and `utils.date_diff(utils.nowdate(), doc.due_date)`. **Checked:** all four templates rendered with Frappe's own `render_template` and `get_context` on the live ERPNext against the submitted order, and each result is valid JSON with the expected fields. ## 2. `erpsetup` updates outdated webhooks Before, it only checked whether a webhook existed. Now it compares body and condition and updates in place (same name, URL and secret; the dry run reports `would update`). Tested with a fake Frappe: no duplicate, one write. ## 3. Usage Records have been failing since go-live MariaDB rejects `occurred_at = 2026-09-30T06:03:53Z` (Error Log: `Incorrect datetime value`). The client now sends `YYYY-MM-DD HH:MM:SS` in **Europe/Berlin** (the ERPNext system time zone; `time/tzdata` embedded because the image is distroless). The outbox kept retrying, so nothing is lost; the records land once prod runs the fix. ## Rollout - **ERPNext side (webhooks):** after the merge, run `erpsetup` again from the new image with the admin key. The dry run should show 2× `would update`. No prod registry change is needed for this. - **Registry side (usage):** prod promotion with today's hotfix round. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang added 1 commit 2026-09-30 07:40:26 +00:00
fix(erp): webhook templates and usage datetimes for the live ERPNext
ci / shared (pull_request) Successful in 15s
ci / test (pull_request) Failing after 14m49s
ci / image (pull_request) Skipped
0ba5f38122
Found in the first sales-order test on the live ERPNext (the staging mock
renders no Jinja and takes any date):
- Frappe renders webhook bodies with only {doc: <dict>, utils}: doc.items
  is the dict's items() method, so the sales-order webhook failed before
  it was sent; the overdue template used frappe.utils, which is not there.
  Now doc["items"] and utils.date_diff; checked by rendering all four
  on the live ERPNext against the submitted order.
- erpsetup updates an existing webhook whose body or condition differs
  (in place; dry run reports "would update").
- Usage Record occurred_at is sent as "YYYY-MM-DD HH:MM:SS" in
  Europe/Berlin; MariaDB refused RFC 3339, so usage records have not
  reached ERPNext since go-live (the outbox kept retrying).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang added 1 commit 2026-09-30 07:53:21 +00:00
feat(erpsetup): GoBD invoice number range RE-JJJJ-NNNN
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Failing after 15m23s
ci / image (pull_request) Skipped
12a43c0c4c
The GoBD Verfahrensdokumentation (§ 9) fixes the outgoing-invoice number
range at RE-JJJJ-NNNN, one range per calendar year for invoices and
returns. ERPNext shipped ACC-SINV-.YYYY.-. erpsetup now makes
RE-.YYYY.-.#### the only and the default Sales Invoice series (Property
Setters) and sets it back if it was changed; the dry run reports
"would update".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang added 1 commit 2026-09-30 08:18:55 +00:00
test(erpsetup): drop unused result (ineffassign)
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 23m42s
ci / image (pull_request) Skipped
fc7407ba42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang merged commit c33ae65342 into main 2026-09-30 08:43:18 +00:00
Sign in to join this conversation.