Skip to content

Commit

Permalink
Fix: Constructor Params for Searching Body Fields and Page Size (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shwetabhk authored Feb 2, 2021
1 parent 85b5c82 commit 2fd50b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dry_run.py
# IDEs
.DS_Store

# Folders
test_scripts/

# cache file
cache.db

Expand Down
14 changes: 6 additions & 8 deletions netsuitesdk/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ def _paginated_search_to_generator(self, paginated_search):
logger.debug('going to page %d', 0)

num_records = paginated_search.num_records
for r in range(0, num_records):
record = paginated_search.records[r]
yield self._serialize(record=record)

for p in range(2, num_pages + 1):
records = []

for p in range(1, num_pages + 1):
logger.debug('going to page %d', p)
paginated_search.goto_page(p)
logger.debug(f'current page index {paginated_search.page_index}')
num_records = paginated_search.num_records
for r in range(0, num_records):
record = paginated_search.records[r]
yield self._serialize(record=record)
records.extend(paginated_search.records)

return records

def _search_all_generator(self, page_size):
ps = PaginatedSearch(client=self.ns_client, type_name=self.type_name, pageSize=page_size)
Expand Down
6 changes: 4 additions & 2 deletions netsuitesdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@


class NetSuiteConnection:
def __init__(self, account, consumer_key, consumer_secret, token_key, token_secret):
ns_client = NetSuiteClient(account=account)
def __init__(self, account, consumer_key, consumer_secret, token_key, token_secret,
search_body_fields_only=True, page_size: int = 100):
ns_client = NetSuiteClient(account=account, search_body_fields_only=search_body_fields_only,
page_size=page_size)
ns_client.connect_tba(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
Expand Down
10 changes: 6 additions & 4 deletions netsuitesdk/internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class NetSuiteClient:
_token_secret = None
_app_id = None

def __init__(self, account=None, caching=True, caching_timeout=2592000):
def __init__(self, account=None, caching=True, caching_timeout=2592000, search_body_fields_only=True,
page_size: int = 100):
"""
Initialize the Zeep SOAP client, parse the xsd specifications
of Netsuite and store the complex types as attributes of this
Expand Down Expand Up @@ -82,11 +83,12 @@ def __init__(self, account=None, caching=True, caching_timeout=2592000):

self._app_info = None
self._is_authenticated = False
self.set_search_preferences()
self.set_search_preferences(page_size=page_size, search_body_fields_only=search_body_fields_only)

def set_search_preferences(self, page_size: int = 5, return_search_columns: bool = False):
def set_search_preferences(self, page_size: int = 5, search_body_fields_only: bool = True,
return_search_columns: bool = True):
self._search_preferences = self.SearchPreferences(
bodyFieldsOnly=False,
bodyFieldsOnly=search_body_fields_only,
pageSize=page_size,
returnSearchColumns=return_search_columns
)
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.12.0',
version='1.13.0',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down

0 comments on commit 2fd50b6

Please sign in to comment.