-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.py
55 lines (44 loc) · 1.84 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from datetime import datetime, timedelta, timezone
from apps.mappings.models import ImportLog
from apps.workspaces.models import Configuration
from apps.mappings.imports.schedules import schedule_or_delete_fyle_import_tasks as new_schedule_or_delete_fyle_import_tasks
from apps.mappings.tasks import (
schedule_auto_map_employees,
schedule_auto_map_charge_card_employees
)
def schedule_or_delete_auto_mapping_tasks(configuration: Configuration) -> None:
"""
:param configuration: Workspace Configuration Instance
:return: None
"""
new_schedule_or_delete_fyle_import_tasks(configuration)
schedule_auto_map_employees(
employee_mapping_preference=configuration.auto_map_employees, workspace_id=int(configuration.workspace_id))
if not configuration.auto_map_employees:
schedule_auto_map_charge_card_employees(workspace_id=int(configuration.workspace_id))
def prepend_code_to_name(prepend_code_in_name: bool, value: str, code: str = None) -> str:
"""
Format the attribute name based on the use_code_in_naming flag
:param prepend_code_in_name: Boolean flag to prepend code in name
:param value: Value of the attribute
:param code: Code of the attribute
:return: Formatted attribute name
"""
if prepend_code_in_name and code:
return "{}: {}".format(code, value)
return value
def is_project_sync_allowed(import_log: ImportLog = None) -> bool:
"""
Check if job sync is allowed
:param import_log: Import Log Instance
:return: Boolean
"""
time_difference = datetime.now(timezone.utc) - timedelta(minutes=30)
time_difference = time_difference.replace(tzinfo=timezone.utc)
if (
not import_log
or import_log.last_successful_run_at is None
or import_log.last_successful_run_at < time_difference
):
return True
return False