Skip to content

Commit

Permalink
Merge pull request #51 from fylein/accounting_export_count_api
Browse files Browse the repository at this point in the history
Accounting export count api added
  • Loading branch information
ruuushhh authored Oct 27, 2023
2 parents 64d3849 + 1dd04e4 commit 92d1010
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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.RetrieveAPIView):
"""
Retrieve Accounting Export Count
"""

def get(self, request, *args, **kwargs):
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

0 comments on commit 92d1010

Please sign in to comment.