mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-24 09:38:35 +02:00
Merge pull request #22
feat(api): add RecurringTransaction and InstallmentPlan endpoints
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
from apps.api.serializers.currencies import CurrencySerializer
|
from apps.api.serializers.currencies import CurrencySerializer
|
||||||
from apps.accounts.models import AccountGroup, Account
|
from apps.accounts.models import AccountGroup, Account
|
||||||
@@ -6,6 +7,8 @@ from apps.currencies.models import Currency
|
|||||||
|
|
||||||
|
|
||||||
class AccountGroupSerializer(serializers.ModelSerializer):
|
class AccountGroupSerializer(serializers.ModelSerializer):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AccountGroup
|
model = AccountGroup
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@@ -31,6 +34,8 @@ class AccountSerializer(serializers.ModelSerializer):
|
|||||||
allow_null=True,
|
allow_null=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Account
|
model = Account
|
||||||
fields = [
|
fields = [
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
from apps.currencies.models import Currency, ExchangeRate
|
from apps.currencies.models import Currency, ExchangeRate
|
||||||
|
|
||||||
|
|
||||||
class CurrencySerializer(serializers.ModelSerializer):
|
class CurrencySerializer(serializers.ModelSerializer):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Currency
|
model = Currency
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@@ -24,6 +28,8 @@ class ExchangeRateSerializer(serializers.ModelSerializer):
|
|||||||
queryset=Currency.objects.all(), source="to_currency", write_only=True
|
queryset=Currency.objects.all(), source="to_currency", write_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ExchangeRate
|
model = ExchangeRate
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
from apps.dca.models import DCAEntry, DCAStrategy
|
from apps.dca.models import DCAEntry, DCAStrategy
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +18,8 @@ class DCAEntrySerializer(serializers.ModelSerializer):
|
|||||||
max_digits=42, decimal_places=30, read_only=True
|
max_digits=42, decimal_places=30, read_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DCAEntry
|
model = DCAEntry
|
||||||
fields = [
|
fields = [
|
||||||
@@ -57,6 +61,8 @@ class DCAStrategySerializer(serializers.ModelSerializer):
|
|||||||
max_digits=42, decimal_places=30, read_only=True
|
max_digits=42, decimal_places=30, read_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DCAStrategy
|
model = DCAStrategy
|
||||||
fields = [
|
fields = [
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from apps.transactions.models import (
|
|||||||
TransactionTag,
|
TransactionTag,
|
||||||
InstallmentPlan,
|
InstallmentPlan,
|
||||||
TransactionEntity,
|
TransactionEntity,
|
||||||
|
RecurringTransaction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -47,11 +48,77 @@ class TransactionEntitySerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class InstallmentPlanSerializer(serializers.ModelSerializer):
|
class InstallmentPlanSerializer(serializers.ModelSerializer):
|
||||||
|
category = TransactionCategoryField(required=False)
|
||||||
|
tags = TransactionTagField(required=False)
|
||||||
|
entities = TransactionEntityField(required=False)
|
||||||
|
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InstallmentPlan
|
model = InstallmentPlan
|
||||||
fields = "__all__"
|
fields = [
|
||||||
|
"id",
|
||||||
|
"account",
|
||||||
|
"type",
|
||||||
|
"description",
|
||||||
|
"number_of_installments",
|
||||||
|
"installment_start",
|
||||||
|
"installment_total_number",
|
||||||
|
"start_date",
|
||||||
|
"reference_date",
|
||||||
|
"end_date",
|
||||||
|
"recurrence",
|
||||||
|
"installment_amount",
|
||||||
|
"category",
|
||||||
|
"tags",
|
||||||
|
"entities",
|
||||||
|
"notes",
|
||||||
|
]
|
||||||
|
read_only_fields = ["installment_total_number", "end_date"]
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
instance = super().create(validated_data)
|
||||||
|
instance.create_transactions()
|
||||||
|
return instance
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
instance = super().update(instance, validated_data)
|
||||||
|
instance.update_transactions()
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
class RecurringTransactionSerializer(serializers.ModelSerializer):
|
||||||
|
category = TransactionCategoryField(required=False)
|
||||||
|
tags = TransactionTagField(required=False)
|
||||||
|
entities = TransactionEntityField(required=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = RecurringTransaction
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"is_paused",
|
||||||
|
"account",
|
||||||
|
"type",
|
||||||
|
"amount",
|
||||||
|
"description",
|
||||||
|
"category",
|
||||||
|
"tags",
|
||||||
|
"entities",
|
||||||
|
"notes",
|
||||||
|
"reference_date",
|
||||||
|
"start_date",
|
||||||
|
"end_date",
|
||||||
|
"recurrence_type",
|
||||||
|
"recurrence_interval",
|
||||||
|
"last_generated_date",
|
||||||
|
"last_generated_reference_date",
|
||||||
|
]
|
||||||
|
read_only_fields = ["last_generated_date", "last_generated_reference_date"]
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
instance = super().create(validated_data)
|
||||||
|
instance.create_upcoming_transactions()
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class TransactionSerializer(serializers.ModelSerializer):
|
class TransactionSerializer(serializers.ModelSerializer):
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ router.register(r"categories", views.TransactionCategoryViewSet)
|
|||||||
router.register(r"tags", views.TransactionTagViewSet)
|
router.register(r"tags", views.TransactionTagViewSet)
|
||||||
router.register(r"entities", views.TransactionEntityViewSet)
|
router.register(r"entities", views.TransactionEntityViewSet)
|
||||||
router.register(r"installment-plans", views.InstallmentPlanViewSet)
|
router.register(r"installment-plans", views.InstallmentPlanViewSet)
|
||||||
|
router.register(r"recurring-transactions", views.RecurringTransactionViewSet)
|
||||||
router.register(r"account-groups", views.AccountGroupViewSet)
|
router.register(r"account-groups", views.AccountGroupViewSet)
|
||||||
router.register(r"accounts", views.AccountViewSet)
|
router.register(r"accounts", views.AccountViewSet)
|
||||||
router.register(r"currencies", views.CurrencyViewSet)
|
router.register(r"currencies", views.CurrencyViewSet)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from rest_framework import permissions, viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from apps.api.serializers import (
|
from apps.api.serializers import (
|
||||||
TransactionSerializer,
|
TransactionSerializer,
|
||||||
@@ -6,6 +6,7 @@ from apps.api.serializers import (
|
|||||||
TransactionTagSerializer,
|
TransactionTagSerializer,
|
||||||
InstallmentPlanSerializer,
|
InstallmentPlanSerializer,
|
||||||
TransactionEntitySerializer,
|
TransactionEntitySerializer,
|
||||||
|
RecurringTransactionSerializer,
|
||||||
)
|
)
|
||||||
from apps.transactions.models import (
|
from apps.transactions.models import (
|
||||||
Transaction,
|
Transaction,
|
||||||
@@ -13,6 +14,7 @@ from apps.transactions.models import (
|
|||||||
TransactionTag,
|
TransactionTag,
|
||||||
InstallmentPlan,
|
InstallmentPlan,
|
||||||
TransactionEntity,
|
TransactionEntity,
|
||||||
|
RecurringTransaction,
|
||||||
)
|
)
|
||||||
from apps.rules.signals import transaction_updated, transaction_created
|
from apps.rules.signals import transaction_updated, transaction_created
|
||||||
|
|
||||||
@@ -53,10 +55,7 @@ class InstallmentPlanViewSet(viewsets.ModelViewSet):
|
|||||||
queryset = InstallmentPlan.objects.all()
|
queryset = InstallmentPlan.objects.all()
|
||||||
serializer_class = InstallmentPlanSerializer
|
serializer_class = InstallmentPlanSerializer
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
instance = serializer.save()
|
|
||||||
instance.create_transactions()
|
|
||||||
|
|
||||||
def perform_update(self, serializer):
|
class RecurringTransactionViewSet(viewsets.ModelViewSet):
|
||||||
instance = serializer.save()
|
queryset = RecurringTransaction.objects.all()
|
||||||
instance.create_transactions()
|
serializer_class = RecurringTransactionSerializer
|
||||||
|
|||||||
Reference in New Issue
Block a user