Skip to content

Commit d425309

Browse files
committed
feat: add system comments for p2 areas
1 parent 972c92c commit d425309

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

apps/workspaces/enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class SystemCommentSourceEnum(str, Enum):
5050
CREATE_EXPENSE_REPORT = 'CREATE_EXPENSE_REPORT'
5151
RETRIGGER_STUCK_EXPORTS = 'RETRIGGER_STUCK_EXPORTS'
5252

53+
# Connection handling
54+
HANDLE_SAGE_INTACCT_REST_API_CONNECTION = 'HANDLE_SAGE_INTACCT_REST_API_CONNECTION'
55+
5356

5457
class SystemCommentIntentEnum(str, Enum):
5558
"""
@@ -69,6 +72,7 @@ class SystemCommentIntentEnum(str, Enum):
6972
EXPORT_SUMMARY_NOT_UPDATED = 'EXPORT_SUMMARY_NOT_UPDATED'
7073
EXPORT_RETRIGGERED = 'EXPORT_RETRIGGERED'
7174
EXPORT_MODULE_RETIRED = 'EXPORT_MODULE_RETIRED'
75+
CONNECTION_FAILED = 'CONNECTION_FAILED'
7276

7377

7478
class SystemCommentReasonEnum(str, Enum):

apps/workspaces/views.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
LastExportDetailSerializer,
5858
SageIntacctCredentialSerializer,
5959
)
60+
from apps.workspaces.enums import SystemCommentSourceEnum, SystemCommentIntentEnum, SystemCommentReasonEnum, SystemCommentEntityTypeEnum
61+
from apps.workspaces.system_comments import add_system_comment
62+
from fyle_accounting_library.system_comments.models import SystemComment
6063

6164

6265
User = get_user_model()
@@ -415,6 +418,7 @@ def handle_sage_intacct_rest_api_connection(
415418
:param si_user_password: Sage Intacct user password
416419
:return: None
417420
"""
421+
system_comments = []
418422
try:
419423
sage_intacct_credentials = SageIntacctCredential.objects.filter(workspace=workspace).first()
420424

@@ -472,6 +476,16 @@ def handle_sage_intacct_rest_api_connection(
472476

473477
except SageIntacctRestInvalidTokenError as e:
474478
logger.info('Something went wrong while connecting to Sage Intacct - %s', e.response)
479+
add_system_comment(
480+
system_comments=system_comments,
481+
source=SystemCommentSourceEnum.HANDLE_SAGE_INTACCT_REST_API_CONNECTION,
482+
intent=SystemCommentIntentEnum.CONNECTION_FAILED,
483+
entity_type=None,
484+
workspace_id=workspace.id,
485+
entity_id=None,
486+
reason='Sage Intacct REST API connection failed: Invalid token error',
487+
info={'error': str(e.response), 'error_type': 'InvalidTokenError'}
488+
)
475489
return Response(
476490
{
477491
'message': e.response
@@ -481,6 +495,16 @@ def handle_sage_intacct_rest_api_connection(
481495

482496
except SageIntacctRESTBadRequestError as e:
483497
logger.info('Something went wrong while connecting to Sage Intacct - %s', e.response)
498+
add_system_comment(
499+
system_comments=system_comments,
500+
source=SystemCommentSourceEnum.HANDLE_SAGE_INTACCT_REST_API_CONNECTION,
501+
intent=SystemCommentIntentEnum.CONNECTION_FAILED,
502+
entity_type=None,
503+
workspace_id=workspace.id,
504+
entity_id=None,
505+
reason='Sage Intacct REST API connection failed: Bad request error',
506+
info={'error': str(e.response), 'error_type': 'BadRequestError'}
507+
)
484508
return Response(
485509
{
486510
'message': e.response
@@ -489,12 +513,25 @@ def handle_sage_intacct_rest_api_connection(
489513
)
490514
except SageIntacctRESTInternalServerError as e:
491515
logger.info('Something went wrong while connecting to Sage Intacct - %s', e.response)
516+
add_system_comment(
517+
system_comments=system_comments,
518+
source=SystemCommentSourceEnum.HANDLE_SAGE_INTACCT_REST_API_CONNECTION,
519+
intent=SystemCommentIntentEnum.CONNECTION_FAILED,
520+
entity_type=None,
521+
workspace_id=workspace.id,
522+
entity_id=None,
523+
reason='Sage Intacct REST API connection failed: Internal server error',
524+
info={'error': str(e.response), 'error_type': 'InternalServerError'}
525+
)
492526
return Response(
493527
{
494528
'message': 'Something went wrong while connecting to Sage Intacct'
495529
},
496530
status=status.HTTP_401_UNAUTHORIZED
497531
)
532+
finally:
533+
if system_comments:
534+
SystemComment.bulk_create_comments(system_comments)
498535

499536
def handle_sage_intacct_soap_api_connection(
500537
self,

0 commit comments

Comments
 (0)