-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting Employee Mapping error, resolving and export exception decorator #445
Merged
Merged
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
5c31b3f
onboarding state implementation
798e2bc
tests migrations
NileshPant1999 fdd7a9e
added onboarding state
609594d
changed comment
d15a8f5
added subsidiary state to onboarding state
ec4f4d1
changed script to add subsidiary state and fixed some bug
c64ff14
Merge branch 'master' into onboarding-state
67ddf59
bug fix
b9e5d3b
Merge branch 'master' into onboarding-state
Ashutosh619-sudo 3bce538
state change on connection and subsidiary change
ac37706
Merge branch 'master' into onboarding-state-sub
4d291b3
map employees v2 api
173c5bb
map_employees typos
932cf3f
bug fix
8f6cbb7
Merge branch 'master' into v2-api
5972c5c
export setting changes
cfb791b
export settings V2 api
02095ab
Merge branch 'master' into v2-api
Ashutosh619-sudo e9a0b17
added test for export settings api
8016d3d
Merge branch 'v2-api' of https://github.com/fylein/fyle-netsuite-api …
aa56ca4
resolved comments
62697bb
import settings v2 api
35be2fd
Merge branch 'master' into v2-api
3357a2e
test added for import settings v2 api
3558f30
advanced settings v2 api
84ed5c9
advanced settings v2 api with test case
16225f1
Merge branch 'master' into v2-api
18ecafe
First schedule should be triggered after interval hours
adf33da
Handle Admin GET in a safer way
2faa99f
Making reimbursbale expense object nullable and checking edge cases f…
fe4f88b
comment resolved
e7b1d40
resolving comments
48a39fd
all comment resolved
2eb6d34
added code in test for the changes
a21e0c1
added test code for the changes
6c2c439
Error model, API and test
7c41782
Export error decorator, creating employee error and resolving.
a06936f
exception error removed
0a4aee3
import error resolved
469efda
employee mapping error test added
31696d2
Merge branch 'master' into employee_mapping_err
NileshPant1999 69a0ce7
Merge branch 'master' into employee_mapping_err
Ashutosh619-sudo dc81ada
made changes to the decorator for export functions
Ashutosh619-sudo 24fabfa
Settings category mapping error and resolving (#446)
Ashutosh619-sudo cc17962
resolved comments
1c66ec1
resolved comments
Ashutosh619-sudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from apps.tasks.models import TaskLog | ||
from apps.workspaces.models import LastExportDetail | ||
from django.db.models import Q | ||
|
||
|
||
def update_last_export_details(workspace_id): | ||
last_export_detail = LastExportDetail.objects.get(workspace_id=workspace_id) | ||
|
||
failed_exports = TaskLog.objects.filter( | ||
~Q(type__in=['CREATING_VENDOR_PAYMENT','FETCHING_EXPENSES']), workspace_id=workspace_id, status__in=['FAILED', 'FATAL'] | ||
).count() | ||
|
||
successful_exports = TaskLog.objects.filter( | ||
~Q(type__in=['CREATING_VENDOR_PAYMENT', 'FETCHING_EXPENSES']), | ||
workspace_id=workspace_id, | ||
status='COMPLETE', | ||
updated_at__gt=last_export_detail.last_exported_at | ||
).count() | ||
|
||
last_export_detail.failed_expense_groups_count = failed_exports | ||
last_export_detail.successful_expense_groups_count = successful_exports | ||
last_export_detail.total_expense_groups_count = failed_exports + successful_exports | ||
last_export_detail.save() | ||
|
||
return last_export_detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import logging | ||
import json | ||
import traceback | ||
|
||
from apps.fyle.models import ExpenseGroup | ||
from apps.tasks.models import TaskLog, Error | ||
from apps.workspaces.models import LastExportDetail, NetSuiteCredentials | ||
|
||
from netsuitesdk.internal.exceptions import NetSuiteRequestError | ||
from netsuitesdk import NetSuiteRateLimitError, NetSuiteLoginError | ||
from fyle_netsuite_api.exceptions import BulkError | ||
|
||
from .actions import update_last_export_details | ||
|
||
from django.db.models import Q | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.level = logging.INFO | ||
|
||
netsuite_error_message = 'NetSuite System Error' | ||
|
||
def __handle_netsuite_connection_error(expense_group: ExpenseGroup, task_log: TaskLog) -> None: | ||
logger.info( | ||
'NetSuite Credentials not found for workspace_id %s / expense group %s', | ||
expense_group.id, | ||
expense_group.workspace_id | ||
) | ||
detail = { | ||
'message': 'NetSuite Account not connected' | ||
} | ||
|
||
Error.objects.update_or_create( | ||
workspace_id=expense_group.workspace_id, | ||
expense_group=expense_group, | ||
defaults={ | ||
'type': 'NETSUITE_ERROR', | ||
'error_title': netsuite_error_message, | ||
'error_detail': detail['message'], | ||
'is_resolved': False | ||
}) | ||
|
||
task_log.status = 'FAILED' | ||
task_log.detail = detail | ||
|
||
task_log.save() | ||
|
||
|
||
def __log_error(task_log: TaskLog) -> None: | ||
logger.exception('Something unexpected happened workspace_id: %s %s', task_log.workspace_id, task_log.detail) | ||
|
||
|
||
def handle_netsuite_exceptions(payment=False): | ||
def decorator(func): | ||
def wrapper(*args): | ||
if payment: | ||
entity_object = args[0] | ||
workspace_id = args[1] | ||
object_type = args[2] | ||
task_log, _ = TaskLog.objects.update_or_create( | ||
workspace_id=workspace_id, | ||
task_id='PAYMENT_{}'.format(entity_object['unique_id']), | ||
defaults={ | ||
'status': 'IN_PROGRESS', | ||
'type': 'CREATING_VENDOR_PAYMENT' | ||
} | ||
) | ||
else: | ||
expense_group = args[0] | ||
task_log_id = args[1] | ||
task_log = TaskLog.objects.get(id=task_log_id) | ||
last_export = args[2] | ||
|
||
try: | ||
func(*args) | ||
|
||
except NetSuiteCredentials.DoesNotExist: | ||
if payment: | ||
logger.info( | ||
'NetSuite Credentials not found for workspace_id %s', | ||
workspace_id | ||
) | ||
detail = { | ||
'message': 'NetSuite Account not connected' | ||
} | ||
task_log.status = 'FAILED' | ||
task_log.detail = detail | ||
|
||
task_log.save() | ||
else: | ||
__handle_netsuite_connection_error(expense_group, task_log) | ||
|
||
except (NetSuiteRequestError, NetSuiteLoginError) as exception: | ||
all_details = [] | ||
logger.info({'error': exception}) | ||
detail = json.dumps(exception.__dict__) | ||
detail = json.loads(detail) | ||
task_log.status = 'FAILED' | ||
|
||
all_details.append({ | ||
'value': netsuite_error_message, | ||
'type': detail['code'], | ||
'message': detail['message'] | ||
}) | ||
if not payment: | ||
Error.objects.update_or_create( | ||
workspace_id=expense_group.workspace_id, | ||
expense_group=expense_group, | ||
defaults={ | ||
'type': 'NETSUITE_ERROR', | ||
'error_title': netsuite_error_message, | ||
'error_detail': detail['message'], | ||
'is_resolved': False | ||
} | ||
) | ||
task_log.detail = all_details | ||
|
||
task_log.save() | ||
|
||
except BulkError as exception: | ||
logger.info(exception.response) | ||
detail = exception.response | ||
task_log.status = 'FAILED' | ||
task_log.detail = detail | ||
|
||
task_log.save() | ||
|
||
except NetSuiteRateLimitError: | ||
if not payment: | ||
Error.objects.update_or_create( | ||
workspace_id=expense_group.workspace_id, | ||
expense_group=expense_group, | ||
defaults={ | ||
'type': 'NETSUITE_ERROR', | ||
'error_title': netsuite_error_message, | ||
'error_detail': f'Rate limit error, workspace_id - {expense_group.workspace_id}', | ||
'is_resolved': False | ||
} | ||
) | ||
logger.info('Rate limit error, workspace_id - %s', workspace_id if payment else expense_group.workspace_id) | ||
task_log.status = 'FAILED' | ||
task_log.detail = { | ||
'error': 'Rate limit error' | ||
} | ||
|
||
task_log.save() | ||
|
||
except Exception: | ||
error = traceback.format_exc() | ||
task_log.detail = { | ||
'error': error | ||
} | ||
task_log.status = 'FATAL' | ||
task_log.save() | ||
__log_error(task_log) | ||
|
||
if not payment and last_export is True: | ||
update_last_export_details(expense_group.workspace_id) | ||
|
||
return wrapper | ||
return decorator |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why special treatment for payment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the payment function there is no expense_group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#445 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the Error Model needs expense_group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can assign expense_group = None inside 55 line block and then in __handle_netsuite_connection_error(), check for expense_group existence and update or create things