diff --git a/app/urls.py b/app/urls.py index 7894808..1aa78ef 100644 --- a/app/urls.py +++ b/app/urls.py @@ -27,6 +27,7 @@ from core.views import ( base, linkgroups, notifications, + payouts, platforms, profit, wallets, @@ -241,6 +242,27 @@ urlpatterns = [ wallets.WalletDelete.as_view(), name="wallet_delete", ), + # Payouts + path( + "payouts//", + payouts.PayoutList.as_view(), + name="payouts", + ), + path( + "payouts//create/", + payouts.PayoutCreate.as_view(), + name="payout_create", + ), + path( + "payouts//update//", + payouts.PayoutUpdate.as_view(), + name="payout_update", + ), + path( + "payouts//delete//", + payouts.PayoutDelete.as_view(), + name="payout_delete", + ), # Link groups path( "links//", diff --git a/core/forms.py b/core/forms.py index 10ab1a3..e820b38 100644 --- a/core/forms.py +++ b/core/forms.py @@ -11,6 +11,7 @@ from .models import ( LinkGroup, NotificationSettings, OperatorWallets, + Payout, Platform, Provider, Requisition, @@ -332,3 +333,18 @@ class OperatorWalletsForm(RestrictedFormMixin, ModelForm): help_text=Meta.help_texts["payees"], required=False, ) + + +class PayoutForm(RestrictedFormMixin, ModelForm): + class Meta: + model = Payout + fields = ( + "wallet", + "amount", + "description", + ) + help_texts = { + "wallet": "The wallet the payment was sent to.", + "amount": "The amount of the payment.", + "description": "The description of the payment.", + } diff --git a/core/management/commands/scheduling.py b/core/management/commands/scheduling.py index 88f17b3..b5af9e1 100644 --- a/core/management/commands/scheduling.py +++ b/core/management/commands/scheduling.py @@ -27,7 +27,7 @@ async def withdrawal_job(group=None): groups = LinkGroup.objects.filter(enabled=True) for group in groups: checks = await money.check_all( - user=group.user, nordigen=NordigenClient, agora=AgoraClient + link_group=group, nordigen=NordigenClient, agora=AgoraClient ) print("CHECKS", checks) aggregators = Aggregator.objects.filter( diff --git a/core/migrations/0037_payout.py b/core/migrations/0037_payout.py new file mode 100644 index 0000000..03a430b --- /dev/null +++ b/core/migrations/0037_payout.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.7 on 2023-05-06 10:09 + +import uuid + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0036_requisition_owner_name'), + ] + + operations = [ + migrations.CreateModel( + name='Payout', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('amount', models.FloatField()), + ('description', models.CharField(blank=True, max_length=255, null=True)), + ('ts', models.DateTimeField(auto_now_add=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('wallet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.wallet')), + ], + ), + ] diff --git a/core/models.py b/core/models.py index 766b73d..99fda56 100644 --- a/core/models.py +++ b/core/models.py @@ -652,6 +652,19 @@ class OperatorWallets(models.Model): payees = models.ManyToManyField(Wallet, blank=True) +class Payout(models.Model): + """ + A profit payout. + """ + + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + user = models.ForeignKey(User, on_delete=models.CASCADE) + wallet = models.ForeignKey(Wallet, on_delete=models.CASCADE) + amount = models.FloatField() + description = models.CharField(max_length=255, null=True, blank=True) + ts = models.DateTimeField(auto_now_add=True) + + assets = { "XMR": "Monero", "BTC": "Bitcoin", diff --git a/core/templates/base.html b/core/templates/base.html index a0b5c3b..ea0df8e 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -220,14 +220,21 @@ Home {% if user.is_authenticated %} - - Profit - + +