From 34cdc27553dc80d97a20436a63bce7beae0b92f4 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Thu, 23 Nov 2023 16:39:19 +0530 Subject: [PATCH 1/3] added expense group sync API --- apps/fyle/tasks.py | 25 +++++++++++++++---------- apps/fyle/views.py | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index f3ed39f8..789885af 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -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: + if configuration.corporate_credit_card_expenses_object: 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) diff --git a/apps/fyle/views.py b/apps/fyle/views.py index 561d0670..75ad45fc 100644 --- a/apps/fyle/views.py +++ b/apps/fyle/views.py @@ -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, \ @@ -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 + ) From fce7ebb4d30428909d0d31351bc4902aa73aca7e Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Thu, 23 Nov 2023 16:40:44 +0530 Subject: [PATCH 2/3] minor changes --- apps/fyle/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index 789885af..e3b9ab40 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -35,7 +35,7 @@ def get_task_log_and_fund_source(workspace_id: int): configuration = Configuration.objects.get(workspace_id=workspace_id) fund_source = ['PERSONAL'] - if configuration.corporate_credit_card_expenses_object: + if configuration.corporate_credit_card_expenses_object is not None: fund_source.append('CCC') return task_log, fund_source, configuration From 4f93375aa4446b5b7ccd5b333c02a77a35bd8588 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 27 Nov 2023 16:40:35 +0530 Subject: [PATCH 3/3] added url for expense group sync view --- apps/fyle/urls.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/fyle/urls.py b/apps/fyle/urls.py index ceee784b..2333ba8c 100644 --- a/apps/fyle/urls.py +++ b/apps/fyle/urls.py @@ -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 @@ -13,7 +13,8 @@ path('expense_groups//', ExpenseGroupByIdView.as_view(), name='expense-group-by-id'), path('expense_groups//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 = [