Skip to content

Commit

Permalink
making expenses optional and adding items support for vendor_bill (#115)
Browse files Browse the repository at this point in the history
* making expenses optional and adding items support for vendor_bill

* adding test
  • Loading branch information
labhvam5 authored May 26, 2023
1 parent 32cf0b0 commit 8a14ba5
Show file tree
Hide file tree
Showing 6 changed files with 601 additions and 30 deletions.
87 changes: 59 additions & 28 deletions netsuitesdk/api/vendor_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,68 @@ def get_all_generator(self):
def post(self, data) -> OrderedDict:
assert data['externalId'], 'missing external id'
vb = self.ns_client.VendorBill(externalId=data['externalId'])
expense_list = []
for eod in data['expenseList']:
if 'customFieldList' in eod and eod['customFieldList']:
custom_fields = []
for field in eod['customFieldList']:
if field['type'] == 'String':
custom_fields.append(
self.ns_client.StringCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=field['value']
# If expesess are present, add them
if 'expenseList' in data and data['expenseList']:
expense_list = []
for eod in data['expenseList']:
if 'customFieldList' in eod and eod['customFieldList']:
custom_fields = []
for field in eod['customFieldList']:
if field['type'] == 'String':
custom_fields.append(
self.ns_client.StringCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=field['value']
)
)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
)
)
)
)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
vbe = self.ns_client.VendorBillExpense(**eod)
expense_list.append(vbe)

vb['expenseList'] = self.ns_client.VendorBillExpenseList(expense=expense_list)

# If items are present, add them
if 'itemList' in data and data['itemList']:
item_list = []
for eod in data['itemList']:
if 'customFieldList' in eod and eod['customFieldList']:
custom_fields = []
for field in eod['customFieldList']:
print(field['value'])
if field['type'] == 'String':
custom_fields.append(
self.ns_client.StringCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=field['value']
)
)
)
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
vbe = self.ns_client.VendorBillExpense(**eod)
expense_list.append(vbe)

vb['expenseList'] = self.ns_client.VendorBillExpenseList(expense=expense_list)
elif field['type'] == 'Select':
custom_fields.append(
self.ns_client.SelectCustomFieldRef(
scriptId=field['scriptId'] if 'scriptId' in field else None,
internalId=field['internalId'] if 'internalId' in field else None,
value=self.ns_client.ListOrRecordRef(
internalId=field['value']
)
)
)
eod['customFieldList'] = self.ns_client.CustomFieldList(custom_fields)
vbe = self.ns_client.VendorBillItem(**eod)
item_list.append(vbe)

vb['itemList']= self.ns_client.VendorBillItemList(item=item_list)

if 'currency' in data:
vb['currency'] = self.ns_client.RecordRef(**(data['currency']))
Expand All @@ -82,9 +116,6 @@ def post(self, data) -> OrderedDict:
if 'account' in data:
vb['account'] = self.ns_client.RecordRef(**(data['account']))

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

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

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='2.17.0',
version='2.17.1',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down
Loading

0 comments on commit 8a14ba5

Please sign in to comment.