Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
More descriptive message when active proposal is not found (#325)
Browse files Browse the repository at this point in the history
* Include most recent proposal end date and allocation status when no active proposal is found

* get the first proposal instead of all recent ones and indexing

* shorten up line lengths

---------

Co-authored-by: Nickolas Comeau <[email protected]>
  • Loading branch information
Comeani and Comeani authored Sep 15, 2023
1 parent 1bf9c9f commit dd574c4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bank/account_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ def __init__(self, account_name: str) -> None:
.where(Proposal.account_id.in_(subquery)) \
.where(Proposal.is_active)

self._recent_proposals_query = select(Proposal) \
.where(Proposal.account_id.in_(subquery))

self._active_investment_query = select(Investment) \
.where(Investment.account_id.in_(subquery)) \
.where(Investment.is_active)
Expand Down Expand Up @@ -680,7 +683,17 @@ def _build_usage_table(self) -> PrettyTable:
investments = session.execute(self._active_investment_query).scalars().all()

if not proposal:
raise MissingProposalError('Account has no proposal')
recent_proposal = session.execute(self._recent_proposals_query).scalars().first()
if not recent_proposal:
raise MissingProposalError('This account has never had a proposal')
recent_proposal_end = recent_proposal.end_date.strftime(settings.date_format)
recent_proposal_alloc_status = (
[f'{alloc.cluster_name}:{alloc.service_units_used}/{alloc.service_units_total}' for alloc in
recent_proposal.allocations])
raise MissingProposalError('\nMost recent proposal end date:\n'
f' {recent_proposal_end}\n'
'Most recent proposal allocation status:\n'
f' {recent_proposal_alloc_status}')

# Proposal End Date as first row
output_table.add_row(['Proposal End Date:', proposal.end_date.strftime(settings.date_format), ""],
Expand Down Expand Up @@ -802,8 +815,8 @@ def info(self) -> None:
try:
print(self._build_usage_table())

except MissingProposalError:
print(f'Account {self._account_name} has no current proposal')
except MissingProposalError as e:
print(f'Account {self._account_name} has no active proposal: {str(e)}')

try:
print(self._build_investment_table())
Expand Down

0 comments on commit dd574c4

Please sign in to comment.