Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netsuite error parser support for JE and Bills #118

Merged
merged 8 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
21 changes: 18 additions & 3 deletions netsuitesdk/errors/errors.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@

error_reference = {
"expense_report":
{
"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']},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'category_reference_error': {'regex': r"An error occured in a upsert request: Invalid category reference key \d+ for entity \d+", 'keys': ['expense_category', 'employee']},
'category_reference_error': {
'regex': r"An error occured in a upsert request: Invalid category reference key \d+ for entity \d+",
'keys': ['expense_category', 'employee']
},

@NileshPant1999 can we format all errors like this, makes them more readable

'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": {
'account_reference_error': {'regex': r"An error occured in a upsert request: Invalid account reference key \d+", 'keys': ['account']},
'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']
]
5 changes: 4 additions & 1 deletion netsuitesdk/errors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ def get_entity_values(self, error_dict):
object_2 = self.get_instance(convert_to_camelcase(entity_keys[1]), error_dict[entity_keys[1]])

if object_1 and object_2:
if entity_keys[1] == 'employee':
if entity_keys[1] in ['employee', 'vendor']:
object_2 = object_2['email'] if object_2['email'] else object_2['firstName'] + " " + object_2['lastName']
return object_1['name'], object_2

if entity_keys[0] == 'account':
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']


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.18.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it 2.19.0
minor version is only for bugfixes

author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down