Skip to content

Commit

Permalink
netsuite error parser support for JE and Bills (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 authored Jun 13, 2023
1 parent 3b02232 commit b7228e6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 48 deletions.
2 changes: 1 addition & 1 deletion netsuitesdk/api/journal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ def post(self, data) -> OrderedDict:
self.build_record_ref_fields(self.RECORD_REF_FIELDS, data, je)

logger.debug('able to create je = %s', je)
res = self.ns_client.upsert(je)
res = self.ns_client.upsert(je, 'journal_entry')
return self._serialize(res)
3 changes: 1 addition & 2 deletions netsuitesdk/api/vendor_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def post(self, data) -> OrderedDict:
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(
Expand Down Expand Up @@ -123,5 +122,5 @@ 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)
res = self.ns_client.upsert(vb, 'bills')
return self._serialize(res)
81 changes: 72 additions & 9 deletions netsuitesdk/errors/errors.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,81 @@

error_reference = {
"expense_report":
{
'category_reference_error': {'regex': r"An error occured in a upsert request: Invalid category reference key \d+ for entity \d+", 'keys': ['expense_category', 'employee']},
'account_reference_error': {'regex': r"An error occured in a upsert request: Invalid account reference key \d+ for subsidiary \d+", 'keys': ['account', 'subsidiary']},
'project_reference_error': {'regex': r"An error occured in a upsert request: Invalid customer reference key \d+ for entity \d+", 'keys': ['customer', 'employee']},
'location_reference_error': {'regex': r"An error occured in a upsert request: Invalid location reference key \d+ for subsidiary \d+", 'keys': ['location', 'subsidiary']},
'department_reference_error': {'regex':r"An error occured in a upsert request: Invalid department reference key \d+ for subsidiary \d+" , 'keys': ['department', 'subsidiary']},
'currency_reference_error': {'regex': r"An error occured in a upsert request: Invalid currency reference key \d+ for subsidiary \d+", 'keys': ['currency', 'subsidiary']}
"expense_report": {
'category_reference_error': {
'regex': r"An error occured in a upsert request: Invalid category reference key \d+ for entity \d+",
'keys': ['expense_category', 'employee']
},
'account_reference_error': {
'regex': r"An error occured in a upsert request: Invalid account reference key \d+ for subsidiary \d+",
'keys': ['account', 'subsidiary']
},
'project_reference_error': {
'regex': r"An error occured in a upsert request: Invalid customer reference key \d+ for entity \d+",
'keys': ['customer', 'employee']
},
'location_reference_error': {
'regex': r"An error occured in a upsert request: Invalid location reference key \d+ for subsidiary \d+",
'keys': ['location', 'subsidiary']
},
'department_reference_error': {
'regex':r"An error occured in a upsert request: Invalid department reference key \d+ for subsidiary \d+" ,
'keys': ['department', 'subsidiary']
},
'currency_reference_error': {
'regex': r"An error occured in a upsert request: Invalid currency reference key \d+ for subsidiary \d+",
'keys': ['currency', 'subsidiary']
}
},
"bills": {
'bill_account_reference_error': {
'regex': r"An error occured in a upsert request: Invalid account reference key \d+ for subsidiary \d+",
'keys': ['account', 'subsidiary']
},
'location_reference_error': {
'regex': r"An error occured in a upsert request: Invalid location reference key \d+ for subsidiary \d+",
'keys': ['location', 'subsidiary']
},
'department_reference_error': {
'regex':r"An error occured in a upsert request: Invalid department reference key \d+ for subsidiary \d+" ,
'keys': ['department', 'subsidiary']
},
'currency_reference_error': {
'regex': r"An error occured in a upsert request: Invalid currency reference key \d+ for subsidiary \d+",
'keys': ['currency', 'subsidiary']
},
'vendor_reference_error': {
'regex': r"An error occured in a upsert request: Invalid entity reference key \d+ for subsidiary \d+",
'keys': ['vendor', 'subsidiary']
}
},
"journal_entry": {
'location_reference_error': {
'regex': r"An error occured in a upsert request: Invalid location reference key \d+ for subsidiary \d+",
'keys': ['location', 'subsidiary']
},
'department_reference_error': {
'regex':r"An error occured in a upsert request: Invalid department reference key \d+ for subsidiary \d+" ,
'keys': ['department', 'subsidiary']
},
'account_reference_error': {
'regex': r"An error occured in a upsert request: Invalid account reference key \d+ for subsidiary \d+",
'keys': ['account', 'subsidiary']
},
'currency_reference_error': {
'regex': r"An error occured in a upsert request: Invalid currency reference key \d+ for subsidiary \d+",
'keys': ['currency', 'subsidiary']
},
'project_reference_error': {
'regex': r"An error occured in a upsert request: Invalid customer reference key \d+ for entity \d+",
'keys': ['customer', 'employee']
},
}
}


list_of_dicts = [
['expense_category', 'employee'], ['account', 'subsidiary'],
['customer', 'employee'], ['location', 'subsidiary'],
['department', 'subsidiary'], ['currency', 'subsidiary']
['department', 'subsidiary'], ['currency', 'subsidiary'],
['vendor', 'subsdiary']
]
4 changes: 4 additions & 0 deletions netsuitesdk/errors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ def get_entity_values(self, error_dict):
object_1 = object_1['acctName']
return object_1, object_2['name']

if entity_keys[0] == 'vendor':
object_1 = object_1['companyName'] if object_1['companyName'] else object_1['entityId']
return object_1, object_2['name']
return object_1['name'], object_2['name']


def export_error_parser(self, error_dict, message):

parsed_message = message
print('dsdf', list(error_dict))
if list(error_dict) in list_of_dicts:
object_1, object_2 = self.get_entity_values(error_dict)
entity_keys = list(error_dict)
Expand Down
2 changes: 1 addition & 1 deletion netsuitesdk/internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def upsert(self, record, record_type=None):

if record_type:
error_parser = ErrorParser(self.get)
error_dict = export_error_matcher(exc.message, 'expense_report')
error_dict = export_error_matcher(exc.message, record_type)
message = error_parser.export_error_parser(error_dict, exc.message)
exc.message = message

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.18.1',
version='2.19.0',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_vendor_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def test_post(nc):
logger.debug('rvb1 = %s', vb4)
res = nc.vendor_bills.post(vb4)
logger.debug('res = %s', res)
assert res['externalId'] == vb4['externalId'], 'External ID does not match'
assert res['externalId'] == vb4['externalId'], 'External ID does not match'
67 changes: 34 additions & 33 deletions test/internal/test_upsert.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from netsuitesdk.internal.utils import PaginatedSearch
from netsuitesdk.internal.exceptions import NetSuiteRequestError
import logging
import pytest
import zeep


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,6 +73,19 @@ def test_upsert_vendor_bill(ns):
bill2 = ns.get(recordType='vendorBill', externalId='1234')
logger.debug('bill2 = %s', str(bill2))
assert (29.99 < bill2['userTotal']) and (bill2['userTotal'] < 30.01), 'Bill total is not 30.0'

subs_ref = ns.RecordRef(type='subsdiary', internalId=5)
bill_account_ref = ns.RecordRef(type='account', internalId=237)
vbe1['account'] = bill_account_ref
vbe1['subsdiary'] = subs_ref

try:
record_ref = ns.upsert(bill, record_type='bills')
logger.debug('record_ref = %s', record_ref)
except NetSuiteRequestError as e:
assert e.message == 'An error occured in a upsert request: Invalid account reference key UK EXP Account for subsidiary Honeycomb Mfg..'
assert e.code == 'INVALID_KEY_OR_REF'


def test_upsert_journal_entry(ns):
vendor_ref = ns.RecordRef(type='vendor', internalId=get_vendor(ns).internalId)
Expand Down Expand Up @@ -117,48 +129,23 @@ def test_upsert_journal_entry(ns):
je = ns.get(recordType='journalEntry', externalId='JE_1234')
logger.debug('je = %s', str(je))
assert (je['externalId'] == 'JE_1234'), 'Journal Entry External ID does not match'


def test_failed_expense_report(ns):
employee_ref = ns.RecordRef(type='employee', internalId=get_employee(ns).internalId)
cat_account_ref = ns.RecordRef(type='account', internalId='3')
loc_ref = ns.RecordRef(type='location', internalId=12)
subs_ref = ns.RecordRef(type='subsdiary', internalId=5)
dep_ref = ns.RecordRef(type='department', internalId=get_department(ns).internalId)
class_ref = ns.RecordRef(type='classification', internalId=get_department(ns).internalId)
currency_ref = ns.RecordRef(type='currency', internalId=get_currency(ns).internalId)
expenses = []

er = ns.ExpenseReportExpense()
er['category'] = cat_account_ref
er['amount'] = 10.0
er['department'] = dep_ref
er['class'] = class_ref
er['location'] = loc_ref
er['currency'] = currency_ref
er['subsdiary'] = subs_ref

expenses.append(er)
cat_account_ref = ns.RecordRef(type='account', internalId=237)
credit_line['account'] = cat_account_ref

expense_report = ns.ExpenseReport(externalId='EXPR_1')
expense_report['expenseReportCurrency'] = currency_ref # US dollar
expense_report['exchangerate'] = 1.0
expense_report['expenseList'] = ns.ExpenseReportExpenseList(expense=expenses)
expense_report['memo'] = 'test memo'
expense_report['entity'] = employee_ref
logger.debug('upserting expense report %s', expense_report)

try:
record_ref = ns.upsert(expense_report, record_type='expense_report')
record_ref = ns.upsert(journal_entry, 'journal_entry')
logger.debug('record_ref = %s', record_ref)
except NetSuiteRequestError as e:
assert e.message == 'An error occured in a upsert request: Invalid location reference key UK Location for subsidiary Honeycomb Mfg..'
assert e.message == 'An error occured in a upsert request: Invalid account reference key UK EXP Account for subsidiary Honeycomb Mfg..'
assert e.code == 'INVALID_KEY_OR_REF'


def test_upsert_expense_report(ns):
employee_ref = ns.RecordRef(type='employee', internalId=get_employee(ns).internalId)
bill_account_ref = ns.RecordRef(type='account', internalId=25)
cat_account_ref = ns.RecordRef(type='account', internalId='3')

loc_ref = ns.RecordRef(type='location', internalId=get_location(ns).internalId)
dep_ref = ns.RecordRef(type='department', internalId=get_department(ns).internalId)
class_ref = ns.RecordRef(type='classification', internalId=get_department(ns).internalId)
Expand Down Expand Up @@ -188,3 +175,17 @@ def test_upsert_expense_report(ns):

expr = ns.get(recordType='ExpenseReport', externalId='EXPR_1')
logger.debug('expense report = %s', str(expr))


loc_ref = ns.RecordRef(type='location', internalId=12)
subs_ref = ns.RecordRef(type='subsdiary', internalId=5)

er['location'] = loc_ref
er['subsdiary'] = subs_ref

try:
record_ref = ns.upsert(expense_report, record_type='expense_report')
logger.debug('record_ref = %s', record_ref)
except NetSuiteRequestError as e:
assert e.message == 'An error occured in a upsert request: Invalid location reference key UK Location for subsidiary Honeycomb Mfg..'
assert e.code == 'INVALID_KEY_OR_REF'

0 comments on commit b7228e6

Please sign in to comment.