Skip to content

Commit

Permalink
Sync import API (#459)
Browse files Browse the repository at this point in the history
* added expense group sync API

* minor changes

* added url for expense group sync view
  • Loading branch information
Ashutosh619-sudo authored Nov 29, 2023
1 parent 8b0760f commit d429e9c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
23 changes: 14 additions & 9 deletions apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,32 @@
'CCC': 'PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT'
}

def schedule_expense_group_creation(workspace_id: int):
"""
Schedule Expense group creation
:param workspace_id: Workspace id
:param user: User email
:return: None
"""
def get_task_log_and_fund_source(workspace_id: int):
task_log, _ = TaskLog.objects.update_or_create(
workspace_id=workspace_id,
type='FETCHING_EXPENSES',
defaults={
'status': 'IN_PROGRESS'
'status': 'IN_PROGRESS'
}
)

configuration = Configuration.objects.get(workspace_id=workspace_id)

fund_source = ['PERSONAL']
if configuration.corporate_credit_card_expenses_object is not None:
fund_source.append('CCC')

return task_log, fund_source, configuration

def schedule_expense_group_creation(workspace_id: int):
"""
Schedule Expense group creation
:param workspace_id: Workspace id
:param user: User email
:return: None
"""

task_log, fund_source, configuration = get_task_log_and_fund_source(workspace_id)

async_task('apps.fyle.tasks.create_expense_groups', workspace_id, configuration, fund_source, task_log)


Expand Down
5 changes: 3 additions & 2 deletions apps/fyle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.urls import path

from .views import ExpenseGroupView, ExpenseGroupByIdView, ExpenseGroupScheduleView, ExportableExpenseGroupsView, FyleFieldsView, ExpenseView,\
from .views import ExpenseGroupSyncView, ExpenseGroupView, ExpenseGroupByIdView, ExpenseGroupScheduleView, ExportableExpenseGroupsView, FyleFieldsView, ExpenseView,\
ExpenseAttributesView, ExpenseGroupSettingsView, SyncFyleDimensionView, RefreshFyleDimensionView,\
ExpenseGroupCountView, ExpenseFilterView, ExpenseGroupExpenseView, CustomFieldView

Expand All @@ -13,7 +13,8 @@
path('expense_groups/<int:pk>/', ExpenseGroupByIdView.as_view(), name='expense-group-by-id'),
path('expense_groups/<int:expense_group_id>/expenses/', ExpenseGroupExpenseView.as_view(), name='expense-group-expenses'),
path('expense_group_settings/', ExpenseGroupSettingsView.as_view(), name='expense-group-settings'),
path('exportable_expense_groups/', ExportableExpenseGroupsView.as_view(), name='expense-expense-groups')
path('exportable_expense_groups/', ExportableExpenseGroupsView.as_view(), name='expense-expense-groups'),
path('expense_groups/sync/', ExpenseGroupSyncView.as_view(), name='sync-expense-groups'),
]

fyle_dimension_paths = [
Expand Down
19 changes: 18 additions & 1 deletion apps/fyle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from apps.workspaces.models import Configuration, FyleCredential, Workspace

from .tasks import schedule_expense_group_creation
from .tasks import schedule_expense_group_creation, get_task_log_and_fund_source, create_expense_groups
from .helpers import check_interval_and_sync_dimension, sync_dimensions
from .models import Expense, ExpenseGroup, ExpenseGroupSettings, ExpenseFilter
from .serializers import ExpenseGroupSerializer, ExpenseSerializer, ExpenseFieldSerializer, \
Expand Down Expand Up @@ -419,3 +419,20 @@ def get(self, request, *args, **kwargs):
},
status=status.HTTP_400_BAD_REQUEST
)


class ExpenseGroupSyncView(generics.CreateAPIView):
"""
Create expense groups
"""
def post(self, request, *args, **kwargs):
"""
Post expense groups creation
"""
task_log, fund_source, configuration = get_task_log_and_fund_source(kwargs['workspace_id'])

create_expense_groups(kwargs['workspace_id'], configuration ,fund_source, task_log)

return Response(
status=status.HTTP_200_OK
)

0 comments on commit d429e9c

Please sign in to comment.