credits: only charge spend incurred while credits were available (#12 follow-up)
ci/woodpecker/push/woodpecker Pipeline was canceled

close_credit_cycles drew max(0, cycle_spend - allowance) capped by the
pack's current balance, so a pack bought mid-cycle was charged for spend
that predated it. Split the cycle at the first grant: allowance is consumed
first, then credits cover only the spend after they became available.
apply_cycle_draw takes the eligible figure; the ledger reason records it.
Correction rows for the six over-drawn clawback cycles are separate.
This commit is contained in:
inference-bot committed 2026-12-02 15:32:34 +00:00
1 parent 122824fd99
commit ca336a3115
3 files changed
+225 -12

No files matched your search

+3
View File
@@ -158,6 +158,9 @@ m._ensure_allowance_tables(conn) # adds anchor_day
conn.execute(
"INSERT INTO members (email, key_token, active, account_type, balance, credit_balance, anchor_day) "
"VALUES ('defer@example.com', '', 1, 'member', 15.0, 20.0, ?)", (anchor,))
conn.execute(
"INSERT INTO credit_ledger (email, delta, reason, reference, created_at) "
"VALUES ('defer@example.com', 20.0, 'pack (test)', 'test-pack', '2026-10-01 00:00:00')")
conn.commit()
conn.close()