Skip to content
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

Import projects base imp #519

Merged
merged 8 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "fyle_integrations_imports"]
path = fyle_integrations_imports
url = https://github.com/fylein/fyle_integrations_imports.git
53 changes: 53 additions & 0 deletions apps/mappings/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from qbosdk.exceptions import WrongParamsError as QBOWrongParamsError

from apps.workspaces.models import QBOCredential
from fyle_integrations_imports.models import ImportLog

logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down Expand Up @@ -50,3 +51,55 @@ def new_fn(workspace_id: int, *args):
return new_fn

return decorator


def handle_import_exceptions_v2(func):
def new_fn(expense_attribute_instance, *args):
labhvam5 marked this conversation as resolved.
Show resolved Hide resolved
import_log: ImportLog = args[0]
workspace_id = import_log.workspace_id
attribute_type = import_log.attribute_type
error = {
'task': 'Import {0} to Fyle and Auto Create Mappings'.format(attribute_type),
'workspace_id': workspace_id,
'message': None,
'response': None
}
try:
return func(expense_attribute_instance, *args)
except WrongParamsError as exception:
error['message'] = exception.message
error['response'] = exception.response
error['alert'] = True
import_log.status = 'FAILED'

except InvalidTokenError:
error['message'] = 'Invalid Token for fyle'
error['alert'] = False
import_log.status = 'FAILED'

except InternalServerError:
error['message'] = 'Internal server error while importing to Fyle'
error['alert'] = True
import_log.status = 'FAILED'

except (QBOWrongParamsError, QBOInvalidTokenError, QBOCredential.DoesNotExist) as exception:
error['message'] = 'Invalid Token or QBO credentials does not exist workspace_id - {0}'.format(workspace_id)
error['alert'] = False
import_log.status = 'FAILED'

except Exception:
response = traceback.format_exc()
error['message'] = 'Something went wrong'
error['response'] = response
error['alert'] = False
import_log.status = 'FATAL'

if error['alert']:
logger.error(error)
else:
logger.info(error)

import_log.error_log = error
import_log.save()

return new_fn
2 changes: 1 addition & 1 deletion apps/mappings/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_auto_sync_permission(mapping_setting: MappingSetting):
:return: bool
"""
is_auto_sync_status_allowed = False
if (mapping_setting.destination_field == 'PROJECT' and mapping_setting.source_field == 'CUSTOMER') or mapping_setting.source_field == 'CATEGORY':
if (mapping_setting.destination_field == 'CUSTOMER' and mapping_setting.source_field == 'PROJECT') or mapping_setting.source_field == 'CATEGORY':
is_auto_sync_status_allowed = True

return is_auto_sync_status_allowed
31 changes: 16 additions & 15 deletions apps/mappings/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from apps.mappings.models import GeneralMapping
from apps.workspaces.models import WorkspaceGeneralSettings, QBOCredential
from apps.mappings.helpers import get_auto_sync_permission
from fyle_integrations_imports.queues import chain_import_fields_to_fyle
from fyle_integrations_imports.dataclasses import TaskSetting

SYNC_METHODS = {
'ACCOUNT': 'accounts',
Expand Down Expand Up @@ -107,26 +109,25 @@ def construct_tasks_and_chain_import_fields_to_fyle(workspace_id):
mapping_settings = MappingSetting.objects.filter(workspace_id=workspace_id, import_to_fyle=True)
credentials = QBOCredential.objects.get(workspace_id=workspace_id)

task_settings = {
task_settings: TaskSetting = {
'import_tax': None,
'import_vendors_as_merchants': None,
'import_categories': None,
'mapping_settings': [],
'credentails': credentials,
'credentials': credentials,
'sdk_connection_string': 'apps.quickbooks_online.utils.QBOConnector',
}

# For now we are only adding PROJECTS support that is why we are hardcoding it
for mapping_setting in mapping_settings:
if mapping_setting.source_field in ['PROJECT']:
task_settings['mapping_settings'].append({
'source_field': mapping_setting.source_field,
'destination_field': mapping_setting.destination_field,
'destination_sync_method': SYNC_METHODS[mapping_setting.destination_field],
'is_auto_sync_enabled': get_auto_sync_permission(mapping_setting),
'is_custom': False,
})

# Make a call to the SDK
# chain_import_fields_to_fyle(workspace_id, task_settings)
pass
if mapping_settings:
labhvam5 marked this conversation as resolved.
Show resolved Hide resolved
for mapping_setting in mapping_settings:
if mapping_setting.source_field in ['PROJECT']:
labhvam5 marked this conversation as resolved.
Show resolved Hide resolved
task_settings['mapping_settings'].append({
'source_field': mapping_setting.source_field,
'destination_field': mapping_setting.destination_field,
'destination_sync_method': SYNC_METHODS[mapping_setting.destination_field],
'is_auto_sync_enabled': get_auto_sync_permission(mapping_setting),
'is_custom': False,
})

chain_import_fields_to_fyle(workspace_id, task_settings)
2 changes: 1 addition & 1 deletion apps/workspaces/apis/map_employees/triggers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps.mappings.queue import schedule_auto_map_employees
from apps.mappings.queues import schedule_auto_map_employees
from apps.workspaces.models import WorkspaceGeneralSettings


Expand Down
1 change: 1 addition & 0 deletions fyle_integrations_imports
1 change: 1 addition & 0 deletions fyle_qbo_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'corsheaders',
'fyle_rest_auth',
'fyle_accounting_mappings',
'fyle_integrations_imports',
'django_q',
'django_filters',
# User Created Apps
Expand Down
6 changes: 6 additions & 0 deletions sql/functions/delete-workspace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ BEGIN
GET DIAGNOSTICS rcount = ROW_COUNT;
RAISE NOTICE 'Deleted % errors', rcount;

DELETE
FROM import_logs il
WHERE il.workspace_id = _workspace_id;
GET DIAGNOSTICS rcount = ROW_COUNT;
RAISE NOTICE 'Deleted % import_logs', rcount;

DELETE
FROM bill_lineitems bl
WHERE bl.bill_id IN (
Expand Down
Loading