Skip to content

Commit

Permalink
feat: Add generators in syncing dimensions (#638)
Browse files Browse the repository at this point in the history
* Add generators in syncing dimensions

* resolved tests

* comment resolved
  • Loading branch information
Ashutosh619-sudo committed Oct 1, 2024
1 parent 87b2cbc commit dd737ef
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 72 deletions.
138 changes: 71 additions & 67 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -519,81 +519,84 @@ 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',
'value': location['name'],
'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 []

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 []

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 []

Expand Down Expand Up @@ -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 []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_netsuite/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6561,7 +6561,7 @@
"externalId": "report 1057 - [email protected]",
"internalId": "76115"
},
'get_all_locations': [
'get_all_locations': [[
{
'nullFieldList': None,
'name': '02: Boston Gaon',
Expand Down Expand Up @@ -6764,7 +6764,7 @@
'customFieldList': None,
'internalId': '5',
'externalId': None
}],
}]],
'get_all_currencies': [
[OrderedDict([('nullFieldList', None),
('name', 'USA PEW S A'),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_netsuite/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dd737ef

Please sign in to comment.