Skip to content

Commit

Permalink
Exportable expense groups api
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Nov 20, 2023
1 parent 4843ad0 commit 9ab47c5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 8 deletions.
27 changes: 25 additions & 2 deletions apps/fyle/helpers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
24 changes: 21 additions & 3 deletions apps/fyle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/', 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))
30 changes: 27 additions & 3 deletions apps/fyle/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)

0 comments on commit 9ab47c5

Please sign in to comment.