-
Notifications
You must be signed in to change notification settings - Fork 77
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
feature: support of error parser for expense report export #113
Merged
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
31f9e49
feature: support of error parser for expense report export
NileshPant1999 ce8481b
test fix
NileshPant1999 b288c3f
beautify netsuite errors
NileshPant1999 b5a2c03
minor fix
NileshPant1999 30b7b4a
add more errors
NileshPant1999 8aa7b4e
minor change
NileshPant1999 56edf68
kik
NileshPant1999 09b3473
iuyg
NileshPant1999 8edb3ff
Merge branch 'master' of https://github.com/fylein/netsuite-sdk-py in…
NileshPant1999 7c86741
bump up version
NileshPant1999 96cd969
tests
NileshPant1999 2c0f88d
refactor
NileshPant1999 0081e3a
fix;
NileshPant1999 d8120b5
move exceptions to upsert function
NileshPant1999 1807dd7
added
NileshPant1999 a064027
fixed tests
NileshPant1999 c5115a8
fixed tests
NileshPant1999 c5648f1
ad
NileshPant1999 24e56f9
ad
NileshPant1999 c40803c
ad
NileshPant1999 93fcf2c
conflict fix
NileshPant1999 42dd6f9
test fix
NileshPant1999 cef0812
asd
NileshPant1999 42b6777
sdf
NileshPant1999 811c7b8
test fixed
NileshPant1999 f7fb31b
added tests
NileshPant1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
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,12 @@ | ||
|
||
error_reference = { | ||
"expense_report": | ||
{ | ||
"category_reference_error": r"An error occured in a upsert request: Invalid category reference key \d+ for entity \d+", | ||
"account_reference_error": r"An error occured in a upsert request: Invalid account reference key \d+ for subsidiary \d+", | ||
"project_reference_error": r"An error occured in a upsert request: Invalid customer reference key \d+ for entity \d+", | ||
"location_reference_error": r"An error occured in a upsert request: Invalid location reference key \d+ for subsidiary \d+", | ||
"department_reference_error": r"An error occured in a upsert request: Invalid department reference key \d+ for subsidiary \d+", | ||
"currency_reference_error": r"An error occured in a upsert request: Invalid currency reference key \d+ for subsidiary \d+", | ||
} | ||
} |
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,42 @@ | ||
import re | ||
from .errors import error_reference | ||
|
||
|
||
def decode_project_or_customer_name(name): | ||
value = name.replace(u'\xa0', ' ') | ||
value = value.replace('/', '-') | ||
return value | ||
|
||
|
||
def replace_numbers(string , replacement1, replacement2, number1, number2): | ||
replaced_string = re.sub(r'\b({}|{})\b'.format(number1, number2), lambda m: replacement1 if m.group() == number1 else replacement2, string) | ||
return replaced_string | ||
|
||
|
||
def export_error_matcher(string, export_type): | ||
|
||
if re.match(error_reference[export_type]['category_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"category": numbers[0], "entity": numbers[1]} | ||
|
||
if re.match(error_reference[export_type]['account_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"account": numbers[0], "subsidiary": numbers[1]} | ||
|
||
if re.match(error_reference[export_type]['project_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"customer": numbers[0], "entity": numbers[1]} | ||
|
||
if re.match(error_reference[export_type]['location_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"location": numbers[0], "subsidiary": numbers[1]} | ||
|
||
if re.match(error_reference[export_type]['department_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"department": numbers[0], "subsidiary": numbers[1]} | ||
|
||
if re.match(error_reference[export_type]['currency_reference_error'], string): | ||
numbers = re.findall(r'\d+', string) | ||
return {"currency": numbers[0], "subsidiary": numbers[1]} | ||
|
||
return {} |
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,39 @@ | ||
from .helpers import decode_project_or_customer_name, replace_numbers | ||
|
||
|
||
def expense_report_error_parser(error_dict, ns_client, message): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once we move ahead with other module and see the pattern |
||
|
||
if list(error_dict) == ['category', 'entity']: | ||
category = ns_client.get('ExpenseCategory', error_dict['category'])['name'] | ||
entity = ns_client.get('Employee', error_dict['entity']) | ||
entity_name = entity['email'] if entity['email'] else entity['firstName'] + " " + entity['lastName'] | ||
message = replace_numbers(message, category, entity_name, error_dict['category'], error_dict['entity']) | ||
|
||
elif list(error_dict) == ['account', 'subsidiary']: | ||
account = ns_client.get('Account', error_dict['account'])['acctName'] | ||
subsdiary = ns_client.get('Subsidiary', error_dict['subsidiary'])['name'] | ||
message = replace_numbers(message, account, subsdiary, error_dict['account'], error_dict['subsidiary']) | ||
|
||
elif list(error_dict) == ['customer', 'entity']: | ||
customer = ns_client.get('Customer', error_dict['customer'])['entityId'] | ||
customer_name = decode_project_or_customer_name(customer) | ||
entity = ns_client.get('Employee', error_dict['entity']) | ||
entity_name = entity['email'] if entity['email'] else entity['firstName'] + " " + entity['lastName'] | ||
message = replace_numbers(message, customer_name, entity_name, error_dict['customer'], error_dict['entity']) | ||
|
||
elif list(error_dict) == ['location', 'subsidiary']: | ||
location = ns_client.get('Location', error_dict['location'])['name'] | ||
subsdiary = ns_client.get('Subsidiary', error_dict['subsidiary'])['name'] | ||
message = replace_numbers(message, location, subsdiary, error_dict['location'], error_dict['subsidiary']) | ||
|
||
elif list(error_dict) == ['department', 'subsidiary']: | ||
department = ns_client.get('Department', error_dict['department'])['name'] | ||
subsdiary = ns_client.get('Subsidiary', error_dict['subsidiary'])['name'] | ||
message = replace_numbers(message, department, subsdiary, error_dict['department'], error_dict['subsidiary']) | ||
|
||
elif list(error_dict) == ['currency', 'subsidiary']: | ||
currency = ns_client.get('Currency', error_dict['currency'])['name'] | ||
subsdiary = ns_client.get('Subsidiary', error_dict['subsidiary'])['name'] | ||
message = replace_numbers(message, currency, subsdiary, error_dict['currency'], error_dict['subsidiary']) | ||
|
||
return message |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use broad exception