Keep dunning a bounced debit out of the direct-debit track

Once the direct debit bounced and the board sent the Rücklastschrift reminder,
the claim is expected as a transfer by the deadline that letter states. Three
places still treated it as a claim the mandate covers, and the housekeeper's was
the one the board kept running into: after the reminder's deadline lapsed, the
finding went back to "Lastschrift überfällig -- Einzug prüfen, eine postalische
Mahnung ist hier nicht vorgesehen", for a claim that had just been dunned.

The rule now asks whether the claim was dunned before treating it as one for the
direct debit. If it was, it continues in the ordinary dunning sequence: the
running deadline shows as the usual "Frist läuft noch" note, and once that has
passed the next dunning level comes due. The SEPA-specific pending-reminder
detour that used to cover the deadline window is gone with it -- the ordinary
path reports the same thing.

The SEPA run now skips a dunned claim as well, instead of quietly collecting the
money the letter asked the member to transfer (which can bounce a second time,
with a second fee). The skip is reported like the incomplete mandates are, so
nothing disappears from the run without saying why; the dialog's wording is no
longer specific to mandates.

And a dunning mail asks for a transfer even from a member with an active
mandate. The shipped template spells the bank details out, but the ready-made
{{payment.instructions}} paragraph, offered by the template editor for exactly
this mail, told them "wir ziehen den Betrag ein, du musst nichts weiter tun" --
in the letter demanding payment.

Reverting the sent reminder is what puts the claim back into the direct-debit
run; the read of "dunned" is a sent reminder, not a draft.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marcel Peterkau
2026-09-05 00:16:26 +02:00
co-authored by Claude Opus 5
parent 31c1646571
commit f80b17c443
11 changed files with 218 additions and 87 deletions
+42
View File
@@ -63,6 +63,48 @@ def test_pending_debits_select_due_open_balance(tmp_path):
assert debits[0].claim_ids == ("due",)
def test_a_dunned_claim_is_not_collected_again(tmp_path):
"""The dunning letter asked the member to transfer the money -- pulling it by
direct debit anyway would contradict it (and can bounce a second time)."""
repository, member = _repository(tmp_path)
draft = repository.create_reminder_draft(
member.member_id,
"due",
level=1,
name="Rücklastschrift",
payment_deadline_days=14,
items=[{"description": "Rücklastschriftgebühr", "amount": "5.00"}],
)
# A draft alone is not a dunning: nothing has gone out yet.
debits, warnings = pending_direct_debits(repository, due_until=date(2026, 12, 31))
assert [debit.claim_ids for debit in debits] == [("due",)]
assert warnings == []
repository.mark_reminder_sent(member.member_id, "due", draft["reminder_id"])
debits, warnings = pending_direct_debits(repository, due_until=date(2026, 12, 31))
# Nothing else is due in the window, so the member drops out of the run entirely
# -- and says why instead of vanishing silently.
assert debits == []
assert warnings == ["C3-42: „Mitgliedsbeitrag 2026“ wurde bereits gemahnt "
"Zahlung per Überweisung erwartet, kein erneuter Einzug."]
def test_a_dunned_claim_does_not_hold_back_the_members_other_claims(tmp_path):
repository, member = _repository(tmp_path)
draft = repository.create_reminder_draft(
member.member_id, "due", level=1, name="Rücklastschrift", payment_deadline_days=14
)
repository.mark_reminder_sent(member.member_id, "due", draft["reminder_id"])
debits, warnings = pending_direct_debits(repository, due_until=date(2027, 12, 31))
assert [debit.claim_ids for debit in debits] == [("future",)]
assert debits[0].amount == Decimal("150.00")
assert len(warnings) == 1
def test_pending_debits_follow_members_monthly_payment_frequency(tmp_path):
repository, member = _repository(tmp_path)
member.accepted_at = "2025-01-01"