-
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.
Removed dead code, add few test cases, added script for adding new sc…
…hedule for different workspaces
- Loading branch information
1 parent
b7c3ac3
commit af2b90f
Showing
18 changed files
with
8,048 additions
and
620 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
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,40 @@ | ||
from django.db import transaction | ||
from django_q.models import Schedule | ||
|
||
|
||
existing_import_schedules = ( | ||
Schedule.objects.filter( | ||
func__in=[ | ||
'apps.mappings.tasks.auto_import_and_map_fyle_fields', | ||
'apps.mappings.tasks.auto_create_tax_codes_mappings', | ||
'apps.mappings.tasks.async_auto_create_custom_field_mappings', | ||
'apps.mappings.tasks.auto_create_cost_center_mappings' | ||
] | ||
).values('args').distinct() | ||
) | ||
|
||
try: | ||
with transaction.atomic(): | ||
for schedule in existing_import_schedules: | ||
workspace_id = schedule['args'] | ||
|
||
is_new_schedule_created = Schedule.objects.filter( | ||
func='apps.mappings.queue.construct_tasks_and_chain_import_fields_to_fyle', | ||
args=workspace_id | ||
).exists() | ||
|
||
if not is_new_schedule_created: | ||
old_schedule = Schedule.objects.filter( | ||
args=workspace_id | ||
).first() | ||
|
||
Schedule.objects.create( | ||
func='apps.mappings.queue.construct_tasks_and_chain_import_fields_to_fyle', | ||
args=workspace_id, | ||
schedule_type=Schedule.MINUTES, | ||
minutes=24 * 60, | ||
next_run=old_schedule.next_run | ||
) | ||
|
||
except Exception as e: | ||
print('Error:', e) |
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,71 @@ | ||
import pytest | ||
|
||
from apps.workspaces.models import Workspace, XeroCredentials, FyleCredential | ||
from fyle_accounting_mappings.models import ( | ||
ExpenseAttribute, | ||
DestinationAttribute, | ||
Mapping | ||
) | ||
from apps.mappings.models import TenantMapping | ||
|
||
|
||
@pytest.fixture | ||
def create_temp_workspace(db): | ||
workspace_id = 3 | ||
Workspace.objects.create( | ||
id=workspace_id, | ||
name="Fyle for Hrishabh Testing", | ||
fyle_org_id="Testing123", | ||
xero_short_code="xero123", | ||
last_synced_at=None, | ||
source_synced_at=None, | ||
destination_synced_at=None, | ||
xero_accounts_last_synced_at=None | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def add_xero_credentials(db, create_temp_workspace): | ||
workspace_id = 3 | ||
XeroCredentials.objects.create( | ||
workspace_id=workspace_id, | ||
refresh_token="refresh_token", | ||
is_expired=False, | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def add_fyle_credentials(db): | ||
workspace_id = 3 | ||
|
||
FyleCredential.objects.create( | ||
refresh_token="refresh_token", | ||
workspace_id=workspace_id, | ||
cluster_domain="https://staging.fyle.tech", | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def add_tenant_mapping(db, create_temp_workspace): | ||
workspace = Workspace.objects.filter(id = 3).first() | ||
|
||
tenant_mapping = TenantMapping( | ||
tenant_name="sample", tenant_id="wertyui", workspace=workspace | ||
) | ||
tenant_mapping.save() | ||
|
||
|
||
@pytest.fixture | ||
def create_project_mapping(db, create_temp_workspace): | ||
workspace_id = 3 | ||
expense_attribute = ExpenseAttribute.objects.create(attribute_type='PROJECT', display_name='project', value='Concrete', source_id='src123', workspace_id=workspace_id, active=True) | ||
destination_attribute = DestinationAttribute.objects.create(attribute_type='CUSTOMER', display_name='customer', value='Concrete', destination_id='dest123', workspace_id=workspace_id, active=True) | ||
Mapping.objects.create(source_type='PROJECT', destination_type='CUSTOMER', destination_id=destination_attribute.id, source_id=expense_attribute.id, workspace_id=workspace_id) | ||
|
||
|
||
@pytest.fixture | ||
def create_category_mapping(db, create_temp_workspace): | ||
workspace_id = 3 | ||
expense_attribute = ExpenseAttribute.objects.create(attribute_type='CATEGORY', display_name='category', value='Concrete', source_id='src123', workspace_id=workspace_id, active=True) | ||
destination_attribute = DestinationAttribute.objects.create(attribute_type='ACCOUNT', display_name='account', value='Concrete', destination_id='dest123', workspace_id=workspace_id, active=True) | ||
Mapping.objects.create(source_type='CATEGORY', destination_type='ACCOUNT', destination_id=destination_attribute.id, source_id=expense_attribute.id, workspace_id=workspace_id) |
Oops, something went wrong.