-
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.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 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,63 @@ | ||
from datetime import datetime | ||
from typing import List | ||
|
||
from fyle_accounting_mappings.models import DestinationAttribute | ||
|
||
from apps.mappings.imports.modules.base import Base | ||
|
||
|
||
class Project(Base): | ||
""" | ||
Class for Project module | ||
""" | ||
|
||
def __init__(self, workspace_id: int, destination_field: str, sync_after: datetime): | ||
super().__init__( | ||
workspace_id=workspace_id, | ||
source_field="PROJECT", | ||
destination_field=destination_field, | ||
platform_class_name="projects", | ||
sync_after=sync_after, | ||
) | ||
|
||
def trigger_import(self): | ||
""" | ||
Trigger import for Project module | ||
""" | ||
self.check_import_log_and_start_import() | ||
|
||
def construct_fyle_payload( | ||
self, | ||
paginated_destination_attributes: List[DestinationAttribute], | ||
existing_fyle_attributes_map: object, | ||
is_auto_sync_status_allowed: bool | ||
): | ||
""" | ||
Construct Fyle payload for Project module | ||
:param paginated_destination_attributes: List of paginated destination attributes | ||
:param existing_fyle_attributes_map: Existing Fyle attributes map | ||
:param is_auto_sync_status_allowed: Is auto sync status allowed | ||
:return: Fyle payload | ||
""" | ||
payload = [] | ||
|
||
for attribute in paginated_destination_attributes: | ||
project = { | ||
'name': attribute.value, | ||
'code': attribute.destination_id, | ||
'description': 'Sage 300 Project - {0}, Id - {1}'.format( | ||
attribute.value, | ||
attribute.destination_id | ||
), | ||
'is_enabled': True if attribute.active is None else attribute.active | ||
} | ||
|
||
# Create a new project if it does not exist in Fyle | ||
if attribute.value.lower() not in existing_fyle_attributes_map: | ||
payload.append(project) | ||
# Disable the existing project in Fyle if auto-sync status is allowed and the destination_attributes is inactive | ||
elif is_auto_sync_status_allowed and not attribute.active: | ||
project['id'] = existing_fyle_attributes_map[attribute.value.lower()] | ||
payload.append(project) | ||
|
||
return payload |
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