Skip to content

Commit

Permalink
adding task logs filters and errors msg in details col (#189)
Browse files Browse the repository at this point in the history
* adding task logs filters and errors msg in details col

* fixing test and adding validation
  • Loading branch information
labhvam5 authored Nov 14, 2022
1 parent 3120435 commit 96007b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 15 additions & 6 deletions apps/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ def get_queryset(self):
"""
Return task logs in workspace
"""
task_status = self.request.query_params.getlist('status')
task_type = self.request.query_params.get('task_type')
expense_group_ids = self.request.query_params.get('expense_group_ids')
task_status = self.request.query_params.get('status')

if len(task_status) == 1 and task_status[0] == 'ALL':
task_status = ['ENQUEUED', 'IN_PROGRESS', 'FAILED', 'COMPLETE']
filters = {
'workspace_id': self.kwargs['workspace_id']
}

task_logs = TaskLog.objects.filter(~Q(type='CREATING_PAYMENT'),
workspace_id=self.kwargs['workspace_id'], status__in=task_status).order_by('-updated_at').all()
if task_type:
filters['type__in'] = task_type.split(',')

return task_logs
if expense_group_ids:
filters['expense_group_id__in'] = expense_group_ids.split(',')

if task_status:
filters['status__in'] = task_status.split(',')

return TaskLog.objects.filter(**filters).order_by('-updated_at').all()


class TasksByIdView(generics.RetrieveAPIView):
Expand Down
9 changes: 8 additions & 1 deletion apps/xero/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,20 @@ def handle_xero_error(exception, expense_group: ExpenseGroup, task_log: TaskLog)
'message': detail['message']['Message'],
'error': detail['message']
})

error_detail = 'Something unexcepted happen'
if 'Elements' in detail['message'] and len(detail['message']['Elements']) > 0 and\
'ValidationErrors' in detail['message']['Elements'][0] and len(detail['message']['Elements'][0]['ValidationErrors']) > 0 and\
'Message' in detail['message']['Elements'][0]['ValidationErrors'][0]:
error_detail = detail['message']['Elements'][0]['ValidationErrors'][0]['Message']

Error.objects.update_or_create(
workspace_id=expense_group.workspace_id,
expense_group=expense_group,
defaults={
'type': 'XERO_ERROR',
'error_title': detail['message']['Message'],
'error_detail': detail['message'],
'error_detail': error_detail,
'is_resolved': False
}
)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_xero/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def test_create_bill_exceptions(db):
}, response='Invalid params')
create_bill(expense_group.id, task_log.id, xero_connection, False)

mock_call.side_effect = WrongParamsError({'ErrorNumber': 10, 'Type': 'ValidationException', 'Message': 'A validation exception occurred', 'Elements': [{'BankAccount': {'AccountID': '562555f2-8cde-4ce9-8203-0363922537a4', 'Code': '090', 'ValidationErrors': []}, 'Type': 'SPEND', 'Reference': 'E/2022/03/T/1', 'Url': 'None/app/admin/#/view_expense/txkImp4VID2Z?org_id=orhlmPm4H0wn', 'IsReconciled': False, 'Contact': {'ContactID': '73e6b7fb-ba7e-4b0a-a08b-f971b8ebbed8', 'Addresses': [], 'Phones': [], 'ContactGroups': [], 'ContactPersons': [], 'HasValidationErrors': False, 'ValidationErrors': []}, 'DateString': '2022-03-30T00:00:00', 'Date': '/Date(1648598400000+0000)/', 'Status': 'AUTHORISED', 'LineAmountTypes': 'Exclusive', 'LineItems': [{'Description': '[email protected], category - Food spent on 2022-03-30, report number - C/2022/03/R/1 - https://staging.fyle.tech/app/main/#/enterprise/view_expense/txkImp4VID2Z?org_id=orhlmPm4H0wn', 'UnitAmount': 92.38, 'TaxType': 'OUTPUT', 'TaxAmount': 7.62, 'LineAmount': 92.38, 'AccountCode': '425', 'Tracking': [], 'Quantity': 1.0, 'AccountID': 'c4b1c463-9913-4672-a8b8-01a3b546126f', 'ValidationErrors': []}], 'SubTotal': 92.38, 'TotalTax': 7.62, 'Total': 100.0, 'CurrencyCode': 'USD', 'ValidationErrors': [{'Message': 'Url must be a valid absolute url'}]}]})
create_bill(expense_group.id, task_log.id, xero_connection, False)

task_log = TaskLog.objects.get(id=task_log.id)
assert task_log.status == 'FAILED'

Expand Down Expand Up @@ -376,6 +379,9 @@ def test_create_bank_transactions_exceptions(db):
}, response='Invalid params')
create_bank_transaction(expense_group.id, task_log.id, xero_connection, False)

mock_call.side_effect = WrongParamsError({'ErrorNumber': 10, 'Type': 'ValidationException', 'Message': 'A validation exception occurred', 'Elements': [{'BankAccount': {'AccountID': '562555f2-8cde-4ce9-8203-0363922537a4', 'Code': '090', 'ValidationErrors': []}, 'Type': 'SPEND', 'Reference': 'E/2022/03/T/1', 'Url': 'None/app/admin/#/view_expense/txkImp4VID2Z?org_id=orhlmPm4H0wn', 'IsReconciled': False, 'Contact': {'ContactID': '73e6b7fb-ba7e-4b0a-a08b-f971b8ebbed8', 'Addresses': [], 'Phones': [], 'ContactGroups': [], 'ContactPersons': [], 'HasValidationErrors': False, 'ValidationErrors': []}, 'DateString': '2022-03-30T00:00:00', 'Date': '/Date(1648598400000+0000)/', 'Status': 'AUTHORISED', 'LineAmountTypes': 'Exclusive', 'LineItems': [{'Description': '[email protected], category - Food spent on 2022-03-30, report number - C/2022/03/R/1 - https://staging.fyle.tech/app/main/#/enterprise/view_expense/txkImp4VID2Z?org_id=orhlmPm4H0wn', 'UnitAmount': 92.38, 'TaxType': 'OUTPUT', 'TaxAmount': 7.62, 'LineAmount': 92.38, 'AccountCode': '425', 'Tracking': [], 'Quantity': 1.0, 'AccountID': 'c4b1c463-9913-4672-a8b8-01a3b546126f', 'ValidationErrors': []}], 'SubTotal': 92.38, 'TotalTax': 7.62, 'Total': 100.0, 'CurrencyCode': 'USD', 'ValidationErrors': [{'Message': 'Url must be a valid absolute url'}]}]})
create_bank_transaction(expense_group.id, task_log.id, xero_connection, False)

task_log = TaskLog.objects.get(id=task_log.id)
assert task_log.status == 'FAILED'

Expand Down

0 comments on commit 96007b4

Please sign in to comment.