Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync import API #459

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the the corresponding url path in url file ??

"""
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
)
Loading