-
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.
Import Standard Cost Code, Standard Category as Cost Center
- Loading branch information
Showing
6 changed files
with
133 additions
and
4 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
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,57 @@ | ||
from datetime import datetime | ||
from typing import List | ||
from apps.mappings.imports.modules.base import Base | ||
from fyle_accounting_mappings.models import DestinationAttribute | ||
|
||
|
||
class CostCenter(Base): | ||
""" | ||
Class for Cost Center module | ||
""" | ||
|
||
def __init__(self, workspace_id: int, destination_field: str, sync_after: datetime): | ||
super().__init__( | ||
workspace_id=workspace_id, | ||
source_field="COST_CENTER", | ||
destination_field=destination_field, | ||
platform_class_name="cost_centers", | ||
sync_after=sync_after, | ||
) | ||
|
||
def trigger_import(self): | ||
""" | ||
Trigger import for Cost Center 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 CostCenter 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: | ||
cost_center = { | ||
'name': attribute.value, | ||
'code': attribute.destination_id, | ||
'is_enabled': True if attribute.active is None else attribute.active, | ||
'description': 'Cost Center - {0}, Id - {1}'.format( | ||
attribute.value, | ||
attribute.destination_id | ||
) | ||
} | ||
|
||
# Create a new cost-center if it does not exist in Fyle | ||
if attribute.value.lower() not in existing_fyle_attributes_map: | ||
payload.append(cost_center) | ||
|
||
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
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
21 changes: 21 additions & 0 deletions
21
tests/test_mappings/test_imports/test_modules/test_cost_centers.py
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,21 @@ | ||
from apps.mappings.imports.modules.cost_centers import CostCenter | ||
from fyle_accounting_mappings.models import DestinationAttribute | ||
from .fixtures import data | ||
|
||
|
||
def test_construct_fyle_payload(api_client, test_connection, mocker, create_temp_workspace, add_sage300_creds, add_fyle_credentials, add_cost_center_mappings): | ||
cost_center = CostCenter(1, 'COST_CENTER', None) | ||
|
||
# create new case | ||
paginated_destination_attributes = DestinationAttribute.objects.filter(workspace_id=1, attribute_type='COST_CENTER') | ||
|
||
existing_fyle_attributes_map = {} | ||
is_auto_sync_status_allowed = cost_center.get_auto_sync_permission() | ||
|
||
fyle_payload = cost_center.construct_fyle_payload( | ||
paginated_destination_attributes, | ||
existing_fyle_attributes_map, | ||
is_auto_sync_status_allowed | ||
) | ||
|
||
assert fyle_payload == data['create_fyle_cost_center_payload_create_new_case'] |