Skip to content

Commit

Permalink
added more fields in expense serializer for redirection (#458)
Browse files Browse the repository at this point in the history
* added more fields in expense serializer

* Sync import API (#459)

* 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 9b0998e commit cf736f5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 24 deletions.
20 changes: 11 additions & 9 deletions apps/fyle/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
from .models import Expense, ExpenseFilter, ExpenseGroup, ExpenseGroupSettings


class ExpenseSerializer(serializers.ModelSerializer):
"""
Expense serializer
"""
class Meta:
model = Expense
fields = ['updated_at', 'claim_number', 'employee_email', 'employee_name', 'fund_source', 'expense_number', 'vendor', 'category', 'amount',
'report_id', 'settlement_id', 'expense_id']

class ExpenseGroupSerializer(serializers.ModelSerializer):
"""
Expense group serializer
"""
expenses = ExpenseSerializer(many=True)
class Meta:
model = ExpenseGroup
fields = '__all__'
extra_fields = ['expenses']


class ExpenseGroupExpenseSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -60,12 +71,3 @@ def create(self, validated_data):
)

return expense_filter


class ExpenseSerializer(serializers.ModelSerializer):
"""
Expense serializer
"""
class Meta:
model = Expense
fields = ['updated_at', 'claim_number', 'employee_email', 'employee_name', 'fund_source']
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
)
24 changes: 22 additions & 2 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@
'claim_number': ' C/2021/12/R/198',
'employee_email': '[email protected]',
'employee_name': None,
'fund_source': 'CCC'
'fund_source': 'CCC',
'expense_number': 'E/2023/09/T/7',
'vendor': None,
'category': 'Train',
'amount': 101.0,
'report_id': 'dummy_report_id',
'settlement_id': 'dummy_settlement_id',
'expense_id': 'dummy_expense_id'
},
{
'updated_at': '2021-12-03T11:26:58.702209Z',
Expand Down Expand Up @@ -547,7 +554,20 @@
"exported_at": "2021-11-15T11:02:55.125205Z",
"updated_at": "2021-11-15T11:02:55.125634Z",
"workspace": 1,
"expenses": [1],
"expenses": [ {
"updated_at": "2023-11-21T10:41:09.919000Z",
"claim_number": "C/2023/06/R/4",
"employee_email": "[email protected]",
"employee_name": "Theresa Brown",
"fund_source": "PERSONAL",
"expense_number": "E/2023/06/T/21",
"vendor": "95110",
"category": "Airlines",
"amount": 6377.0,
"report_id": "rp0kaXoqkJle",
"settlement_id": "setPzkM7eyQFd",
"expense_id": "txyZ1zJDQfiK"
}],
},
"expense_group_setting_response": {
"id": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fyle/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,4 @@ def test_exportable_expense_group_view(api_client, access_token):
assert response.status_code==200

response = json.loads(response.content)
assert response['exportable_expense_group_ids'] == [1, 2]
assert response['exportable_expense_group_ids'] == [1, 2]

0 comments on commit cf736f5

Please sign in to comment.