Skip to content

Commit

Permalink
GH-7: Show zero funding details as '£0' not 'N/A'
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 46a21a7 commit d77a5dc
Showing 4 changed files with 98 additions and 19 deletions.
28 changes: 12 additions & 16 deletions schemes/schemes/domain.py
Original file line number Diff line number Diff line change
@@ -47,40 +47,36 @@ def update_financial(self, financial_revision: FinancialRevision) -> None:

@property
def funding_allocation(self) -> Decimal | None:
amounts = (
amounts = [
revision.amount
for revision in self._financial_revisions
if revision.type == FinancialType.FUNDING_ALLOCATION and revision.effective_date_to is None
)
return sum(amounts, Decimal(0)) if self._financial_revisions else None
]
return sum(amounts, Decimal(0)) if amounts else None

@property
def spend_to_date(self) -> Decimal | None:
amounts = (
amounts = [
revision.amount
for revision in self._financial_revisions
if revision.type == FinancialType.SPENT_TO_DATE and revision.effective_date_to is None
)
return sum(amounts, Decimal(0)) if self._financial_revisions else None
]
return sum(amounts, Decimal(0)) if amounts else None

@property
def change_control_adjustment(self) -> Decimal | None:
amounts = (
amounts = [
revision.amount
for revision in self._financial_revisions
if revision.source == DataSource.CHANGE_CONTROL and revision.effective_date_to is None
)
return sum(amounts, Decimal(0)) if self._financial_revisions else None
]
return sum(amounts, Decimal(0)) if amounts else None

@property
def allocation_still_to_spend(self) -> Decimal:
funding_allocation = self.funding_allocation
spend_to_date = self.spend_to_date
return (
funding_allocation - spend_to_date
if funding_allocation is not None and spend_to_date is not None
else Decimal(0)
)
funding_allocation = self.funding_allocation or Decimal(0)
spend_to_date = self.spend_to_date or Decimal(0)
return funding_allocation - spend_to_date


class SchemeType(Enum):
6 changes: 3 additions & 3 deletions schemes/templates/scheme_funding.html
Original file line number Diff line number Diff line change
@@ -6,23 +6,23 @@ <h2 class="govuk-heading-l">Funding</h2>
"text": "Funding allocation"
},
"value": {
"text": "£{:,}".format(funding.funding_allocation | round) if funding.funding_allocation else "N/A"
"text": "£{:,}".format(funding.funding_allocation | round) if funding.funding_allocation is not none() else "N/A"
}
},
{
"key": {
"text": "Spend to date"
},
"value": {
"text": "£{:,}".format(funding.spend_to_date | round) if funding.spend_to_date else "N/A"
"text": "£{:,}".format(funding.spend_to_date | round) if funding.spend_to_date is not none() else "N/A"
}
},
{
"key": {
"text": "Change control adjustment"
},
"value": {
"text": "£{:,}".format(funding.change_control_adjustment | round) if funding.change_control_adjustment else "N/A"
"text": "£{:,}".format(funding.change_control_adjustment | round) if funding.change_control_adjustment is not none() else "N/A"
}
},
{
41 changes: 41 additions & 0 deletions tests/integration/test_scheme.py
Original file line number Diff line number Diff line change
@@ -144,3 +144,44 @@ def test_scheme_shows_funding(schemes: SchemeRepository, client: FlaskClient) ->
and scheme_page.funding.change_control_adjustment == "£10,000"
and scheme_page.funding.allocation_still_to_spend == "£60,000"
)


def test_scheme_shows_zero_funding(schemes: SchemeRepository, client: FlaskClient) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=1)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("0"),
source=DataSource.ATF4_BID,
)
)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.SPENT_TO_DATE,
amount=Decimal("0"),
source=DataSource.ATF4_BID,
)
)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("0"),
source=DataSource.CHANGE_CONTROL,
)
)
schemes.add(scheme)

scheme_page = SchemePage(client).open(1)

assert (
scheme_page.funding.funding_allocation == "£0"
and scheme_page.funding.spend_to_date == "£0"
and scheme_page.funding.change_control_adjustment == "£0"
and scheme_page.funding.allocation_still_to_spend == "£0"
)
42 changes: 42 additions & 0 deletions tests/unit/schemes/test_domain.py
Original file line number Diff line number Diff line change
@@ -233,6 +233,20 @@ def test_get_funding_allocation_selects_latest_revision(self) -> None:

assert scheme.funding_allocation == Decimal("200000")

def test_get_funding_allocation_when_no_matching_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.EXPECTED_COST,
amount=Decimal("100000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.funding_allocation is None

def test_get_funding_allocation_when_no_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)

@@ -307,6 +321,20 @@ def test_get_spend_to_date_selects_latest_revision(self) -> None:

assert scheme.spend_to_date == Decimal("200000")

def test_get_spend_to_date_when_no_matching_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.EXPECTED_COST,
amount=Decimal("100000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.spend_to_date is None

def test_get_spend_to_date_when_no_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)

@@ -381,6 +409,20 @@ def test_get_change_control_adjustment_selects_latest_revision(self) -> None:

assert scheme.change_control_adjustment == Decimal("20000")

def test_get_change_control_adjustment_when_no_matching_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("10000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.change_control_adjustment is None

def test_get_change_control_adjustment_when_no_revisions(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)

0 comments on commit d77a5dc

Please sign in to comment.