-
Notifications
You must be signed in to change notification settings - Fork 0
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
Imports refactor master #322
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
823f0b7
Added integrations_imports submodule, made changes in settings (#310)
Hrishabh17 ef25328
Refactor imports for Project resource (#311)
Hrishabh17 7c0469b
Refactor imports for project and cost_center (#314)
Hrishabh17 8ac1c16
Refactor imports custom expense (#313)
Hrishabh17 457537b
Resource Tax Group: refactored imports (#315)
Hrishabh17 44e9af1
Resource Category: refactored imports (#316)
Hrishabh17 ae893af
Refactor imports supplier (#318)
Hrishabh17 e168eda
Refactor old flow (#321)
Hrishabh17 a03449f
Merged changes from master
Hrishabh17 4f057c6
Update delete workspace func (#319)
ruuushhh c39a459
upate workspace last synced fix (#320)
ruuushhh 0b32cd6
Merge branch 'master' into imports-refactor-master
Hrishabh17 55d9050
Modified the workflow for submodule
Hrishabh17 af10b05
Decreased the coverage to 88%
Hrishabh17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "fyle_integrations_imports"] | ||
path = fyle_integrations_imports | ||
url = [email protected]:fylein/fyle_integrations_imports.git |
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 |
---|---|---|
@@ -1,42 +1,14 @@ | ||
from datetime import datetime | ||
|
||
from django_q.models import Schedule | ||
from fyle_accounting_mappings.models import MappingSetting | ||
|
||
from apps.fyle.enums import FyleAttributeEnum | ||
from apps.workspaces.models import WorkspaceGeneralSettings | ||
|
||
|
||
def schedule_or_delete_fyle_import_tasks(configuration: WorkspaceGeneralSettings): | ||
def is_auto_sync_allowed(workspace_general_settings: WorkspaceGeneralSettings, mapping_setting: MappingSetting = None): | ||
""" | ||
:param configuration: WorkspaceGeneralSettings Instance | ||
:return: None | ||
Get the auto sync permission | ||
:return: bool | ||
""" | ||
project_mapping = MappingSetting.objects.filter( | ||
source_field=FyleAttributeEnum.PROJECT, workspace_id=configuration.workspace_id | ||
).first() | ||
if ( | ||
configuration.import_categories | ||
or (project_mapping and project_mapping.import_to_fyle) | ||
or configuration.import_suppliers_as_merchants | ||
): | ||
start_datetime = datetime.now() | ||
Schedule.objects.update_or_create( | ||
func="apps.mappings.tasks.auto_import_and_map_fyle_fields", | ||
cluster='import', | ||
args="{}".format(configuration.workspace_id), | ||
defaults={ | ||
"schedule_type": Schedule.MINUTES, | ||
"minutes": 24 * 60, | ||
"next_run": start_datetime, | ||
}, | ||
) | ||
elif ( | ||
not configuration.import_categories | ||
and not (project_mapping and project_mapping.import_to_fyle) | ||
and not configuration.import_suppliers_as_merchants | ||
): | ||
Schedule.objects.filter( | ||
func="apps.mappings.tasks.auto_import_and_map_fyle_fields", | ||
args="{}".format(configuration.workspace_id), | ||
).delete() | ||
is_auto_sync_status_allowed = False | ||
if (mapping_setting and mapping_setting.destination_field == 'CUSTOMER' and mapping_setting.source_field == 'PROJECT') or workspace_general_settings.import_categories: | ||
is_auto_sync_status_allowed = True | ||
|
||
return is_auto_sync_status_allowed |
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,50 @@ | ||
from datetime import datetime | ||
from typing import List, Dict | ||
from apps.workspaces.models import WorkspaceGeneralSettings | ||
from django_q.models import Schedule | ||
from fyle_accounting_mappings.models import MappingSetting | ||
|
||
|
||
def new_schedule_or_delete_fyle_import_tasks( | ||
workspace_general_settings_instance: WorkspaceGeneralSettings, | ||
mapping_settings: List[Dict] | ||
): | ||
""" | ||
Schedule or delete fyle import tasks based on the | ||
workspace general settings and mapping settings | ||
:param workspace_general_settings_instance: WorkspaceGeneralSettings instance | ||
:param mapping_settings: List of mapping settings | ||
:return: None | ||
""" | ||
# short-hand notation, it returns True as soon as it encounters import_to_fyle as True | ||
task_to_be_scheduled = any(mapping_setting['import_to_fyle'] for mapping_setting in mapping_settings) | ||
|
||
if ( | ||
task_to_be_scheduled | ||
or workspace_general_settings_instance.import_customers | ||
or workspace_general_settings_instance.import_tax_codes | ||
or workspace_general_settings_instance.import_categories | ||
or workspace_general_settings_instance.import_suppliers_as_merchants | ||
): | ||
Schedule.objects.update_or_create( | ||
func='apps.mappings.queue.construct_tasks_and_chain_import_fields_to_fyle', | ||
args='{}'.format(workspace_general_settings_instance.workspace_id), | ||
defaults={ | ||
'schedule_type':Schedule.MINUTES, | ||
'minutes': 24 * 60, | ||
'next_run': datetime.now(), | ||
'cluster': 'import' | ||
} | ||
) | ||
else: | ||
import_fields_count = MappingSetting.objects.filter( | ||
workspace_id=workspace_general_settings_instance.workspace_id, | ||
import_to_fyle=True | ||
).count() | ||
|
||
# if there are no import fields, delete the schedule | ||
if import_fields_count == 0: | ||
Schedule.objects.filter( | ||
func='apps.mappings.queue.construct_tasks_and_chain_import_fields_to_fyle', | ||
args='{}'.format(workspace_general_settings_instance.workspace_id) | ||
).delete() |
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.
The introduction of
handle_import_exceptions_v2
inapps/mappings/exceptions.py
is a valuable addition for handling and logging errors during the import process. A few suggestions for improvement:The function does a good job of handling various exceptions and updating the
ImportLog
status accordingly. Ensure that all relevant exceptions are covered and that the error messages are clear and informative.The use of
error['alert']
to determine whether to log an error as info or error is a good practice. However, consider standardizing the conditions under whicherror['alert']
is set toTrue
orFalse
to ensure consistency across different types of errors.The function updates the
ImportLog
with error details, which is crucial for debugging. Ensure that theImportLog
model has appropriate fields to store all necessary error information and that this information is easily accessible for troubleshooting.Consider adding unit tests specifically for
handle_import_exceptions_v2
to verify that it behaves as expected for different types of exceptions. This can help ensure robustness and ease future maintenance.Verify coverage of all relevant exceptions and clarity of error messages.
Standardize conditions for setting
error['alert']
.Ensure the
ImportLog
model adequately supports error logging.Add unit tests for
handle_import_exceptions_v2
.