Changes to payment models #32

Merged
valberg merged 35 commits from benjaoming/membersystem:payment-updates into main 2024-08-03 17:55:33 +00:00
3 changed files with 18 additions and 30 deletions
Showing only changes of commit 17e5f969af - Show all commits

View file

@ -1,4 +1,4 @@
.PHONY: run pre_commit_install pre_commit_run_all makemigrations migrate createsuperuser shell manage_command build requirements
.PHONY: run makemigrations migrate createsuperuser shell manage_command build requirements
DOCKER_COMPOSE = COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose
DOCKER_RUN = ${DOCKER_COMPOSE} run -u `id -u`
MANAGE_EXEC = python /app/src/manage.py
@ -7,12 +7,6 @@ MANAGE_COMMAND = ${DOCKER_RUN} app ${MANAGE_EXEC}
run:
${DOCKER_COMPOSE} up
pre_commit_install:
venv/bin/pre-commit install
pre_commit_run_all:
venv/bin/pre-commit run --all-files
makemigrations:
${MANAGE_COMMAND} makemigrations ${ARGS}

View file

@ -98,13 +98,3 @@ hatch-pip-compile
# Update requirements/requirements-dev.txt:
hatch-pip-compile dev
```
#### Updating requirements
If you want to update the requirements, you can run the following command:
```bash
hatch run requirements
```
This uses [hatch-pip-compile](https://juftin.com/hatch-pip-compile/) to update the requirements.

View file

@ -15,23 +15,27 @@ from django.db.models import QuerySet
from django.http import HttpRequest
from django.http import HttpResponse
from . import models
from .models import Member
from .models import Membership
from .models import MembershipType
from .models import SubscriptionPeriod
from .models import WaitingListEntry
# Do not use existing user admin
admin.site.unregister(User)
@admin.register(models.Membership)
@admin.register(Membership)
class MembershipAdmin(admin.ModelAdmin):
"""Admin for Membership model."""
@admin.register(models.MembershipType)
@admin.register(MembershipType)
class MembershipTypeAdmin(admin.ModelAdmin):
"""Admin for MembershipType model."""
@admin.register(models.SubscriptionPeriod)
@admin.register(SubscriptionPeriod)
class SubscriptionPeriodAdmin(admin.ModelAdmin):
"""Admin for SubscriptionPeriod model."""
@ -39,10 +43,10 @@ class SubscriptionPeriodAdmin(admin.ModelAdmin):
class MembershipInlineAdmin(admin.TabularInline):
"""Inline admin."""
model = models.Membership
model = Membership
def decorate_ensure_membership_type_exists(membership_type: models.MembershipType, label: str) -> Callable:
def decorate_ensure_membership_type_exists(membership_type: MembershipType, label: str) -> Callable:
"""Generate an admin action for given membership type and label."""
@admin.action(description=label)
@ -56,7 +60,7 @@ def decorate_ensure_membership_type_exists(membership_type: models.MembershipTyp
def ensure_membership_type_exists(
request: HttpRequest,
queryset: QuerySet,
membership_type: models.MembershipType,
membership_type: MembershipType,
) -> HttpResponse:
"""Inner function that ensures that a membership exists for a given queryset of Member objects."""
for member in queryset:
@ -71,10 +75,10 @@ def ensure_membership_type_exists(
for product in membership_type.products.all():
OrderProduct.objects.create(order=order, product=product, price=product.price, vat=product.vat)
# Create the Membership
models.Membership.objects.create(
Membership.objects.create(
membership_type=membership_type,
user=member,
period=models.SubscriptionPeriod.objects.current(),
period=SubscriptionPeriod.objects.current(),
order=order,
)
@ -82,7 +86,7 @@ def ensure_membership_type_exists(
messages.success(request, f"{member} has ordered a '{membership_type}' (unpaid)")
@admin.register(models.Member)
@admin.register(Member)
class MemberAdmin(UserAdmin):
"""Member admin is actually an admin for User objects."""
@ -91,12 +95,12 @@ class MemberAdmin(UserAdmin):
def get_actions(self, request: HttpRequest) -> dict:
"""Populate actions with dynamic data (MembershipType)."""
current_period = models.SubscriptionPeriod.objects.current()
current_period = SubscriptionPeriod.objects.current()
super_dict = super().get_actions(request)
if current_period:
for i, mtype in enumerate(models.MembershipType.objects.filter(active=True)):
for i, mtype in enumerate(MembershipType.objects.filter(active=True)):
action_label = f"Ensure membership {mtype.name}, {current_period.period}, {mtype.total_including_vat}"
action_func = decorate_ensure_membership_type_exists(mtype, action_label)
# Django ModelAdmin uses the non-unique __name__ property, so we need to suffix it to make it unique
@ -106,6 +110,6 @@ class MemberAdmin(UserAdmin):
return super_dict
@admin.register(models.WaitingListEntry)
@admin.register(WaitingListEntry)
class WaitingListEntryAdmin(admin.ModelAdmin):
"""Admin for WaitingList model."""