Skip to content

Commit

Permalink
Add support for Vendor Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sravanksk authored Oct 30, 2020
1 parent adea16f commit 4b7ff86
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ 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))
vendors = list(itertools.islice(nc.vendors.get_all_generator(), 10))
vendor_payments = nc.vendor_payments.get_all()

data = {
'accounts': accounts,
Expand All @@ -76,7 +77,8 @@ data = {
'vendor_bills': vendor_bills,
'subsidiaries': subsidiaries,
'expense_categories': expense_categories,
'employees': employees
'employees': employees,
'vendor_payments': vendor_payments
}
with open('/tmp/netsuite.json', 'w') as oj:
oj.write(json.dumps(data, default=str, indent=2))
Expand All @@ -88,7 +90,7 @@ 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, expense_reports and journal_entries currently (see tests on how to construct vendor bill, expense report and journal entry)
# Post operation is only supported on vendor_bills, expense_reports, journal_entries and vendor_payments currently (see tests on how to construct vendor bill, expense report and journal entry)
vb = {...}
nc.vendor_bills.post(vb)

Expand All @@ -98,6 +100,9 @@ nc.expense_reports.post(er)
je = {...}
nc.journal_entries.post(je)

vp = {...}
nc.vendor_payments.post(vp)

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

Expand Down
69 changes: 69 additions & 0 deletions netsuitesdk/api/vendor_payments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import logging

from netsuitesdk.internal.utils import PaginatedSearch

from .base import ApiBase
from collections import OrderedDict

logger = logging.getLogger(__name__)


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

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

def get_all_generator(self):
record_type_search_field = self.ns_client.SearchStringField(searchValue='VendorPayment', 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'
vp = self.ns_client.VendorPayment(externalId=data['externalId'])
apply_lists = []
for eod in data['applyList']['apply']:
vpal = self.ns_client.VendorPaymentApply(**eod)
apply_lists.append(vpal)

vp['applyList'] = self.ns_client.VendorPaymentApplyList(apply=apply_lists)
vp['currency'] = self.ns_client.RecordRef(**(data['currency']))

if 'amount' in data:
vp['amount'] = data['amount']

if 'memo' in data:
vp['memo'] = data['memo']

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

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

if 'class' in data:
vp['class'] = self.ns_client.RecordRef(**(data['class']))

if 'location' in data:
vp['location'] = self.ns_client.RecordRef(**(data['location']))

if 'department' in data:
vp['department'] = self.ns_client.RecordRef(**(data['department']))

if 'account' in data:
vp['account'] = self.ns_client.RecordRef(**(data['account']))

if 'externalId' in data:
vp['externalId'] = data['externalId']

vp['entity'] = self.ns_client.RecordRef(**(data['entity']))
logger.debug('able to create vp = %s', vp)
res = self.ns_client.upsert(vp)
return self._serialize(res)
2 changes: 2 additions & 0 deletions netsuitesdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .api.expense_categories import ExpenseCategory
from .api.custom_lists import CustomLists
from .api.custom_records import CustomRecords
from .api.vendor_payments import VendorPayments
from .internal.client import NetSuiteClient


Expand Down Expand Up @@ -43,3 +44,4 @@ def __init__(self, account, consumer_key, consumer_secret, token_key, token_secr
self.expense_categories = ExpenseCategory(ns_client)
self.custom_lists = CustomLists(ns_client)
self.custom_records = CustomRecords(ns_client)
self.vendor_payments = VendorPayments(ns_client)
4 changes: 4 additions & 0 deletions netsuitesdk/internal/netsuite_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
'VendorBillItem',
'VendorBillItemList',
'VendorPayment',
'VendorPaymentApplyList',
'VendorPaymentCredit',
'VendorPaymentCreditList',
'VendorPaymentApply'
],

# urn:general_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.9.0',
version='1.10.0',
author='Siva Narayanan',
author_email='siva@fyle.in',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down

0 comments on commit 4b7ff86

Please sign in to comment.