Skip to content

Commit

Permalink
Adding check for tranDate in bills, journals and expense reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Sravanksk authored Oct 1, 2020
1 parent f19e7b6 commit 2d78e04
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ def connect_tba():
NS_CONSUMER_SECRET = os.getenv('NS_CONSUMER_SECRET')
NS_TOKEN_KEY = os.getenv('NS_TOKEN_KEY')
NS_TOKEN_SECRET = os.getenv('NS_TOKEN_SECRET')
nc = NetSuiteConnection(account=NS_ACCOUNT, consumer_key=NS_CONSUMER_KEY, consumer_secret=NS_CONSUMER_SECRET, token_key=NS_TOKEN_KEY, token_secret=NS_TOKEN_SECRET)
nc = NetSuiteConnection(
account=NS_ACCOUNT,
consumer_key=NS_CONSUMER_KEY,
consumer_secret=NS_CONSUMER_SECRET,
token_key=NS_TOKEN_KEY,
token_secret=NS_TOKEN_SECRET
)
return nc

nc = connect_tba()
Expand All @@ -53,6 +59,8 @@ locations = nc.locations.get_all()
departments = nc.departments.get_all()
classifications = nc.classifications.get_all()
subsidiaries = nc.subsidiaries.get_all()
expense_categories = nc.expense_categories.get_all()
employees = nc.employees.get_all()
all_accounts = list(itertools.islice(nc.accounts.get_all_generator(), 100))
accounts = [a for a in all_accounts if a['acctType'] == '_expense']
vendor_bills = list(itertools.islice(nc.vendor_bills.get_all_generator(), 10))
Expand All @@ -66,7 +74,9 @@ data = {
'currencies': currencies,
'vendors': vendors,
'vendor_bills': vendor_bills,
'subsidiaries': subsidiaries
'subsidiaries': subsidiaries,
'expense_categories': expense_categories,
'employees': employees
}
with open('/tmp/netsuite.json', 'w') as oj:
oj.write(json.dumps(data, default=str, indent=2))
Expand All @@ -78,10 +88,16 @@ for c in nc.currencies.get_all_generator():
# Get a specific object
nc.currencies.get(internalId='1')

# Post operation is only supported on vendor_bills currently (see test_vendor_bills.py on how to construct vendor bill)
# Post operation is only supported on vendor_bills, expense_reports and journal_entries currently (see tests on how to construct vendor bill, expense report and journal entry)
vb = {...}
nc.vendor_bills.post(vb)

er = {...}
nc.expense_reports.post(er)

je = {...}
nc.journal_entries.post(je)

### Upsert Files
file = open('receipt.pdf', 'rb').read()

Expand Down
3 changes: 3 additions & 0 deletions netsuitesdk/api/expense_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def post(self, data) -> OrderedDict:
if 'memo' in data:
er['memo'] = data['memo']

if 'tranDate' in data:
er['tranDate'] = data['tranDate']

if 'tranId' in data:
er['tranId'] = data['tranId']

Expand Down
3 changes: 3 additions & 0 deletions netsuitesdk/api/journal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def post(self, data) -> OrderedDict:
if 'memo' in data:
je['memo'] = data['memo']

if 'tranDate' in data:
je['tranDate'] = data['tranDate']

if 'tranId' in data:
je['tranId'] = data['tranId']

Expand Down
17 changes: 11 additions & 6 deletions netsuitesdk/api/vendor_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

logger = logging.getLogger(__name__)


class VendorBills(ApiBase):
"""
VendorBills are not directly searchable - only via as transactions
"""

def __init__(self, ns_client):
ApiBase.__init__(self, ns_client=ns_client, type_name='vendorBill')

def get_all_generator(self):
record_type_search_field = self.ns_client.SearchStringField(searchValue='VendorBill', operator='contains')
basic_search = self.ns_client.basic_search_factory('Transaction', recordType=record_type_search_field)
paginated_search = PaginatedSearch(client=self.ns_client,
type_name='Transaction',
basic_search=basic_search,
pageSize=20)
type_name='Transaction',
basic_search=basic_search,
pageSize=20)
return self._paginated_search_to_generator(paginated_search=paginated_search)

def post(self, data) -> OrderedDict:
assert data['externalId'], 'missing external id'
vb = self.ns_client.VendorBill(externalId=data['externalId'])
Expand All @@ -50,6 +52,9 @@ def post(self, data) -> OrderedDict:
if 'memo' in data:
vb['memo'] = data['memo']

if 'tranDate' in data:
vb['tranDate'] = data['tranDate']

if 'tranId' in data:
vb['tranId'] = data['tranId']

Expand All @@ -68,4 +73,4 @@ def post(self, data) -> OrderedDict:
vb['entity'] = self.ns_client.RecordRef(**(data['entity']))
logger.debug('able to create vb = %s', vb)
res = self.ns_client.upsert(vb)
return self._serialize(res)
return self._serialize(res)
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.0',
version='1.7.1',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down

0 comments on commit 2d78e04

Please sign in to comment.