diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index 015ea28d..4ca7025a 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -493,20 +493,20 @@ def sync_currencies(self): """ Sync Currencies """ - currencies = self.connection.currencies.get_all() + currencies_generator = self.connection.currencies.get_all_generator() currency_attributes = [] - for currency in currencies: - currency_attributes.append( - { - 'attribute_type': 'CURRENCY', - 'display_name': 'Currency', - 'value': currency['symbol'], - 'destination_id': currency['internalId'], - 'active': True - } - ) + for currency in currencies_generator: + currency_attributes.append( + { + 'attribute_type': 'CURRENCY', + 'display_name': 'Currency', + 'value': currency['symbol'], + 'destination_id': currency['internalId'], + 'active': True + } + ) DestinationAttribute.bulk_create_or_update_destination_attributes( currency_attributes, 'CURRENCY', self.workspace_id, True) @@ -519,17 +519,26 @@ def sync_locations(self): """ subsidiary_mapping = SubsidiaryMapping.objects.get(workspace_id=self.workspace_id) - locations = self.connection.locations.get_all() + location_generator = self.connection.locations.get_all_generator() location_attributes = [] - for location in locations: - if not location['isInactive']: - if 'subsidiaryList' in location and location['subsidiaryList']: - subsidiaries = location['subsidiaryList']['recordRef'] - counter = 0 - if subsidiaries[counter]['internalId'] == subsidiary_mapping.internal_id: - counter += 1 + for locations in location_generator: + for location in locations: + if not location['isInactive']: + if 'subsidiaryList' in location and location['subsidiaryList']: + subsidiaries = location['subsidiaryList']['recordRef'] + counter = 0 + if subsidiaries[counter]['internalId'] == subsidiary_mapping.internal_id: + counter += 1 + location_attributes.append({ + 'attribute_type': 'LOCATION', + 'display_name': 'Location', + 'value': location['name'], + 'destination_id': location['internalId'], + 'active': not location['isInactive'] + }) + else: location_attributes.append({ 'attribute_type': 'LOCATION', 'display_name': 'Location', @@ -537,17 +546,9 @@ def sync_locations(self): 'destination_id': location['internalId'], 'active': not location['isInactive'] }) - else: - location_attributes.append({ - 'attribute_type': 'LOCATION', - 'display_name': 'Location', - 'value': location['name'], - 'destination_id': location['internalId'], - 'active': not location['isInactive'] - }) - DestinationAttribute.bulk_create_or_update_destination_attributes( - location_attributes, 'LOCATION', self.workspace_id, True) + DestinationAttribute.bulk_create_or_update_destination_attributes( + location_attributes, 'LOCATION', self.workspace_id, True) return [] @@ -555,22 +556,23 @@ def sync_classifications(self): """ Sync classification """ - classifications = self.connection.classifications.get_all() + classification_generator = self.connection.classifications.get_all_generator() classification_attributes = [] - for classification in classifications: - if not classification['isInactive']: - classification_attributes.append({ - 'attribute_type': 'CLASS', - 'display_name': 'Class', - 'value': classification['name'], - 'destination_id': classification['internalId'], - 'active': not classification['isInactive'] - }) + for classifications in classification_generator: + for classification in classifications: + if not classification['isInactive']: + classification_attributes.append({ + 'attribute_type': 'CLASS', + 'display_name': 'Class', + 'value': classification['name'], + 'destination_id': classification['internalId'], + 'active': not classification['isInactive'] + }) - DestinationAttribute.bulk_create_or_update_destination_attributes( - classification_attributes, 'CLASS', self.workspace_id, True) + DestinationAttribute.bulk_create_or_update_destination_attributes( + classification_attributes, 'CLASS', self.workspace_id, True) return [] @@ -578,22 +580,23 @@ def sync_departments(self): """ Sync departments """ - departments = self.connection.departments.get_all() + department_generator = self.connection.departments.get_all_generator() department_attributes = [] - for department in departments: - if not department['isInactive']: - department_attributes.append({ - 'attribute_type': 'DEPARTMENT', - 'display_name': 'Department', - 'value': department['name'], - 'destination_id': department['internalId'], - 'active': not department['isInactive'] - }) + for departments in department_generator: + for department in departments: + if not department['isInactive']: + department_attributes.append({ + 'attribute_type': 'DEPARTMENT', + 'display_name': 'Department', + 'value': department['name'], + 'destination_id': department['internalId'], + 'active': not department['isInactive'] + }) - DestinationAttribute.bulk_create_or_update_destination_attributes( - department_attributes, 'DEPARTMENT', self.workspace_id, True) + DestinationAttribute.bulk_create_or_update_destination_attributes( + department_attributes, 'DEPARTMENT', self.workspace_id, True) return [] @@ -923,23 +926,24 @@ def sync_subsidiaries(self): """ Sync subsidiaries """ - subsidiaries = self.connection.subsidiaries.get_all() + subsidiary_generator = self.connection.subsidiaries.get_all_generator() subsidiary_attributes = [] - for subsidiary in subsidiaries: - subsidiary_attributes.append({ - 'attribute_type': 'SUBSIDIARY', - 'display_name': 'Subsidiary', - 'value': subsidiary['name'], - 'destination_id': subsidiary['internalId'], - 'detail': { - 'country': subsidiary['country'] - }, - 'active': True - }) + for subsidiaries in subsidiary_generator: + for subsidiary in subsidiaries: + subsidiary_attributes.append({ + 'attribute_type': 'SUBSIDIARY', + 'display_name': 'Subsidiary', + 'value': subsidiary['name'], + 'destination_id': subsidiary['internalId'], + 'detail': { + 'country': subsidiary['country'] + }, + 'active': True + }) - DestinationAttribute.bulk_create_or_update_destination_attributes( - subsidiary_attributes, 'SUBSIDIARY', self.workspace_id, True) + DestinationAttribute.bulk_create_or_update_destination_attributes( + subsidiary_attributes, 'SUBSIDIARY', self.workspace_id, True) return [] diff --git a/tests/test_netsuite/fixtures.py b/tests/test_netsuite/fixtures.py index 3b9233a8..79449799 100644 --- a/tests/test_netsuite/fixtures.py +++ b/tests/test_netsuite/fixtures.py @@ -6561,7 +6561,7 @@ "externalId": "report 1057 - user2@fylefornscurrency.in-255", "internalId": "76115" }, - 'get_all_locations': [ + 'get_all_locations': [[ { 'nullFieldList': None, 'name': '02: Boston Gaon', @@ -6764,7 +6764,7 @@ 'customFieldList': None, 'internalId': '5', 'externalId': None - }], + }]], 'get_all_currencies': [ [OrderedDict([('nullFieldList', None), ('name', 'USA PEW S A'), diff --git a/tests/test_netsuite/test_connector.py b/tests/test_netsuite/test_connector.py index 3c105413..9eb0ea7a 100644 --- a/tests/test_netsuite/test_connector.py +++ b/tests/test_netsuite/test_connector.py @@ -325,7 +325,7 @@ def test_sync_subsidiaries(mocker, db): def test_sync_locations(mocker, db): mocker.patch( - 'netsuitesdk.api.locations.Locations.get_all', + 'netsuitesdk.api.locations.Locations.get_all_generator', return_value=data['get_all_locations'] ) netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=49) @@ -360,7 +360,7 @@ def test_sync_departments(mocker, db): def test_sync_customers(mocker, db): mocker.patch( 'netsuitesdk.api.customers.Customers.get_all_generator', - return_value=data['get_all_projects'] + return_value=data['get_all_projects'] ) mocker.patch( @@ -405,7 +405,7 @@ def test_sync_tax_items(mocker, db): def test_sync_currencies(mocker, db): mocker.patch( - 'netsuitesdk.api.currencies.Currencies.get_all', + 'netsuitesdk.api.currencies.Currencies.get_all_generator', return_value=data['get_all_currencies'][0] ) netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=49)