Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added limits to attributes #564

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions apps/sage_intacct/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ def is_sync_allowed(self, attribute_type: str, attribute_count: int):
Returns:
bool: True
"""
workspace_created_at = Workspace.objects.get(id=self.workspace_id).created_at
if workspace_created_at > timezone.make_aware(datetime(2024, 10, 1), timezone.get_current_timezone()) and attribute_count > SYNC_UPPER_LIMIT[attribute_type]:
return False
if attribute_count > SYNC_UPPER_LIMIT[attribute_type]:
workspace_created_at = Workspace.objects.get(id=self.workspace_id).created_at
print(workspace_created_at)
if workspace_created_at > timezone.make_aware(datetime(2024, 10, 1), timezone.get_current_timezone()):
return False
else:
return True

return True

Expand Down Expand Up @@ -381,14 +385,14 @@ def sync_projects(self):
'detail': detail
})

DestinationAttribute.bulk_create_or_update_destination_attributes(
project_attributes,
'PROJECT',
self.workspace_id,
True,
attribute_disable_callback_path=self.get_disable_attribute_callback_func('PROJECT'),
is_import_to_fyle_enabled=is_project_import_enabled
)
DestinationAttribute.bulk_create_or_update_destination_attributes(
project_attributes,
'PROJECT',
self.workspace_id,
True,
attribute_disable_callback_path=self.get_disable_attribute_callback_func('PROJECT'),
is_import_to_fyle_enabled=is_project_import_enabled
)

return []

Expand Down Expand Up @@ -419,8 +423,8 @@ def sync_items(self):
'active': True
})

DestinationAttribute.bulk_create_or_update_destination_attributes(
item_attributes, 'ITEM', self.workspace_id, True)
DestinationAttribute.bulk_create_or_update_destination_attributes(
item_attributes, 'ITEM', self.workspace_id, True)

return []

Expand Down Expand Up @@ -647,6 +651,7 @@ def sync_classes(self):
Get classes
"""
attribute_count = self.connection.classes.count()
print(attribute_count)
if not self.is_sync_allowed(attribute_type = 'classes', attribute_count = attribute_count):
logger.info('Skipping sync of classes for workspace %s as it has %s counts which is over the limit', self.workspace_id, attribute_count)
return
Expand All @@ -665,8 +670,8 @@ def sync_classes(self):
'active': True
})

DestinationAttribute.bulk_create_or_update_destination_attributes(
class_attributes, 'CLASS', self.workspace_id, True)
DestinationAttribute.bulk_create_or_update_destination_attributes(
class_attributes, 'CLASS', self.workspace_id, True)

return []

Expand Down Expand Up @@ -694,8 +699,8 @@ def sync_customers(self):
'active': True
})

DestinationAttribute.bulk_create_or_update_destination_attributes(
customer_attributes, 'CUSTOMER', self.workspace_id, True)
DestinationAttribute.bulk_create_or_update_destination_attributes(
customer_attributes, 'CUSTOMER', self.workspace_id, True)

return []

Expand Down
37 changes: 37 additions & 0 deletions tests/test_sageintacct/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
import json
from datetime import datetime
import pytest
import logging
from unittest import mock
Expand Down Expand Up @@ -930,3 +931,39 @@ def mock_allocations_generator(field, value, updated_at=None):
assert set(allocation_attribute.detail.keys()) == {'LOCATIONID'}
else:
assert set(allocation_attribute.detail.keys()) == {'LOCATIONID', 'GLDIMWHAT_IS_NILESH_PANT'}


def test_skip_sync_attributes(mocker, db):
workspace_id = 1

mocker.patch(
'sageintacctsdk.apis.Classes.count',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as netsuite

return_value=2000
)

mocker.patch(
'sageintacctsdk.apis.Projects.count',
return_value=30000
)

intacct_credentials = SageIntacctCredential.objects.get(workspace_id=workspace_id)
sage_intacct_connection = SageIntacctConnector(credentials_object=intacct_credentials, workspace_id=workspace_id)

today = datetime.today()
Workspace.objects.filter(id=workspace_id).update(created_at=today)

class_count = DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='CLASS').count()
assert class_count == 6

sage_intacct_connection.sync_classes()

new_class_count = DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='CLASS').count()
assert new_class_count == 6

project_count = DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='PROJECT').count()
assert project_count == 16

sage_intacct_connection.sync_projects()

project_count = DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='PROJECT').count()
assert project_count == 16
Loading