forked from data.coop/membersystem
Compare commits
No commits in common. "768ef5a7d200ba2bf5fcf6a1c583b3ca4a1afc5d" and "d9de265de9acff49c21bdec0685acedad24aae12" have entirely different histories.
768ef5a7d2
...
d9de265de9
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build:
|
build:
|
||||||
|
@ -12,7 +11,8 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app/
|
- ./:/app/
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
|
||||||
|
@ -24,6 +24,13 @@ services:
|
||||||
- 5432:5432
|
- 5432:5432
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
# This healthcheck has a large number of retries, this is currently based on the number of
|
||||||
|
# retries necessary to get the database running in GitHub Actions.
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD-SHELL", "pg_isready -U postgres -d postgres" ]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 30
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|
|
@ -1,16 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Waiting for postgres..."
|
|
||||||
|
|
||||||
POSTGRES_PORT=${POSTGRES_PORT:-5432}
|
|
||||||
POSTGRES_HOST=${POSTGRES_HOST:-localhost}
|
|
||||||
|
|
||||||
while ! nc -z "$POSTGRES_HOST" "$POSTGRES_PORT"; do
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "PostgreSQL started"
|
|
||||||
|
|
||||||
# Only migrate, collectstatic and compilemessages if we are NOT in development
|
# Only migrate, collectstatic and compilemessages if we are NOT in development
|
||||||
if [ -z "$DEBUG" ]; then
|
if [ -z "$DEBUG" ]; then
|
||||||
python src/manage.py migrate;
|
python src/manage.py migrate;
|
||||||
|
|
|
@ -56,18 +56,3 @@ class PaymentAdmin(admin.ModelAdmin):
|
||||||
def order_id(self, instance: models.Payment) -> int:
|
def order_id(self, instance: models.Payment) -> int:
|
||||||
"""Return the ID of the order."""
|
"""Return the ID of the order."""
|
||||||
return instance.order.id
|
return instance.order.id
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Product)
|
|
||||||
class ProductAdmin(admin.ModelAdmin): # noqa: D101
|
|
||||||
list_display = ("name", "price", "vat")
|
|
||||||
|
|
||||||
|
|
||||||
class TransactionInline(admin.TabularInline): # noqa: D101
|
|
||||||
model = models.Transaction
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Account)
|
|
||||||
class AccountAdmin(admin.ModelAdmin): # noqa: D101
|
|
||||||
list_display = ("owner", "balance")
|
|
||||||
inlines = (TransactionInline,)
|
|
||||||
|
|
|
@ -7,7 +7,3 @@ class AccountingConfig(AppConfig):
|
||||||
"""Accounting app config."""
|
"""Accounting app config."""
|
||||||
|
|
||||||
name = "accounting"
|
name = "accounting"
|
||||||
|
|
||||||
def ready(self) -> None:
|
|
||||||
"""Implicitly connect a signal handlers decorated with @receiver."""
|
|
||||||
from . import signals # noqa: F401
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('accounting', '0005_remove_order_price_remove_order_price_currency_and_more'),
|
('accounting', '0005_remove_order_price_remove_order_price_currency_and_more'),
|
||||||
('membership', '0006_waitinglistentry_alter_membership_options'),
|
('membership', '0007_membershiptype_current_membershiptype_product'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
|
|
@ -95,11 +95,6 @@ class Order(CreatedModifiedAbstract):
|
||||||
"""Return the total VAT of the order."""
|
"""Return the total VAT of the order."""
|
||||||
return sum(order_product.vat for order_product in self.order_products)
|
return sum(order_product.vat for order_product in self.order_products)
|
||||||
|
|
||||||
@property
|
|
||||||
def total_with_vat(self) -> Money:
|
|
||||||
"""Return the TOTAL amount WITH VAT."""
|
|
||||||
return self.total + self.total_vat
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display_id(self) -> str:
|
def display_id(self) -> str:
|
||||||
"""Return an id for the order."""
|
"""Return an id for the order."""
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
"""Loaded with the AppConfig.ready() method."""
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.mail import send_mail
|
|
||||||
from django.db.models.signals import post_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from . import models
|
|
||||||
|
|
||||||
|
|
||||||
# method for updating
|
|
||||||
@receiver(post_save, sender=models.Payment)
|
|
||||||
def check_total_amount(sender: models.Payment, instance: models.Payment, **kwargs: dict) -> None: # noqa: ARG001
|
|
||||||
"""Check that we receive Payments with the correct amount."""
|
|
||||||
if instance.amount != instance.order.total_with_vat:
|
|
||||||
send_mail(
|
|
||||||
"Payment received: wrong amount",
|
|
||||||
f"Please check payment ID {instance.pk}",
|
|
||||||
settings.DEFAULT_FROM_EMAIL,
|
|
||||||
settings.ADMINS,
|
|
||||||
)
|
|
|
@ -1,55 +0,0 @@
|
||||||
# Generated by Django 5.1b1 on 2024-07-25 22:47
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('accounting', '0007_rename_user_order_member'),
|
|
||||||
('membership', '0006_waitinglistentry_alter_membership_options'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='activated',
|
|
||||||
field=models.BooleanField(default=False, help_text='Membership was activated.', verbose_name='activated'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='activated_on',
|
|
||||||
field=models.DateTimeField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='order',
|
|
||||||
field=models.ForeignKey(blank=True, help_text='The order filled in for paying this membership.', null=True, on_delete=django.db.models.deletion.PROTECT, to='accounting.order', verbose_name='order'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='revoked',
|
|
||||||
field=models.BooleanField(default=False, help_text='Membership has explicitly been revoked. Revoking a membership is not associated with regular expiration of the membership period.', verbose_name='revoked'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='revoked_on',
|
|
||||||
field=models.DateTimeField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membership',
|
|
||||||
name='revoked_reason',
|
|
||||||
field=models.TextField(blank=True),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membershiptype',
|
|
||||||
name='active',
|
|
||||||
field=models.BooleanField(default=True),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='membershiptype',
|
|
||||||
name='products',
|
|
||||||
field=models.ManyToManyField(to='accounting.product'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 5.0.7 on 2024-07-21 14:12
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounting', '0004_paymenttype_product_payment_external_transaction_id_and_more'),
|
||||||
|
('membership', '0006_waitinglistentry_alter_membership_options'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='membershiptype',
|
||||||
|
name='current',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='membershiptype',
|
||||||
|
name='product',
|
||||||
|
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='accounting.product'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -84,7 +84,7 @@ class Membership(CreatedModifiedAbstract):
|
||||||
|
|
||||||
def _current(self) -> Self:
|
def _current(self) -> Self:
|
||||||
"""Filter memberships for the current period."""
|
"""Filter memberships for the current period."""
|
||||||
return self.filter(activated=True, revoked=False, period__period__contains=timezone.now())
|
return self.filter(period__period__contains=timezone.now())
|
||||||
|
|
||||||
def current(self) -> "Membership | None":
|
def current(self) -> "Membership | None":
|
||||||
"""Get the current membership."""
|
"""Get the current membership."""
|
||||||
|
@ -116,31 +116,6 @@ class Membership(CreatedModifiedAbstract):
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
|
|
||||||
order = models.ForeignKey(
|
|
||||||
"accounting.Order",
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
verbose_name=_("order"),
|
|
||||||
help_text=_("The order filled in for paying this membership."),
|
|
||||||
on_delete=models.PROTECT,
|
|
||||||
)
|
|
||||||
|
|
||||||
activated = models.BooleanField(
|
|
||||||
default=False, verbose_name=_("activated"), help_text=_("Membership was activated.")
|
|
||||||
)
|
|
||||||
activated_on = models.DateTimeField(null=True, blank=True)
|
|
||||||
|
|
||||||
revoked = models.BooleanField(
|
|
||||||
default=False,
|
|
||||||
verbose_name=_("revoked"),
|
|
||||||
help_text=_(
|
|
||||||
"Membership has explicitly been revoked. Revoking a membership is not associated with regular expiration "
|
|
||||||
"of the membership period."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
revoked_reason = models.TextField(blank=True)
|
|
||||||
revoked_on = models.DateTimeField(null=True, blank=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("membership")
|
verbose_name = _("membership")
|
||||||
verbose_name_plural = _("memberships")
|
verbose_name_plural = _("memberships")
|
||||||
|
@ -158,9 +133,9 @@ class MembershipType(CreatedModifiedAbstract):
|
||||||
|
|
||||||
name = models.CharField(verbose_name=_("name"), max_length=64)
|
name = models.CharField(verbose_name=_("name"), max_length=64)
|
||||||
|
|
||||||
products = models.ManyToManyField("accounting.Product")
|
product = models.ForeignKey("accounting.Product", on_delete=models.PROTECT)
|
||||||
|
|
||||||
active = models.BooleanField(default=True)
|
current = models.BooleanField(default=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("membership type")
|
verbose_name = _("membership type")
|
||||||
|
|
Loading…
Reference in a new issue