Skip to content

Commit

Permalink
24576- NSF reason (#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-barraza authored Jan 20, 2025
1 parent a9b87f4 commit 6ccd0cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pay-api/src/pay_api/services/non_sufficient_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def exists_for_invoice_number(invoice_number: str) -> bool:
def query_all_non_sufficient_funds_invoices(account_id: str):
"""Return all Non-Sufficient Funds invoices and their aggregate amounts."""
query = (
db.session.query(InvoiceModel, InvoiceReferenceModel)
db.session.query(InvoiceModel, InvoiceReferenceModel, NonSufficientFunds.description)
.join(
InvoiceReferenceModel,
InvoiceReferenceModel.invoice_id == InvoiceModel.id,
Expand All @@ -108,7 +108,7 @@ def query_all_non_sufficient_funds_invoices(account_id: str):
InvoiceModel.invoice_status_code != InvoiceStatus.PAID.value,
)
.distinct(InvoiceModel.id)
.group_by(InvoiceModel.id, InvoiceReferenceModel.id)
.group_by(InvoiceModel.id, InvoiceReferenceModel.id, NonSufficientFunds.description)
)

invoice_totals_subquery = (
Expand Down Expand Up @@ -173,7 +173,7 @@ def find_all_non_sufficient_funds_invoices(account_id: str):
results, total, aggregate_totals, statements = (
NonSufficientFundsService.query_all_non_sufficient_funds_invoices(account_id=account_id)
)
invoice_search_model = [InvoiceSearchModel.from_row(invoice_dao) for invoice_dao, _ in results]
invoice_search_model = [InvoiceSearchModel.from_row(invoice_dao) for invoice_dao, _, _ in results]
invoices = Converter().unstructure(invoice_search_model)
invoices = [Converter().remove_nones(invoice_dict) for invoice_dict in invoices]
statements = StatementDTO.dao_to_dict(statements)
Expand All @@ -184,6 +184,7 @@ def find_all_non_sufficient_funds_invoices(account_id: str):
"total_amount": float(aggregate_totals.total_amount or 0),
"total_amount_remaining": float(aggregate_totals.total_amount_remaining or 0),
"nsf_amount": float(aggregate_totals.nsf_amount or 0),
"reason": results[0][2] if results else 'None',
}

return data
Expand Down
3 changes: 2 additions & 1 deletion pay-api/tests/unit/services/test_non_sufficient_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_find_all_non_sufficient_funds_invoices(session):
invoice_reference = factory_invoice_reference(invoice_id=invoice.id, invoice_number=payment.invoice_number)
invoice_reference.save()
non_sufficient_funds = factory_non_sufficient_funds(
invoice_id=invoice.id, invoice_number=payment.invoice_number, description="NSF"
invoice_id=invoice.id, invoice_number=payment.invoice_number, description="EFT invoice overdue"
)
non_sufficient_funds.save()
s1_settings = factory_statement_settings(
Expand Down Expand Up @@ -133,3 +133,4 @@ def test_find_all_non_sufficient_funds_invoices(session):
assert find_non_sufficient_funds["total_amount"] == 0
assert find_non_sufficient_funds["total_amount_remaining"] == 30.0
assert find_non_sufficient_funds["nsf_amount"] == 30.0
assert find_non_sufficient_funds["reason"] == "EFT invoice overdue"

0 comments on commit 6ccd0cd

Please sign in to comment.