fix: erpsetup dunning read rule, migration seed test, usage events 500 #137

Merged
sharang merged 3 commits from fix/erpsetup-dunning-and-small into main 2026-11-17 12:10:38 +00:00
Owner

Three small items from the 17.11. round. One commit each.

  1. feat(erpsetup): the registry user may read Dunning, read only.
    • Why: the Mahnung ladder (#134) reads Dunnings. ERPNext lets only the Accounts roles read them, and the registry's API user (platform-registry@) holds Sales User only. Prod pre-check: Dunning read was HTTP 403.
    • erpsetup now adds a level-0 read rule for Sales User on Dunning. It goes through frappe.core.page.permission_manager.permission_manager.add, which copies the standard rules into Custom DocPerm first, as the Role Permissions Manager UI does, so Accounts User/Manager keep theirs. A broader rule is cut back to read only.
    • Checked against Frappe v15 permissions.add_permission / setup_custom_perms.
    • The live ERP got the same rule by hand on 17.11. (Dunning read now 200), so the next erpsetup run reports it as exists.
    • The spec.go comment no longer claims Accounts User.
  2. test(migrations): intake reports keep their workspace (0030).
    • Why: TestSeed_canInsertAndQuery failed on main. It deleted a tenant that had intake reports, which 0030 forbids on purpose (owner decision Nr. 17).
    • The intake rows now live on a workspace of their own. The test checks that deleting it is refused and the rows stay; the cascade check keeps the other tenant.
    • CI doesn't run this package. It passes locally against Postgres (testcontainers/podman).
  3. fix(usage): a malformed tenant id lists no events on Postgres.
    • Why: pgx reports the invalid UUID from rows.Err, not from Query, so GET /v1/usage/events?tenant_id=not-a-uuid answered 500 on Postgres and 200 on the memory store. It now returns an empty list on both.
    • The new test fails without the fix (500, SQLSTATE 22P02) and passes with it.

Checks: go test ./... with Postgres, go vet, golangci-lint: clean.

🤖 Generated with Claude Code

Three small items from the 17.11. round. One commit each. 1. **`feat(erpsetup)`: the registry user may read Dunning, read only.** - Why: the Mahnung ladder (#134) reads Dunnings. ERPNext lets only the Accounts roles read them, and the registry's API user (platform-registry@) holds Sales User only. Prod pre-check: Dunning read was HTTP 403. - erpsetup now adds a level-0 read rule for Sales User on Dunning. It goes through `frappe.core.page.permission_manager.permission_manager.add`, which copies the standard rules into Custom DocPerm first, as the Role Permissions Manager UI does, so Accounts User/Manager keep theirs. A broader rule is cut back to read only. - Checked against Frappe v15 `permissions.add_permission` / `setup_custom_perms`. - The live ERP got the same rule by hand on 17.11. (Dunning read now 200), so the next `erpsetup` run reports it as `exists`. - The `spec.go` comment no longer claims Accounts User. 2. **`test(migrations)`: intake reports keep their workspace (0030).** - Why: `TestSeed_canInsertAndQuery` failed on main. It deleted a tenant that had intake reports, which 0030 forbids on purpose (owner decision Nr. 17). - The intake rows now live on a workspace of their own. The test checks that deleting it is refused and the rows stay; the cascade check keeps the other tenant. - CI doesn't run this package. It passes locally against Postgres (testcontainers/podman). 3. **`fix(usage)`: a malformed tenant id lists no events on Postgres.** - Why: pgx reports the invalid UUID from `rows.Err`, not from `Query`, so `GET /v1/usage/events?tenant_id=not-a-uuid` answered 500 on Postgres and 200 on the memory store. It now returns an empty list on both. - The new test fails without the fix (500, SQLSTATE 22P02) and passes with it. Checks: `go test ./...` with Postgres, `go vet`, golangci-lint: clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 3 commits 2026-11-17 11:55:42 +00:00
The late-payment ladder (#134) reads Dunnings, which ERPNext lets only the Accounts roles read. The registry's API user holds Sales User only. erpsetup now adds a level-0 read rule for Sales User on Dunning through Frappe's permission manager (which first copies the standard rules, as the Role Permissions Manager UI does) and cuts a broader rule back to read only. The spec.go comment no longer claims Accounts User. Live ERP: the same rule was added by hand on 17.11.; the next run reports it as existing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TestSeed_canInsertAndQuery deleted a tenant that had intake reports, which 0030 forbids on purpose (reports outlive their workspace). The intake rows now sit on a workspace of their own; the test checks that its delete is refused and the rows stay, and the cascade check keeps the other tenant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix(usage): malformed tenant id lists no events on postgres
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 8m27s
ci / image (pull_request) Skipped
37032e649e
pgx reports an invalid UUID from rows.Err, not from Query, so GET /v1/usage/events?tenant_id=not-a-uuid answered 500 on Postgres and 200 on the memory store. It now returns an empty list on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 9d6b5d48cf into main 2026-11-17 12:10:38 +00:00
Sign in to join this conversation.