Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions users/models/bank_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
class BankTransaction(models.Model):
"""
Represents a incoming money transaction on the club's account.

Mapped to user instance if possible.
"""

# User this transaction was made by, or null if unknown
user = models.ForeignKey("CustomUser", on_delete=models.SET_NULL, null=True)

# Unique archival reference number that all transactions have
archival_reference = models.CharField(
blank=False,
Expand Down Expand Up @@ -69,14 +63,6 @@ class BankTransaction(models.Model):
help_text=_("Code"),
max_length=512,
)
has_been_used = models.BooleanField(
blank=False,
null=False,
default=False,
help_text=_(
"True, if this transaction has already been used to pay for service."
),
)

comment = models.TextField(
blank=True,
Expand Down
67 changes: 0 additions & 67 deletions users/models/custom_invoice.py

This file was deleted.

65 changes: 0 additions & 65 deletions users/models/member_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,11 @@ class MemberService(models.Model):
validators=[MinValueValidator(0)],
)

"""
Defines another service that this this service pays for. If this service is paid, the referenced
service is also marked as paid for days_per_payment after the payment date.

Can be used to make service chains so that if a more expensive
service is paid, the user can automatically receive cheaper ones.
"""
pays_also_service = models.ForeignKey(
"self", on_delete=models.SET_NULL, blank=True, null=True
)

# cost is used if not set
cost_min = models.IntegerField(
blank=True,
null=True,
verbose_name="Minimum payment",
validators=[MinValueValidator(0)],
)

# Can be left out if no maximum needed
cost_max = models.IntegerField(
blank=True,
null=True,
verbose_name="Maximum payment",
validators=[MinValueValidator(0)],
)

days_per_payment = models.IntegerField(
verbose_name="How many days of service member gets for a valid payment",
validators=[MinValueValidator(0)],
)

days_bonus_for_first = models.IntegerField(
default=0,
verbose_name="How many extra days of service member gets when paying for first time",
validators=[MinValueValidator(0)],
)

days_before_warning = models.IntegerField(
blank=True,
null=True,
verbose_name="How many days before payment expiration a warning message shall be sent",
validators=[MinValueValidator(0)],
)

days_maximum = models.IntegerField(
blank=True,
null=True,
verbose_name="How many days of service member can pay at maximum",
validators=[MinValueValidator(0)],
)

days_until_suspending = models.IntegerField(
blank=True,
null=True,
verbose_name="How many days service can be in payment pending state until it is moved to suspended state",
validators=[MinValueValidator(0)],
)

# This can be used to make "private" services that need to be added by admin to user.
hidden = models.BooleanField(
blank=False,
Expand All @@ -91,13 +37,6 @@ class MemberService(models.Model):
),
)

access_phone_number = models.CharField(
max_length=20,
blank=True,
null=True,
help_text=_("Phone number that can be used to use this memberservice"),
)

# True if users are allowed to subscribe and unsubscribe themselves with this service
self_subscribe = models.BooleanField(
blank=False,
Expand Down Expand Up @@ -134,7 +73,3 @@ def period_string(self):
if self.days_per_payment == 365:
return _("year")
return str(self.days_per_payment) + " " + str(_("days"))

# Returns a list of services that pay for this service
def paid_by_services(self):
return MemberService.objects.filter(pays_also_service=self)
7 changes: 1 addition & 6 deletions users/models/membership_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@ class MembershipApplication(models.Model):
verbose_name=_("Application creation date"),
help_text=_("Automatically set to now when membership application is created"),
)

last_modified = models.DateTimeField(
auto_now=True,
verbose_name=_("Last modified datetime"),
help_text=_("Last time this membership application was modified"),
)

agreement = models.BooleanField(
blank=False,
verbose_name=_("I agree to the terms presented"),
validators=[validate_agreement],
)

def age_days(self):
return (timezone.now() - self.created).days

Expand Down
71 changes: 0 additions & 71 deletions users/models/service_subscription.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
import datetime
from users.models.bank_transaction import BankTransaction


class ServiceSubscription(models.Model):
"""
Expand Down Expand Up @@ -40,38 +37,6 @@ class ServiceSubscription(models.Model):
default=SUSPENDED,
)

# The important paid until date. If this is not set, service has not been used yet or
# has been suspended.
paid_until = models.DateField(
blank=True,
null=True,
verbose_name=_("Paid until"),
help_text=_("The service will stay active until this date"),
)

# Points to the latest payment that caused paid_until to update
last_payment = models.ForeignKey(
BankTransaction, on_delete=models.SET_NULL, blank=True, null=True
)

# https://en.wikipedia.org/wiki/Creditor_Reference#:~:text=The%20Creditor%20Reference%20is%20an,reference%20will%20be%20entered%20correctly.
reference_number = models.CharField(
blank=True,
null=True,
unique=True,
verbose_name=_("Reference number for paying for this service subscription"),
help_text=_("Pay for this service with this reference number"),
max_length=25,
)

reminder_sent = models.DateField(
blank=True,
null=True,
help_text=_(
"Set date when a expiration reminder message has been sent to user. Reset to NULL when state changes."
),
)

SERVICE_STATE_COLORS = {
ACTIVE: "green",
OVERDUE: "yellow",
Expand All @@ -96,42 +61,6 @@ def statestring(self):
return ss[1]
return "(???)" # Should never happen

# Return number of days left until subscription ends
def days_left(self):
if self.state != ServiceSubscription.ACTIVE:
return 0

if not self.paid_until: # Should be, but just to be sure
return 0

daysleft = (self.paid_until - datetime.date.today()).days
if daysleft < 0:
daysleft = 0
return daysleft

# Return number of days subscription is overdue
def days_overdue(self):
if self.state != ServiceSubscription.OVERDUE:
return 0

if not self.paid_until:
return 0

days_overdue = -(self.paid_until - datetime.date.today()).days
if days_overdue < 0:
days_overdue = 0
return days_overdue

# Returns a list of user's servicesubscriptions that pay for this subscription
def paid_by_subscriptions(self):
paying_subs = []
paying_services = self.service.paid_by_services()
for service in paying_services:
subs = ServiceSubscription.objects.filter(user=self.user, service=service)
if subs:
paying_subs.append(subs[0].service.name)
return paying_subs

def __str__(self):
return _("Service %(servicename)s for %(username)s") % {
"servicename": self.service.name,
Expand Down