diff --git a/apps/fyle/helpers.py b/apps/fyle/helpers.py index a65641d..062216a 100644 --- a/apps/fyle/helpers.py +++ b/apps/fyle/helpers.py @@ -1,11 +1,12 @@ import json + import requests from django.conf import settings - from fyle_integrations_platform_connector import PlatformConnector -from apps.workspaces.models import FyleCredential +from apps.accounting_exports.models import AccountingExport from apps.fyle.constants import DEFAULT_FYLE_CONDITIONS +from apps.workspaces.models import ExportSetting, FyleCredential def post_request(url, body, refresh_token=None): @@ -79,3 +80,25 @@ def get_expense_fields(workspace_id: int): }) return response + + +def get_exportable_accounting_exports_ids(workspace_id: int): + """ + Get List of accounting exports ids + """ + + export_setting = ExportSetting.objects.get(workspace_id=workspace_id) + fund_source = [] + + if export_setting.reimbursable_expenses_export_type: + fund_source.append('PERSONAL') + if export_setting.credit_card_expense_export_type: + fund_source.append('CCC') + + accounting_export_ids = AccountingExport.objects.filter( + workspace_id=workspace_id, + exported_at__isnull=True, + fund_source__in=fund_source + ).values_list('id', flat=True) + + return accounting_export_ids diff --git a/apps/fyle/urls.py b/apps/fyle/urls.py index f913444..5149973 100644 --- a/apps/fyle/urls.py +++ b/apps/fyle/urls.py @@ -14,14 +14,32 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +import itertools + from django.urls import path -from apps.fyle.views import ExpenseFilterView, ExpenseFilterDeleteView, ImportFyleAttributesView, FyleFieldsView, CustomFieldView +from apps.fyle.views import ( + CustomFieldView, + ExpenseFilterDeleteView, + ExpenseFilterView, + ExportableExpenseGroupsView, + FyleFieldsView, + ImportFyleAttributesView, +) + +accounting_exports_path = [ + path('exportable_accounting_exports/', ExportableExpenseGroupsView.as_view(), name='exportable-accounting-exports') +] -urlpatterns = [ +other_paths = [ path('expense_filters//', ExpenseFilterDeleteView.as_view(), name='expense-filters'), path('expense_filters/', ExpenseFilterView.as_view(), name='expense-filters'), - path('import_attributes/', ImportFyleAttributesView.as_view(), name='import-fyle-attributes'), path('fields/', FyleFieldsView.as_view(), name='fyle-fields'), path('expense_fields/', CustomFieldView.as_view(), name='fyle-expense-fields'), ] + +fyle_dimension_paths = [ + path('import_attributes/', ImportFyleAttributesView.as_view(), name='import-fyle-attributes') +] + +urlpatterns = list(itertools.chain(accounting_exports_path, fyle_dimension_paths, other_paths)) diff --git a/apps/fyle/views.py b/apps/fyle/views.py index 71d2e84..8eef36f 100644 --- a/apps/fyle/views.py +++ b/apps/fyle/views.py @@ -1,9 +1,19 @@ import logging + from rest_framework import generics -from ms_business_central_api.utils import LookupFieldMixin -from apps.workspaces.models import Workspace -from apps.fyle.serializers import ExpenseFilterSerializer, ImportFyleAttributesSerializer, FyleFieldsSerializer, ExpenseFieldSerializer +from rest_framework.response import Response +from rest_framework.views import status + +from apps.fyle.helpers import get_exportable_accounting_exports_ids from apps.fyle.models import ExpenseFilter +from apps.fyle.serializers import ( + ExpenseFieldSerializer, + ExpenseFilterSerializer, + FyleFieldsSerializer, + ImportFyleAttributesSerializer, +) +from apps.workspaces.models import Workspace +from ms_business_central_api.utils import LookupFieldMixin logger = logging.getLogger(__name__) logger.level = logging.INFO @@ -52,3 +62,17 @@ class CustomFieldView(generics.ListAPIView): serializer_class = ExpenseFieldSerializer queryset = Workspace.objects.all() + + +class ExportableExpenseGroupsView(generics.RetrieveAPIView): + """ + List Exportable Expense Groups + """ + def get(self, request, *args, **kwargs): + + exportable_ids = get_exportable_accounting_exports_ids(workspace_id=kwargs['workspace_id']) + + return Response( + data={'exportable_expense_group_ids': exportable_ids}, + status=status.HTTP_200_OK + )