Skip to content

Commit

Permalink
Custom Fields and Custom Records Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Shwetabhk authored Oct 15, 2020
1 parent 2d78e04 commit 7545b40
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 6 deletions.
18 changes: 18 additions & 0 deletions netsuitesdk/api/custom_lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .base import ApiBase
import logging

logger = logging.getLogger(__name__)


class CustomLists(ApiBase):
def __init__(self, ns_client):
ApiBase.__init__(self, ns_client=ns_client, type_name='CustomList')

def get_all(self):
return self._get_all()

def get_all_generator(self, page_size=20):
"""
Returns a generator which is more efficient memory-wise
"""
return self._get_all_generator()
20 changes: 20 additions & 0 deletions netsuitesdk/api/custom_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from netsuitesdk.internal.utils import PaginatedSearch

from .base import ApiBase
import logging

logger = logging.getLogger(__name__)


class CustomRecords(ApiBase):
def __init__(self, ns_client):
ApiBase.__init__(self, ns_client=ns_client, type_name='CustomRecordType')

def get_all_by_id(self, internalId):
cr_type = self.ns_client.CustomRecordSearchBasic(
recType=self.ns_client.CustomRecordType(
internalId=internalId
)
)
ps = PaginatedSearch(client=self.ns_client, type_name='CustomRecordType', search_record=cr_type, pageSize=20)
return list(self._paginated_search_to_generator(paginated_search=ps))
10 changes: 10 additions & 0 deletions netsuitesdk/api/expense_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def post(self, data) -> OrderedDict:
value=field['value']
)
)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
)
)
)
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
ere = self.ns_client.ExpenseReportExpense(**eod)
expense_list.append(ere)
Expand Down
10 changes: 10 additions & 0 deletions netsuitesdk/api/journal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def post(self, data) -> OrderedDict:
value=field['value']
)
)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
)
)
)
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
jee = self.ns_client.JournalEntryLine(**eod)
line_list.append(jee)
Expand Down
10 changes: 10 additions & 0 deletions netsuitesdk/api/vendor_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def post(self, data) -> OrderedDict:
value=field['value']
)
)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
)
)
)
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
vbe = self.ns_client.VendorBillExpense(**eod)
expense_list.append(vbe)
Expand Down
5 changes: 5 additions & 0 deletions netsuitesdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .api.folders import Folders
from .api.files import Files
from .api.expense_categories import ExpenseCategory
from .api.custom_lists import CustomLists
from .api.custom_records import CustomRecords
from .internal.client import NetSuiteClient


Expand All @@ -24,6 +26,7 @@ def __init__(self, account, consumer_key, consumer_secret, token_key, token_secr
token_key=token_key,
token_secret=token_secret
)
self.client = ns_client
self.accounts = Accounts(ns_client)
self.classifications = Classifications(ns_client)
self.departments = Departments(ns_client)
Expand All @@ -38,3 +41,5 @@ def __init__(self, account, consumer_key, consumer_secret, token_key, token_secr
self.folders = Folders(ns_client)
self.files = Files(ns_client)
self.expense_categories = ExpenseCategory(ns_client)
self.custom_lists = CustomLists(ns_client)
self.custom_records = CustomRecords(ns_client)
1 change: 1 addition & 0 deletions netsuitesdk/internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def get(self, recordType, internalId=None, externalId=None):
record_ref = self.RecordRef(type=recordType, externalId=externalId)
else:
raise ValueError('Either internalId or externalId is necessary to make a get request.')

response = self.request('get', baseRef=record_ref)
response = response.body.readResponse

Expand Down
23 changes: 18 additions & 5 deletions netsuitesdk/internal/netsuite_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'Passport',
'RecordList',
'RecordRef',
'ListOrRecordRef',
'SearchResult',
'SearchStringField',
'SearchMultiSelectField',
Expand All @@ -20,7 +21,9 @@
'TokenPassportSignature',
'WsRole',
'CustomFieldList',
'StringCustomFieldRef'
'StringCustomFieldRef',
'CustomRecordRef',
'SelectCustomFieldRef'
],

# ns4: https://webservices.netsuite.com/xsd/platform/v2017_2_0/messages.xsd
Expand All @@ -46,7 +49,9 @@
'SubsidiarySearchBasic',
'EmployeeSearchBasic',
'FolderSearchBasic',
'FileSearchBasic'
'FileSearchBasic',
'CustomRecordSearchBasic',
'CustomListSearchBasic'
],

# urn:relationships.lists.webservices.netsuite.com
Expand All @@ -65,11 +70,11 @@
'Department', 'DepartmentSearch',
'Location', 'LocationSearch',
'Subsidiary', 'SubsidiarySearch',
'VendorCategory', 'VendorCategorySearch',
'VendorCategory', 'VendorCategorySearch'
],

'ns19': [
'TransactionSearch',
'TransactionSearch'
],

# urn:purchases_2017_2.transactions.webservices.netsuite.com
Expand All @@ -91,9 +96,17 @@
'JournalEntryLineList',
],

'ns32': [
'CustomRecord',
'CustomRecordCustomField',
'CustomRecordSearch',
'CustomListSearch',
'CustomRecordType'
],

# https://webservices.netsuite.com/xsd/lists/v2019_2_0/employees.xsd
'ns34': [
'EmployeeSearch',
'EmployeeSearch'
],

# urn:employees_2019_2.transactions.webservices.netsuite.com
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='netsuitesdk',
version='1.7.1',
version='1.8.0',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down

0 comments on commit 7545b40

Please sign in to comment.