mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-26 18:48:42 +02:00
add tests and fix missing get_queryset
This commit is contained in:
@@ -7,7 +7,11 @@ from rest_framework.response import Response
|
||||
from apps.accounts.models import AccountGroup, Account
|
||||
from apps.accounts.services import get_account_balance
|
||||
from apps.api.custom.pagination import CustomPageNumberPagination
|
||||
from apps.api.serializers import AccountGroupSerializer, AccountSerializer, AccountBalanceSerializer
|
||||
from apps.api.serializers import (
|
||||
AccountGroupSerializer,
|
||||
AccountSerializer,
|
||||
AccountBalanceSerializer,
|
||||
)
|
||||
|
||||
|
||||
class AccountGroupViewSet(viewsets.ModelViewSet):
|
||||
@@ -17,13 +21,15 @@ class AccountGroupViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = AccountGroupSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'owner': ['exact'],
|
||||
"name": ["exact", "icontains"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
search_fields = ["name"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return AccountGroup.objects.all()
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
@@ -40,37 +46,37 @@ class AccountViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = AccountSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'group': ['exact', 'isnull'],
|
||||
'currency': ['exact'],
|
||||
'exchange_currency': ['exact', 'isnull'],
|
||||
'is_asset': ['exact'],
|
||||
'is_archived': ['exact'],
|
||||
'owner': ['exact'],
|
||||
"name": ["exact", "icontains"],
|
||||
"group": ["exact", "isnull"],
|
||||
"currency": ["exact"],
|
||||
"exchange_currency": ["exact", "isnull"],
|
||||
"is_asset": ["exact"],
|
||||
"is_archived": ["exact"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
search_fields = ["name"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
Account.objects.all()
|
||||
.select_related("group", "currency", "exchange_currency")
|
||||
return Account.objects.all().select_related(
|
||||
"group", "currency", "exchange_currency"
|
||||
)
|
||||
|
||||
@action(detail=True, methods=["get"], permission_classes=[IsAuthenticated])
|
||||
def balance(self, request, pk=None):
|
||||
"""Get current and projected balance for an account."""
|
||||
account = self.get_object()
|
||||
|
||||
|
||||
current_balance = get_account_balance(account, paid_only=True)
|
||||
projected_balance = get_account_balance(account, paid_only=False)
|
||||
|
||||
serializer = AccountBalanceSerializer({
|
||||
"current_balance": current_balance,
|
||||
"projected_balance": projected_balance,
|
||||
"currency": account.currency,
|
||||
})
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
serializer = AccountBalanceSerializer(
|
||||
{
|
||||
"current_balance": current_balance,
|
||||
"projected_balance": projected_balance,
|
||||
"currency": account.currency,
|
||||
}
|
||||
)
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
@@ -6,18 +6,21 @@ from apps.api.serializers import DCAStrategySerializer, DCAEntrySerializer
|
||||
|
||||
|
||||
class DCAStrategyViewSet(viewsets.ModelViewSet):
|
||||
queryset = DCAStrategy.all_objects.all()
|
||||
queryset = DCAStrategy.objects.all()
|
||||
serializer_class = DCAStrategySerializer
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'target_currency': ['exact'],
|
||||
'payment_currency': ['exact'],
|
||||
'notes': ['exact', 'icontains'],
|
||||
'created_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'updated_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
"name": ["exact", "icontains"],
|
||||
"target_currency": ["exact"],
|
||||
"payment_currency": ["exact"],
|
||||
"notes": ["exact", "icontains"],
|
||||
"created_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"updated_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
}
|
||||
search_fields = ['name', 'notes']
|
||||
ordering_fields = '__all__'
|
||||
search_fields = ["name", "notes"]
|
||||
ordering_fields = "__all__"
|
||||
|
||||
def get_queryset(self):
|
||||
return DCAStrategy.objects.all()
|
||||
|
||||
@action(detail=True, methods=["get"])
|
||||
def investment_frequency(self, request, pk=None):
|
||||
@@ -43,16 +46,21 @@ class DCAEntryViewSet(viewsets.ModelViewSet):
|
||||
queryset = DCAEntry.objects.all()
|
||||
serializer_class = DCAEntrySerializer
|
||||
filterset_fields = {
|
||||
'strategy': ['exact'],
|
||||
'date': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'amount_paid': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'amount_received': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'expense_transaction': ['exact', 'isnull'],
|
||||
'income_transaction': ['exact', 'isnull'],
|
||||
'notes': ['exact', 'icontains'],
|
||||
'created_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'updated_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
"strategy": ["exact"],
|
||||
"date": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"amount_paid": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"amount_received": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"expense_transaction": ["exact", "isnull"],
|
||||
"income_transaction": ["exact", "isnull"],
|
||||
"notes": ["exact", "icontains"],
|
||||
"created_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"updated_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
}
|
||||
search_fields = ['notes']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['-date']
|
||||
search_fields = ["notes"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["-date"]
|
||||
|
||||
def get_queryset(self):
|
||||
# Filter entries by strategies the user has access to
|
||||
accessible_strategies = DCAStrategy.objects.all()
|
||||
return DCAEntry.objects.filter(strategy__in=accessible_strategies)
|
||||
|
||||
@@ -27,30 +27,33 @@ class TransactionViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = TransactionSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'account': ['exact'],
|
||||
'type': ['exact'],
|
||||
'is_paid': ['exact'],
|
||||
'date': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'reference_date': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'mute': ['exact'],
|
||||
'amount': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'description': ['exact', 'icontains'],
|
||||
'notes': ['exact', 'icontains'],
|
||||
'category': ['exact', 'isnull'],
|
||||
'installment_plan': ['exact', 'isnull'],
|
||||
'installment_id': ['exact', 'gte', 'lte'],
|
||||
'recurring_transaction': ['exact', 'isnull'],
|
||||
'internal_note': ['exact', 'icontains'],
|
||||
'internal_id': ['exact'],
|
||||
'deleted': ['exact'],
|
||||
'created_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'updated_at': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'deleted_at': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'owner': ['exact'],
|
||||
"account": ["exact"],
|
||||
"type": ["exact"],
|
||||
"is_paid": ["exact"],
|
||||
"date": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"reference_date": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"mute": ["exact"],
|
||||
"amount": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"description": ["exact", "icontains"],
|
||||
"notes": ["exact", "icontains"],
|
||||
"category": ["exact", "isnull"],
|
||||
"installment_plan": ["exact", "isnull"],
|
||||
"installment_id": ["exact", "gte", "lte"],
|
||||
"recurring_transaction": ["exact", "isnull"],
|
||||
"internal_note": ["exact", "icontains"],
|
||||
"internal_id": ["exact"],
|
||||
"deleted": ["exact"],
|
||||
"created_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"updated_at": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"deleted_at": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['description', 'notes', 'internal_note']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['-id']
|
||||
search_fields = ["description", "notes", "internal_note"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["-id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return Transaction.objects.all()
|
||||
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
@@ -71,14 +74,17 @@ class TransactionCategoryViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = TransactionCategorySerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'mute': ['exact'],
|
||||
'active': ['exact'],
|
||||
'owner': ['exact'],
|
||||
"name": ["exact", "icontains"],
|
||||
"mute": ["exact"],
|
||||
"active": ["exact"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
search_fields = ["name"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return TransactionCategory.objects.all()
|
||||
|
||||
|
||||
class TransactionTagViewSet(viewsets.ModelViewSet):
|
||||
@@ -86,13 +92,16 @@ class TransactionTagViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = TransactionTagSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'active': ['exact'],
|
||||
'owner': ['exact'],
|
||||
"name": ["exact", "icontains"],
|
||||
"active": ["exact"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
search_fields = ["name"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return TransactionTag.objects.all()
|
||||
|
||||
|
||||
class TransactionEntityViewSet(viewsets.ModelViewSet):
|
||||
@@ -100,13 +109,16 @@ class TransactionEntityViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = TransactionEntitySerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'active': ['exact'],
|
||||
'owner': ['exact'],
|
||||
"name": ["exact", "icontains"],
|
||||
"active": ["exact"],
|
||||
"owner": ["exact"],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
search_fields = ["name"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return TransactionEntity.objects.all()
|
||||
|
||||
|
||||
class InstallmentPlanViewSet(viewsets.ModelViewSet):
|
||||
@@ -114,25 +126,28 @@ class InstallmentPlanViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = InstallmentPlanSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'account': ['exact'],
|
||||
'type': ['exact'],
|
||||
'description': ['exact', 'icontains'],
|
||||
'number_of_installments': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'installment_start': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'installment_total_number': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'start_date': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'reference_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'end_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'recurrence': ['exact'],
|
||||
'installment_amount': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'category': ['exact', 'isnull'],
|
||||
'notes': ['exact', 'icontains'],
|
||||
'add_description_to_transaction': ['exact'],
|
||||
'add_notes_to_transaction': ['exact'],
|
||||
"account": ["exact"],
|
||||
"type": ["exact"],
|
||||
"description": ["exact", "icontains"],
|
||||
"number_of_installments": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"installment_start": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"installment_total_number": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"start_date": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"reference_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"end_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"recurrence": ["exact"],
|
||||
"installment_amount": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"category": ["exact", "isnull"],
|
||||
"notes": ["exact", "icontains"],
|
||||
"add_description_to_transaction": ["exact"],
|
||||
"add_notes_to_transaction": ["exact"],
|
||||
}
|
||||
search_fields = ['description', 'notes']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['-id']
|
||||
search_fields = ["description", "notes"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["-id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return InstallmentPlan.objects.all()
|
||||
|
||||
|
||||
class RecurringTransactionViewSet(viewsets.ModelViewSet):
|
||||
@@ -140,25 +155,27 @@ class RecurringTransactionViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = RecurringTransactionSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'is_paused': ['exact'],
|
||||
'account': ['exact'],
|
||||
'type': ['exact'],
|
||||
'amount': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'description': ['exact', 'icontains'],
|
||||
'category': ['exact', 'isnull'],
|
||||
'notes': ['exact', 'icontains'],
|
||||
'reference_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'start_date': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'end_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'recurrence_type': ['exact'],
|
||||
'recurrence_interval': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'keep_at_most': ['exact', 'gte', 'lte', 'gt', 'lt'],
|
||||
'last_generated_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'last_generated_reference_date': ['exact', 'gte', 'lte', 'gt', 'lt', 'isnull'],
|
||||
'add_description_to_transaction': ['exact'],
|
||||
'add_notes_to_transaction': ['exact'],
|
||||
"is_paused": ["exact"],
|
||||
"account": ["exact"],
|
||||
"type": ["exact"],
|
||||
"amount": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"description": ["exact", "icontains"],
|
||||
"category": ["exact", "isnull"],
|
||||
"notes": ["exact", "icontains"],
|
||||
"reference_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"start_date": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"end_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"recurrence_type": ["exact"],
|
||||
"recurrence_interval": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"keep_at_most": ["exact", "gte", "lte", "gt", "lt"],
|
||||
"last_generated_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"last_generated_reference_date": ["exact", "gte", "lte", "gt", "lt", "isnull"],
|
||||
"add_description_to_transaction": ["exact"],
|
||||
"add_notes_to_transaction": ["exact"],
|
||||
}
|
||||
search_fields = ['description', 'notes']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['-id']
|
||||
search_fields = ["description", "notes"]
|
||||
ordering_fields = "__all__"
|
||||
ordering = ["-id"]
|
||||
|
||||
def get_queryset(self):
|
||||
return RecurringTransaction.objects.all()
|
||||
|
||||
Reference in New Issue
Block a user