Skip to content

Refactor mail sending and improve invoice/payment admin UX#34

Merged
nspo merged 2 commits intomasterfrom
feature/quick_invoice
May 6, 2026
Merged

Refactor mail sending and improve invoice/payment admin UX#34
nspo merged 2 commits intomasterfrom
feature/quick_invoice

Conversation

@nspo
Copy link
Copy Markdown
Owner

@nspo nspo commented May 5, 2026

view_helpers:

  • Add EmailConnectionWrapper: wraps Django mail connection to enable unification of mail sending with create_invoices later.
  • Extract HTML mail generation as helper functions
  • Refactor send_invoice_mails() and send_reminder_mails() to use the wrapper; eliminate nested try/except in favor of bool checks
  • send_invoice_mails() now requires users_autolocked and rolls back autolocks on mail failure or connection error
  • Extract create_invoices() from InvoiceCreateView; tracks and reports auto-unlocks
  • send_reminder_mails() skips users with balance >= 0, reports skipped count
  • Set context["subject"] in all mail-sending paths and debug views

views / forms:

  • PaymentForm: restrict user dropdown to self-paying users; block others on submit
  • InvoiceCreateView: pre-select user via ?user= query param (get_initial)

UI:

  • Invoice creation: Show filter box for user names (kind of a hack)
  • User detail: "Create invoice" button (self-paying users only), payment reminder button (balance < 0 only), mail preview footer buttons
  • Payment detail: always show "Generate invoice for user" button
  • Invoice detail: mail preview footer button

view_helpers:
- Add EmailConnectionWrapper: wraps Django mail connection to enable
  unification of mail sending with create_invoices later.
- Extract HTML mail generation as helper functions
- Refactor send_invoice_mails() and send_reminder_mails() to use the wrapper;
  eliminate nested try/except in favor of bool checks
- send_invoice_mails() now requires users_autolocked and rolls back autolocks
  on mail failure or connection error
- Extract create_invoices() from InvoiceCreateView; tracks and reports
  auto-unlocks
- send_reminder_mails() skips users with balance >= 0, reports skipped count
- Set context["subject"] in all mail-sending paths and debug views

views / forms:
- PaymentForm: restrict user dropdown to self-paying users; block others on submit
- InvoiceCreateView: pre-select user via ?user=<pk> query param (get_initial)

UI:
- Invoice creation: Show filter box for user names (kind of a hack)
- User detail: "Create invoice" button (self-paying users only),
  payment reminder button (balance < 0 only), mail preview footer buttons
- Payment detail: always show "Generate invoice for user" button
- Invoice detail: mail preview footer button
@nspo nspo requested a review from jallmenroeder May 5, 2026 22:01
…ionWrapper in standalone views

Single connection for all mails per call; invoices only persist if mail succeeds.
InvoiceResendView and PaymentReminderSendView now use EmailConnectionWrapper directly.
@nspo nspo force-pushed the feature/quick_invoice branch from db07ac5 to aea2c88 Compare May 6, 2026 09:14
@nspo
Copy link
Copy Markdown
Owner Author

nspo commented May 6, 2026

I think I'll commit a sin here and merge this before independent review... Need to have this go live quickly. I let Claude "review" it and checked the potential issues, which IMO are fine:

● Review of feature/quick_invoice

Four potential issues were identified and evaluated:

  1. generate_email_invoice exception orphans invoice — Dismissed: template rendering failures are not a realistic concern with stable templates.
  2. Dependant notification failures bleed into the invoice-abort threshold — Dismissed: intended behavior.
  3. send_messages returning 0 silently treated as success — Dismissed: assumed fine in practice.
  4. continue after invoice delete skips auto-unlock — Dismissed: correct behavior since no invoice was issued, so no state change should occur.

Conclusion: no changes needed, branch is good to merge.

@nspo nspo merged commit 5b84909 into master May 6, 2026
2 checks passed
@nspo nspo deleted the feature/quick_invoice branch May 6, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant