-
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 Employees and Expense Reports
- Loading branch information
Showing
10 changed files
with
281 additions
and
2 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,9 @@ | ||
from .base import ApiBase | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Employees(ApiBase): | ||
def __init__(self, ns_client): | ||
ApiBase.__init__(self, ns_client=ns_client, type_name='Employee') |
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,63 @@ | ||
from collections import OrderedDict | ||
|
||
from .base import ApiBase | ||
import logging | ||
|
||
from netsuitesdk.internal.utils import PaginatedSearch | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ExpenseReports(ApiBase): | ||
""" | ||
ExpenseReports are not directly searchable - only via as employees | ||
""" | ||
|
||
def __init__(self, ns_client): | ||
ApiBase.__init__(self, ns_client=ns_client, type_name='ExpenseReport') | ||
|
||
def get_all_generator(self): | ||
record_type_search_field = self.ns_client.SearchStringField(searchValue='ExpenseReport', operator='contains') | ||
basic_search = self.ns_client.basic_search_factory('Employee', recordType=record_type_search_field) | ||
paginated_search = PaginatedSearch(client=self.ns_client, | ||
type_name='Employee', | ||
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' | ||
er = self.ns_client.ExpenseReport() | ||
expense_list = [] | ||
for eod in data['expenseList']: | ||
ere = self.ns_client.ExpenseReportExpense(**eod) | ||
expense_list.append(ere) | ||
|
||
er['expenseList'] = self.ns_client.ExpenseReportExpenseList(expense=expense_list) | ||
er['expenseReportCurrency'] = self.ns_client.RecordRef(**(data['expenseReportCurrency'])) | ||
|
||
if 'memo' in data: | ||
er['memo'] = data['memo'] | ||
|
||
if 'tranId' in data: | ||
er['tranId'] = data['tranId'] | ||
|
||
if 'class' in data: | ||
er['class'] = data['class'] | ||
|
||
if 'location' in data: | ||
er['location'] = data['location'] | ||
|
||
if 'department' in data: | ||
er['department'] = data['department'] | ||
|
||
if 'account' in data: | ||
er['account'] = self.ns_client.RecordRef(**(data['account'])) | ||
|
||
if 'externalId' in data: | ||
er['externalId'] = data['externalId'] | ||
|
||
er['entity'] = self.ns_client.RecordRef(**(data['entity'])) | ||
logger.debug('able to create er = %s', er) | ||
res = self.ns_client.upsert(er) | ||
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"nullFieldList": null, | ||
"createdDate": null, | ||
"lastModifiedDate": null, | ||
"status": null, | ||
"customForm": null, | ||
"account": { | ||
"name": null, | ||
"internalId": "25", | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"entity": { | ||
"name": null, | ||
"internalId": "1648", | ||
"externalId": null, | ||
"type": "vendor" | ||
}, | ||
"expenseReportCurrency": { | ||
"name": "USD", | ||
"internalId": null, | ||
"externalId": null, | ||
"type": "currency" | ||
}, | ||
"expenseReportExchangeRate": null, | ||
"subsidiary": { | ||
"name": null, | ||
"internalId": "1", | ||
"externalId": null, | ||
"type": "subsidiary" | ||
}, | ||
"taxPointDate": null, | ||
"tranId": null, | ||
"acctCorpCardExp": null, | ||
"postingPeriod": null, | ||
"tranDate": null, | ||
"dueDate": null, | ||
"approvalStatus": null, | ||
"total": null, | ||
"nextApprover": null, | ||
"advance": null, | ||
"tax1Amt": null, | ||
"amount": null, | ||
"memo": "Testing ExpenseReport using Fyle SDK", | ||
"complete": null, | ||
"supervisorApproval": null, | ||
"accountingApproval": null, | ||
"useMultiCurrency": null, | ||
"tax2Amt": null, | ||
"department": null, | ||
"class": null, | ||
"location": null, | ||
"expenseList": [ | ||
{ | ||
"amount": 100, | ||
"category": { | ||
"name": null, | ||
"internalId": "2", | ||
"externalId": null, | ||
"type": "account" | ||
}, | ||
"class": null, | ||
"corporateCreditCard": null, | ||
"currency": { | ||
"name": "USD", | ||
"internalId": "1", | ||
"externalId": null, | ||
"type": "currency" | ||
}, | ||
"customer": null, | ||
"customFieldList": null, | ||
"department": null, | ||
"exchangeRate": null, | ||
"expenseDate": null, | ||
"expMediaItem": null, | ||
"foreignAmount": null, | ||
"grossAmt": null, | ||
"isBillable": null, | ||
"isNonReimbursable": null, | ||
"line": null, | ||
"location": null, | ||
"memo": "Testing ExpenseReports using Fyle SDK", | ||
"quantity": null, | ||
"rate": null, | ||
"receipt": null, | ||
"refNumber": null, | ||
"tax1Amt": null, | ||
"taxCode": null, | ||
"taxRate1": null, | ||
"taxRate2":null | ||
} | ||
], | ||
"accountingBookDetailList": null, | ||
"customFieldList": null, | ||
"internalId": null, | ||
"externalId": "EXPR_1" | ||
} |
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,36 @@ | ||
import logging | ||
import pytest | ||
import json | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def test_get(nc): | ||
data = next(nc.expense_reports.get_all_generator()) | ||
logger.debug('data = %s', data) | ||
assert data, 'get all generator didnt work' | ||
assert data['externalId'] == 'entity-5', f'No object found with externalId' | ||
assert data['internalId'] == '-5', f'No object found with internalId' | ||
|
||
data = nc.expense_reports.get(externalId='EXPR_1') | ||
logger.debug('data = %s', data) | ||
assert data, f'No object with externalId' | ||
assert data['externalId'] == 'EXPR_1', f'No object with externalId' | ||
assert data['internalId'] == '10613', f'No object with internalId' | ||
|
||
def test_post(nc): | ||
filename = os.getenv('NS_ACCOUNT').lower() + '.json' | ||
with open('./test/integration/data/expense_reports/' + filename) as oj: | ||
s = oj.read() | ||
expr1 = json.loads(s) | ||
logger.debug('expr1 = %s', expr1) | ||
res = nc.expense_reports.post(expr1) | ||
logger.debug('res = %s', res) | ||
assert res['externalId'] == expr1['externalId'], 'External ID does not match' | ||
assert res['type'] == 'expenseReport', 'Type does not match' | ||
|
||
expr2 = nc.expense_reports.get(externalId=res['externalId']) | ||
logger.debug('expr2 = %s', expr2) | ||
assert expr2['amount'] == 100.0, 'Amount does not match' | ||
assert expr2['externalId'] == 'EXPR_1', 'External ID does not match' | ||
assert expr2['internalId'] == '10613', 'Internal ID does not match' |
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
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