-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Netsuite SDK support for Journal Entries
- Loading branch information
Showing
9 changed files
with
318 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from collections import OrderedDict | ||
from netsuitesdk.internal.utils import PaginatedSearch | ||
|
||
from .base import ApiBase | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JournalEntries(ApiBase): | ||
def __init__(self, ns_client): | ||
ApiBase.__init__(self, ns_client=ns_client, type_name='journalEntry') | ||
|
||
def get_all_generator(self): | ||
record_type_search_field = self.ns_client.SearchStringField(searchValue='JournalEntry', 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) | ||
return self._paginated_search_to_generator(paginated_search=paginated_search) | ||
|
||
def post(self, data) -> OrderedDict: | ||
assert data['externalId'], 'missing external id' | ||
je = self.ns_client.JournalEntry(externalId=data['externalId']) | ||
line_list = [] | ||
for eod in data['lineList']: | ||
jee = self.ns_client.JournalEntryLine(**eod) | ||
line_list.append(jee) | ||
|
||
je['lineList'] = self.ns_client.JournalEntryLineList(line=line_list) | ||
je['currency'] = self.ns_client.RecordRef(**(data['currency'])) | ||
|
||
if 'memo' in data: | ||
je['memo'] = data['memo'] | ||
|
||
if 'tranId' in data: | ||
je['tranId'] = data['tranId'] | ||
|
||
if 'subsidiary' in data: | ||
je['subsidiary'] = data['subsidiary'] | ||
|
||
if 'class' in data: | ||
je['class'] = data['class'] | ||
|
||
if 'location' in data: | ||
je['location'] = data['location'] | ||
|
||
if 'department' in data: | ||
je['department'] = data['department'] | ||
|
||
logger.debug('able to create je = %s', je) | ||
res = self.ns_client.upsert(je) | ||
return self._serialize(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name='netsuitesdk', | ||
version='1.4.0', | ||
version='1.5.0', | ||
author='Siva Narayanan', | ||
author_email='[email protected]', | ||
description='Python SDK for accessing the NetSuite SOAP webservice', | ||
|
154 changes: 154 additions & 0 deletions
154
test/integration/data/journal_entries/tstdrv2089588.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
"accountingBook": null, | ||
"accountingBookDetailList": null, | ||
"approved": null, | ||
"class": null, | ||
"createdDate": null, | ||
"createdFrom": null, | ||
"currency": { | ||
"name": "USD", | ||
"internalId": null, | ||
"externalId": null, | ||
"type": "currency" | ||
}, | ||
"customFieldList": null, | ||
"customForm": null, | ||
"department": null, | ||
"exchangeRate": null, | ||
"isBookSpecific": null, | ||
"lastModifiedDate": null, | ||
"lineList": [ | ||
{ | ||
"account": { | ||
"name": null, | ||
"internalId": "25", | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"department": { | ||
"name": null, | ||
"internalId": "10", | ||
"externalId": null, | ||
"type": "department" | ||
}, | ||
"location": { | ||
"name": null, | ||
"internalId": "2", | ||
"externalId": null, | ||
"type": "location" | ||
}, | ||
"class": { | ||
"name": null, | ||
"internalId": null, | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"entity": { | ||
"name": null, | ||
"internalId": "1648", | ||
"externalId": null, | ||
"type": "vendor" | ||
}, | ||
"credit": 500, | ||
"creditTax": null, | ||
"customFieldList": null, | ||
"debit": null, | ||
"debitTax": null, | ||
"eliminate": null, | ||
"endDate": null, | ||
"grossAmt": null, | ||
"line": null, | ||
"lineTaxCode": null, | ||
"lineTaxRate": null, | ||
"memo": "Testing JournalEntry via Fyle SDK 3", | ||
"residual": null, | ||
"revenueRecognitionRule": null, | ||
"schedule": null, | ||
"scheduleNum": null, | ||
"startDate": null, | ||
"tax1Acct": null, | ||
"tax1Amt": null, | ||
"taxAccount": null, | ||
"taxBasis": null, | ||
"taxCode": null, | ||
"taxRate1": null, | ||
"totalAmount": null | ||
}, | ||
{ | ||
"account": { | ||
"name": null, | ||
"internalId": "25", | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"department": { | ||
"name": null, | ||
"internalId": "10", | ||
"externalId": null, | ||
"type": "department" | ||
}, | ||
"location": { | ||
"name": null, | ||
"internalId": "2", | ||
"externalId": null, | ||
"type": "location" | ||
}, | ||
"class": { | ||
"name": null, | ||
"internalId": null, | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"credit": null, | ||
"creditTax": null, | ||
"customFieldList": null, | ||
"debit": 500, | ||
"debitTax": null, | ||
"eliminate": null, | ||
"endDate": null, | ||
"entity": { | ||
"name": null, | ||
"internalId": "1648", | ||
"externalId": null, | ||
"type": "vendor" | ||
}, | ||
"grossAmt": null, | ||
"line": null, | ||
"lineTaxCode": null, | ||
"lineTaxRate": null, | ||
"memo": "Testing JournalEntry via Fyle SDK 3", | ||
"residual": null, | ||
"revenueRecognitionRule": null, | ||
"schedule": null, | ||
"scheduleNum": null, | ||
"startDate": null, | ||
"tax1Acct": null, | ||
"tax1Amt": null, | ||
"taxAccount": null, | ||
"taxBasis": null, | ||
"taxCode": null, | ||
"taxRate1": null, | ||
"totalAmount": null | ||
} | ||
], | ||
"location": null, | ||
"memo": "JE Testing Fyle SDK 3", | ||
"nexus": null, | ||
"parentExpenseAlloc": null, | ||
"postingPeriod": null, | ||
"reversalDate": null, | ||
"reversalDefer": null, | ||
"reversalEntry": null, | ||
"subsidiary": { | ||
"name": null, | ||
"internalId": "1", | ||
"externalId": null, | ||
"type": "subsidiary" | ||
}, | ||
"subsidiaryTaxRegNum": null, | ||
"taxPointDate": null, | ||
"toSubsidiary": null, | ||
"tranDate": null, | ||
"tranId": null, | ||
"externalId": "JE_04" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
import pytest | ||
import json | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def test_get(nc): | ||
data = next(nc.journal_entries.get_all_generator()) | ||
logger.debug('data = %s', data) | ||
assert data, 'get all generator didnt work' | ||
assert data['internalId'] == '16', f'No object found with internalId' | ||
|
||
data = nc.journal_entries.get(externalId='JE_04') | ||
logger.debug('data = %s', data) | ||
currency = data['currency'] | ||
assert data, f'No object with externalId' | ||
assert data['internalId'] == '10512', f'No object with internalId' | ||
assert data['externalId'] == 'JE_04', f'No object with externalId' | ||
assert currency['name'] == 'USA', f'Currency does not match' | ||
|
||
def test_post(nc): | ||
filename = os.getenv('NS_ACCOUNT').lower() + '.json' | ||
with open('./test/integration/data/journal_entries/' + filename) as oj: | ||
s = oj.read() | ||
je1 = json.loads(s) | ||
logger.debug('rvb1 = %s', je1) | ||
res = nc.journal_entries.post(je1) | ||
logger.debug('res = %s', res) | ||
assert res['externalId'] == je1['externalId'], 'External ID does not match' | ||
assert res['type'] == 'journalEntry', 'Type does not match' | ||
|
||
je2 = nc.journal_entries.get(externalId=res['externalId']) | ||
currency = je2['currency'] | ||
assert je2['internalId'] == '10512', f'No object with internalId' | ||
assert je2['externalId'] == 'JE_04', f'No object with externalId' | ||
assert currency['name'] == 'USA', f'Currency does not match' | ||
|
||
logger.debug('je2 = %s', je2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters