From 4fbf370ff63b6b326ef79e55915a30160e1404ff Mon Sep 17 00:00:00 2001 From: Ashwin Thanaraj <37061471+ashwin1111@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:14:20 +0530 Subject: [PATCH] Handle Xero invalid token gracefully and case insensitive filter for import operations (#209) * Handle xero invalid token gracefully * case insensitive filter --- apps/mappings/tasks.py | 11 +++++++---- apps/workspaces/views.py | 23 ++++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index 38982686..6850931b 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -277,11 +277,11 @@ def create_fyle_cost_centers_payload(xero_attributes: List[DestinationAttribute] :param fyle_attribute: Fyle Attribute :return: Fyle Cost Centers Payload """ - + existing_fyle_cost_centers = [cost_center.lower() for cost_center in existing_fyle_cost_centers] fyle_cost_centers_payload = [] for xero_attribute in xero_attributes: - if xero_attribute.value not in existing_fyle_cost_centers: + if xero_attribute.value.lower() not in existing_fyle_cost_centers: fyle_cost_centers_payload.append({ 'name': xero_attribute.value, 'is_enabled': True if xero_attribute.active is None else xero_attribute.active, @@ -390,9 +390,10 @@ def create_fyle_projects_payload(projects: List[DestinationAttribute], existing_ :return: Fyle Projects Payload """ payload = [] + existing_project_names = [project_name.lower() for project_name in existing_project_names] for project in projects: - if project.value not in existing_project_names: + if project.value.lower() not in existing_project_names: payload.append({ 'name': project.value, 'code': project.destination_id, @@ -686,9 +687,11 @@ def create_fyle_tax_group_payload(xero_attributes: List[DestinationAttribute], e :return: Fyle tax Group Payload """ + existing_fyle_tax_groups = [tax_group.lower() for tax_group in existing_fyle_tax_groups] + fyle_tax_group_payload = [] for xero_attribute in xero_attributes: - if xero_attribute.value not in existing_fyle_tax_groups: + if xero_attribute.value.lower() not in existing_fyle_tax_groups: fyle_tax_group_payload.append( { 'name': xero_attribute.value, diff --git a/apps/workspaces/views.py b/apps/workspaces/views.py index 471a6c57..d6149e3c 100644 --- a/apps/workspaces/views.py +++ b/apps/workspaces/views.py @@ -519,14 +519,23 @@ def post(self, request, **kwargs): """ Post Xero External Sign Ups """ - authorization_code = request.data.get('code') - redirect_uri = request.data.get('redirect_uri') - identity = generate_xero_identity(authorization_code, redirect_uri) + try: + authorization_code = request.data.get('code') + redirect_uri = request.data.get('redirect_uri') + identity = generate_xero_identity(authorization_code, redirect_uri) - return Response( - data=identity, - status=status.HTTP_200_OK - ) + return Response( + data=identity, + status=status.HTTP_200_OK + ) + except Exception as exception: + logger.info('Error while generating xero identity: %s', exception.__dict__) + return Response( + data={ + 'message': 'Error while generating xero identity' + }, + status=status.HTTP_400_BAD_REQUEST + ) class ExportToXeroView(viewsets.ViewSet):