Skip to content

Commit

Permalink
Handle Xero invalid token gracefully and case insensitive filter for …
Browse files Browse the repository at this point in the history
…import operations (#209)

* Handle xero invalid token gracefully

* case insensitive filter
  • Loading branch information
ashwin1111 authored Feb 2, 2023
1 parent 42e1173 commit 4fbf370
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
11 changes: 7 additions & 4 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions apps/workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4fbf370

Please sign in to comment.