Skip to content

Commit

Permalink
bug fix: check for error key in exception response (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 authored Sep 27, 2023
1 parent af1b099 commit 7a2ef47
Showing 1 changed file with 60 additions and 48 deletions.
108 changes: 60 additions & 48 deletions apps/sage_intacct/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,19 +1131,22 @@ def post_expense_report(self, expense_report: ExpenseReport, expense_report_line
return created_expense_report
except WrongParamsError as exception:
logger.info(exception.response)
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
expense_report_payload = self.__construct_expense_report(expense_report, expense_report_lineitems)
expense_report_payload['datecreated'] = {
'year': first_day_of_month.year,
'month': first_day_of_month.month,
'day': first_day_of_month.day
},
created_expense_report = self.connection.expense_reports.post(expense_report_payload)
return created_expense_report
if 'error' in exception.response:
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
expense_report_payload = self.__construct_expense_report(expense_report, expense_report_lineitems)
expense_report_payload['datecreated'] = {
'year': first_day_of_month.year,
'month': first_day_of_month.month,
'day': first_day_of_month.day
},
created_expense_report = self.connection.expense_reports.post(expense_report_payload)
return created_expense_report
else:
raise
else:
raise
else:
Expand All @@ -1161,15 +1164,18 @@ def post_bill(self, bill: Bill, bill_lineitems: List[BillLineitem]):

except WrongParamsError as exception:
logger.info(exception.response)
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
bill_payload = self.__construct_bill(bill, bill_lineitems)
bill_payload['WHENCREATED'] = first_day_of_month
created_bill = self.connection.bills.post(bill_payload)
return created_bill
if 'error' in exception.response:
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
bill_payload = self.__construct_bill(bill, bill_lineitems)
bill_payload['WHENCREATED'] = first_day_of_month
created_bill = self.connection.bills.post(bill_payload)
return created_bill
else:
raise
else:
raise
else:
Expand All @@ -1187,15 +1193,18 @@ def post_journal_entry(self, journal_entry: JournalEntry, journal_entry_lineitem

except WrongParamsError as exception:
logger.info(exception.response)
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
journal_entry_payload = self.__construct_journal_entry(journal_entry, journal_entry_lineitems)
journal_entry_payload['batch_date'] = first_day_of_month
created_journal_entry = self.connection.journal_entries.post(journal_entry_payload)
return created_journal_entry
if 'error' in exception.response:
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
journal_entry_payload = self.__construct_journal_entry(journal_entry, journal_entry_lineitems)
journal_entry_payload['batch_date'] = first_day_of_month
created_journal_entry = self.connection.journal_entries.post(journal_entry_payload)
return created_journal_entry
else:
raise
else:
raise
else:
Expand Down Expand Up @@ -1237,23 +1246,26 @@ def post_charge_card_transaction(self, charge_card_transaction: ChargeCardTransa

except WrongParamsError as exception:
logger.info(exception.response)
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
charge_card_transaction_payload = self.__construct_charge_card_transaction(
charge_card_transaction, charge_card_transaction_lineitems
)
charge_card_transaction_payload['paymentdate'] = {
'year': first_day_of_month.year,
'month': first_day_of_month.month,
'day': first_day_of_month.day
},
created_charge_card_transaction = self.connection.charge_card_transactions.post(
charge_card_transaction_payload
)
return created_charge_card_transaction
if 'error' in exception.response:
sage_intacct_errors = exception.response['error']
error_words_list = ['period', 'closed', 'Date must be on or after']
if any(word in sage_intacct_errors[0]['description2'] for word in error_words_list):
if configuration.change_accounting_period:
first_day_of_month = datetime.today().date().replace(day=1)
charge_card_transaction_payload = self.__construct_charge_card_transaction(
charge_card_transaction, charge_card_transaction_lineitems
)
charge_card_transaction_payload['paymentdate'] = {
'year': first_day_of_month.year,
'month': first_day_of_month.month,
'day': first_day_of_month.day
},
created_charge_card_transaction = self.connection.charge_card_transactions.post(
charge_card_transaction_payload
)
return created_charge_card_transaction
else:
raise
else:
raise
else:
Expand Down

0 comments on commit 7a2ef47

Please sign in to comment.