diff --git a/apps/accounting_exports/urls.py b/apps/accounting_exports/urls.py index e66f6069..0601ffae 100644 --- a/apps/accounting_exports/urls.py +++ b/apps/accounting_exports/urls.py @@ -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'), ] diff --git a/apps/accounting_exports/views.py b/apps/accounting_exports/views.py index 1f15a035..7664ccda 100644 --- a/apps/accounting_exports/views.py +++ b/apps/accounting_exports/views.py @@ -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 @@ -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() diff --git a/tests/test_accounting_exports/test_views.py b/tests/test_accounting_exports/test_views.py index 6dd96453..9cff65d4 100644 --- a/tests/test_accounting_exports/test_views.py +++ b/tests/test_accounting_exports/test_views.py @@ -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):