Skip to content

Commit

Permalink
generate SEPA XMLs according to num_months field, close #231
Browse files Browse the repository at this point in the history
  • Loading branch information
luto committed Feb 24, 2024
1 parent 2acebb3 commit 482d37f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions announce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import django.forms as forms
from django.db.models import Q

from members.models import get_active_members, ContactInfo, KindOfMembership
from members.models import get_active_members, members_due_for_bank_collection, KindOfMembership


def _announce_filter_collection(users):
users = users.filter(paymentinfo__bank_collection_allowed=True) \
.filter(paymentinfo__bank_collection_mode__id=4)
users = members_due_for_bank_collection(users)
for u in users:
debt = u.contactinfo.get_debt_for_month(date.today())
if debt == 0:
Expand Down
6 changes: 3 additions & 3 deletions members/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.conf import settings
from django.contrib import messages
import django.forms as forms
from members.models import members_due_for_bank_collection

from .models import BankCollectionMode, ContactInfo, KindOfMembership
from .models import Locker, MailinglistMail, MembershipFee, MembershipPeriod
Expand Down Expand Up @@ -97,8 +98,7 @@ def make_into_real_payments(modeladmin, request, queryset):
@admin.action(description="Generate SEPA XML for members (is active & has debt & allows monthly bank collection)")
@transaction.atomic()
def make_sepa_xml_for_members(modeladmin, request, queryset):
queryset = queryset.filter(paymentinfo__bank_collection_allowed=True)
queryset = queryset.filter(paymentinfo__bank_collection_mode__id=4)
queryset = members_due_for_bank_collection(queryset)
dt = datetime.now()
# active members only
queryset = queryset.filter(Q(membershipperiod__begin__lte=dt), Q(membershipperiod__end__isnull=True) | Q(membershipperiod__end__gte=dt))
Expand Down Expand Up @@ -215,7 +215,7 @@ def lookups(self, request, model_admin):
def queryset(self, request, qs):
if self.value():
if self.value() == "not_monthly":
qs = qs.exclude(paymentinfo__bank_collection_mode__pk=4)
qs = qs.exclude(paymentinfo__bank_collection_mode__num_month=1)
else:
qs = qs.filter(paymentinfo__bank_collection_mode__pk=int(self.value()))
return qs
Expand Down
17 changes: 17 additions & 0 deletions members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.encoding import smart_str, force_str
from django.db.models import Q, F, Value
import smtplib
from django.core.mail import send_mail
# for iButton regex
Expand Down Expand Up @@ -322,6 +323,22 @@ def get_active_and_future_members():
.distinct()


def members_due_for_bank_collection(users=None):
if users is None:
users = get_active_members()

current_month = datetime.now().month

users = users.filter(paymentinfo__bank_collection_allowed=True)
users = users.filter(paymentinfo__bank_collection_mode__num_month__gt=0)
users = users.annotate(
is_collectable=Value(current_month - 1) % F("paymentinfo__bank_collection_mode__num_month"),
)
users = users.filter(is_collectable=0)

return users


def get_active_membership_months_until(date):
periods = MembershipPeriod.objects.filter(Q(begin__lte=date))
res = {}
Expand Down

0 comments on commit 482d37f

Please sign in to comment.