Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting export count api added #51

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/accounting_exports/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"""
from django.urls import path

from .views import AccountingExportView, ErrorsView
from .views import AccountingExportView, ErrorsView, AccountingExportCountView


urlpatterns = [
path('', AccountingExportView.as_view(), name='accounting-exports'),
path('count/', AccountingExportCountView.as_view(), name='accounting-exports-count'),
path('errors/', ErrorsView.as_view(), name='errors'),
]
16 changes: 16 additions & 0 deletions apps/accounting_exports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import generics
from rest_framework.response import Response

from sage_desktop_api.utils import LookupFieldMixin
from apps.accounting_exports.serializers import AccountingExportSerializer, ErrorSerializer
from apps.accounting_exports.models import AccountingExport, Error
Expand All @@ -20,6 +22,20 @@ class AccountingExportView(LookupFieldMixin, generics.ListAPIView):
filterset_fields = {"type": {"in"}, "updated_at": {"lte", "gte"}, "id": {"in"}, "status": {"in"}}


class AccountingExportCountView(generics.ListAPIView):
ruuushhh marked this conversation as resolved.
Show resolved Hide resolved
"""
Retrieve Accounting Export Count
"""

def get(self, request, *args, **kwargs):
ruuushhh marked this conversation as resolved.
Show resolved Hide resolved
params = {"workspace_id": self.kwargs['workspace_id']}

if request.query_params.get("status__in"):
params["status__in"] = request.query_params.get("status__in").split(",")

return Response({"count" : AccountingExport.objects.filter(**params).count()})


class ErrorsView(LookupFieldMixin, generics.ListAPIView):
serializer_class = ErrorSerializer
queryset = Error.objects.all()
Expand Down
10 changes: 9 additions & 1 deletion tests/test_accounting_exports/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ def test_get_accounting_exports(api_client, test_connection, create_temp_workspa
assert response.status_code == 200
response = json.loads(response.content)

assert dict_compare_keys(response, data['accounting_export_response']) == [], 'expense group api return diffs in keys'
assert dict_compare_keys(response, data['accounting_export_response']) == [], 'accounting export api return diffs in keys'

url = reverse('accounting-exports-count', kwargs={'workspace_id': 1})

response = api_client.get(url, {'status__in': 'IN_PROGRESS'})
assert response.status_code == 200
response = json.loads(response.content)

assert response['count'] == 2, 'accounting export count api return diffs in keys'


def test_get_errors(api_client, test_connection, create_temp_workspace, add_fyle_credentials, add_errors):
Expand Down
Loading