-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ashutosh619-sudo <[email protected]>
- Loading branch information
1 parent
8af8cad
commit 078f8bd
Showing
17 changed files
with
243 additions
and
229 deletions.
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,91 @@ | ||
from django_q.models import Schedule | ||
from datetime import datetime, timedelta | ||
from fyle_accounting_mappings.models import MappingSetting | ||
|
||
|
||
def schedule_auto_map_employees(employee_mapping_preference: str, workspace_id: str): | ||
if employee_mapping_preference: | ||
Schedule.objects.update_or_create( | ||
func='apps.mappings.tasks.async_auto_map_employees', | ||
args='{}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': 24 * 60, | ||
'next_run': datetime.now() | ||
} | ||
) | ||
else: | ||
schedule: Schedule = Schedule.objects.filter( | ||
func='apps.mappings.tasks.async_auto_map_employees', | ||
args='{}'.format(workspace_id) | ||
).first() | ||
|
||
if schedule: | ||
schedule.delete() | ||
|
||
|
||
def schedule_cost_centers_creation(import_to_fyle, workspace_id: int): | ||
if import_to_fyle: | ||
schedule, _ = Schedule.objects.update_or_create( | ||
func='apps.mappings.tasks.auto_create_cost_center_mappings', | ||
args='{}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': 24 * 60, | ||
'next_run': datetime.now() | ||
} | ||
) | ||
else: | ||
schedule: Schedule = Schedule.objects.filter( | ||
func='apps.mappings.tasks.auto_create_cost_center_mappings', | ||
args='{}'.format(workspace_id) | ||
).first() | ||
|
||
if schedule: | ||
schedule.delete() | ||
|
||
|
||
def schedule_tax_groups_creation(import_tax_codes, workspace_id): | ||
if import_tax_codes: | ||
schedule, _ = Schedule.objects.update_or_create( | ||
func='apps.mappings.tasks.auto_create_tax_codes_mappings', | ||
args='{}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': 24 * 60, | ||
'next_run': datetime.now() | ||
} | ||
) | ||
else: | ||
schedule: Schedule = Schedule.objects.filter( | ||
func='apps.mappings.tasks.auto_create_tax_codes_mappings', | ||
args='{}'.format(workspace_id), | ||
).first() | ||
|
||
if schedule: | ||
schedule.delete() | ||
|
||
|
||
def schedule_fyle_attributes_creation(workspace_id: int): | ||
mapping_settings = MappingSetting.objects.filter( | ||
is_custom=True, import_to_fyle=True, workspace_id=workspace_id | ||
).all() | ||
|
||
if mapping_settings: | ||
schedule, _ = Schedule.objects.get_or_create( | ||
func='apps.mappings.tasks.async_auto_create_custom_field_mappings', | ||
args='{0}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': 24 * 60, | ||
'next_run': datetime.now() + timedelta(hours=24) | ||
} | ||
) | ||
else: | ||
schedule: Schedule = Schedule.objects.filter( | ||
func='apps.mappings.tasks.async_auto_create_custom_field_mappings', | ||
args=workspace_id | ||
).first() | ||
|
||
if schedule: | ||
schedule.delete() |
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
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
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,66 @@ | ||
from datetime import datetime, timedelta | ||
from typing import List | ||
from django_q.models import Schedule | ||
from apps.workspaces.models import WorkspaceSchedule | ||
|
||
|
||
|
||
def schedule_email_notification(workspace_id: int, schedule_enabled: bool, hours: int): | ||
if schedule_enabled: | ||
schedule, _ = Schedule.objects.update_or_create( | ||
func='apps.workspaces.tasks.run_email_notification', | ||
args='{}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': hours * 60, | ||
'next_run': datetime.now() + timedelta(minutes=10) | ||
} | ||
) | ||
else: | ||
schedule: Schedule = Schedule.objects.filter( | ||
func='apps.workspaces.tasks.run_email_notification', | ||
args='{}'.format(workspace_id) | ||
).first() | ||
|
||
if schedule: | ||
schedule.delete() | ||
|
||
|
||
def schedule_sync(workspace_id: int, schedule_enabled: bool, hours: int, email_added: List, emails_selected: List): | ||
ws_schedule, _ = WorkspaceSchedule.objects.get_or_create( | ||
workspace_id=workspace_id | ||
) | ||
|
||
schedule_email_notification(workspace_id=workspace_id, schedule_enabled=schedule_enabled, hours=hours) | ||
|
||
if schedule_enabled: | ||
ws_schedule.enabled = schedule_enabled | ||
ws_schedule.start_datetime = datetime.now() | ||
ws_schedule.interval_hours = hours | ||
ws_schedule.emails_selected = emails_selected | ||
|
||
if email_added: | ||
ws_schedule.additional_email_options.append(email_added) | ||
|
||
schedule, _ = Schedule.objects.update_or_create( | ||
func='apps.workspaces.tasks.run_sync_schedule', | ||
args='{}'.format(workspace_id), | ||
defaults={ | ||
'schedule_type': Schedule.MINUTES, | ||
'minutes': hours * 60, | ||
'next_run': datetime.now() | ||
} | ||
) | ||
|
||
ws_schedule.schedule = schedule | ||
|
||
ws_schedule.save() | ||
|
||
elif not schedule_enabled and ws_schedule.schedule: | ||
schedule = ws_schedule.schedule | ||
ws_schedule.enabled = schedule_enabled | ||
ws_schedule.schedule = None | ||
ws_schedule.save() | ||
schedule.delete() | ||
|
||
return ws_schedule |
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
Oops, something went wrong.