Skip to content

Commit

Permalink
Import project support added
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Nov 29, 2023
1 parent f8e1314 commit da696b7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
63 changes: 63 additions & 0 deletions apps/mappings/imports/modules/projects.py
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
2 changes: 2 additions & 0 deletions apps/mappings/imports/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from apps.mappings.imports.modules.cost_centers import CostCenter
from apps.mappings.imports.modules.expense_custom_fields import ExpenseCustomField
from apps.mappings.imports.modules.merchants import Merchant
from apps.mappings.imports.modules.projects import Project
from apps.mappings.models import ImportLog

SOURCE_FIELD_CLASS_MAP = {
'CATEGORY': Category,
'MERCHANT': Merchant,
'COST_CENTER': CostCenter,
'PROJECT': Project,
}


Expand Down

0 comments on commit da696b7

Please sign in to comment.