-
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.
* auto sync chart of accounts as categories * base pr * Import Jobs as Projects * Test cases added * Flake 8 resolved * migration change * Error resolved * Test cases resolved * comets resolved * Flake8 resolve * Comments resolved --------- Co-authored-by: Nilesh Pant <[email protected]>
- Loading branch information
1 parent
ca230e9
commit 956b860
Showing
13 changed files
with
209 additions
and
8 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
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,61 @@ | ||
from datetime import datetime | ||
from typing import List | ||
from apps.mappings.imports.modules.base import Base | ||
from fyle_accounting_mappings.models import DestinationAttribute | ||
|
||
|
||
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
20 changes: 20 additions & 0 deletions
20
apps/mappings/migrations/0002_alter_importlog_workspace.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,20 @@ | ||
# Generated by Django 4.1.2 on 2023-11-02 09:05 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0002_sage300credential_importsetting_fylecredential_and_more'), | ||
('mappings', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='importlog', | ||
name='workspace', | ||
field=models.ForeignKey(help_text='Reference to Workspace model', on_delete=django.db.models.deletion.PROTECT, to='workspaces.workspace'), | ||
), | ||
] |
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
Empty file.
Empty file.
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,33 @@ | ||
data = { | ||
"create_fyle_project_payload_create_new_case": | ||
[ | ||
{ | ||
'name':'Direct Mail Campaign', | ||
'code':'10064', | ||
'description':'Sage 300 Project - Direct Mail Campaign, Id - 10064', | ||
'is_enabled':True | ||
}, | ||
{ | ||
'name':'Platform APIs', | ||
'code':'10081', | ||
'description':'Sage 300 Project - Platform APIs, Id - 10081', | ||
'is_enabled':True | ||
} | ||
|
||
], | ||
"create_fyle_project_payload_create_disable_case": | ||
[ | ||
{ | ||
'code': '10064', | ||
'description': 'Sage 300 Project - Direct Mail Campaign, Id - 10064', | ||
'is_enabled': True, | ||
'name': 'Direct Mail Campaign' | ||
}, | ||
{ | ||
'code': '10081', | ||
'description': 'Sage 300 Project - Platform APIs, Id - 10081', | ||
'is_enabled': False, | ||
'name': 'Platform APIs' | ||
} | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/test_mappings/test_imports/test_modules/test_projects.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,42 @@ | ||
from apps.mappings.imports.modules.projects import Project | ||
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_project_mappings): | ||
project = Project(1, 'PROJECT', None) | ||
|
||
# create new case | ||
paginated_destination_attributes = DestinationAttribute.objects.filter(workspace_id=1, attribute_type='PROJECT') | ||
|
||
existing_fyle_attributes_map = {} | ||
is_auto_sync_status_allowed = project.get_auto_sync_permission() | ||
|
||
fyle_payload = project.construct_fyle_payload( | ||
paginated_destination_attributes, | ||
existing_fyle_attributes_map, | ||
is_auto_sync_status_allowed | ||
) | ||
|
||
assert fyle_payload == data['create_fyle_project_payload_create_new_case'] | ||
|
||
# disable case | ||
DestinationAttribute.objects.filter( | ||
workspace_id=1, | ||
attribute_type='PROJECT', | ||
value__in=['Platform APIs'] | ||
).update(active=False) | ||
|
||
paginated_destination_attributes = DestinationAttribute.objects.filter(workspace_id=1, attribute_type='PROJECT') | ||
|
||
paginated_destination_attribute_values = [attribute.value for attribute in paginated_destination_attributes] | ||
|
||
existing_fyle_attributes_map = project.get_existing_fyle_attributes(paginated_destination_attribute_values) | ||
|
||
fyle_payload = project.construct_fyle_payload( | ||
paginated_destination_attributes, | ||
existing_fyle_attributes_map, | ||
True | ||
) | ||
|
||
assert fyle_payload == data['create_fyle_project_payload_create_disable_case'] |
Empty file.