mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-10 14:52:42 +02:00
feat(api): add RecurringTransaction and InstallmentPlan endpoints
This commit is contained in:
@@ -19,6 +19,7 @@ from apps.transactions.models import (
|
|||||||
TransactionTag,
|
TransactionTag,
|
||||||
InstallmentPlan,
|
InstallmentPlan,
|
||||||
TransactionEntity,
|
TransactionEntity,
|
||||||
|
RecurringTransaction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +56,69 @@ class InstallmentPlanSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
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