Skip to content

Commit

Permalink
GH-7: Show allocation still to spend on scheme funding
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Nov 20, 2023
1 parent 25eed7d commit d069c5b
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions schemes/schemes/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def change_control_adjustment(self) -> Decimal | None:
)
return sum(amounts, Decimal(0)) if self._financial_revisions 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)
)


class SchemeType(Enum):
DEVELOPMENT = auto()
Expand Down
2 changes: 2 additions & 0 deletions schemes/schemes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ class SchemeFundingContext:
funding_allocation: Decimal | None
spend_to_date: Decimal | None
change_control_adjustment: Decimal | None
allocation_still_to_spend: Decimal

@staticmethod
def for_domain(scheme: Scheme) -> SchemeFundingContext:
return SchemeFundingContext(
funding_allocation=scheme.funding_allocation,
spend_to_date=scheme.spend_to_date,
change_control_adjustment=scheme.change_control_adjustment,
allocation_still_to_spend=scheme.allocation_still_to_spend,
)


Expand Down
8 changes: 8 additions & 0 deletions schemes/templates/scheme_funding.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ <h2 class="govuk-heading-l">Funding</h2>
"value": {
"text": "£{:,}".format(funding.change_control_adjustment | round) if funding.change_control_adjustment else "N/A"
}
},
{
"key": {
"text": "Allocation still to spend"
},
"value": {
"text": "£{:,}".format(funding.allocation_still_to_spend | round)
}
}
]
}) }}
6 changes: 6 additions & 0 deletions tests/e2e/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def __init__(self, component: Locator):
self._funding_allocation = component.get_by_role("definition").nth(0)
self._spend_to_date = component.get_by_role("definition").nth(1)
self._change_control_adjustment = component.get_by_role("definition").nth(2)
self._allocation_still_to_spend = component.get_by_role("definition").nth(3)

@property
def funding_allocation(self) -> str | None:
Expand All @@ -196,6 +197,11 @@ def change_control_adjustment(self) -> str | None:
text = self._change_control_adjustment.text_content()
return text.strip() if text else None

@property
def allocation_still_to_spend(self) -> str | None:
text = self._allocation_still_to_spend.text_content()
return text.strip() if text else None


def _get_base_url(app: Flask) -> str:
scheme = app.config["PREFERRED_URL_SCHEME"]
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/test_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ def test_scheme_funding(app_client: AppClient, oidc_client: OidcClient, app: Fla
funding_component.funding_allocation == "£110,000"
and funding_component.spend_to_date == "£50,000"
and funding_component.change_control_adjustment == "£10,000"
and funding_component.allocation_still_to_spend == "£60,000"
)
4 changes: 4 additions & 0 deletions tests/integration/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ def __init__(self, tag: Tag):
self.change_control_adjustment = (
change_control_adjustment_tag.string.strip() if change_control_adjustment_tag.string else None
)
allocation_still_to_spend_tag = tag.select("main dd")[3]
self.allocation_still_to_spend = (
allocation_still_to_spend_tag.string.strip() if allocation_still_to_spend_tag.string else None
)
2 changes: 2 additions & 0 deletions tests/integration/test_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_scheme_shows_minimal_funding(schemes: SchemeRepository, client: FlaskCl
scheme_page.funding.funding_allocation == "N/A"
and scheme_page.funding.spend_to_date == "N/A"
and scheme_page.funding.change_control_adjustment == "N/A"
and scheme_page.funding.allocation_still_to_spend == "£0"
)


Expand Down Expand Up @@ -141,4 +142,5 @@ def test_scheme_shows_funding(schemes: SchemeRepository, client: FlaskClient) ->
scheme_page.funding.funding_allocation == "£110,000"
and scheme_page.funding.spend_to_date == "£50,000"
and scheme_page.funding.change_control_adjustment == "£10,000"
and scheme_page.funding.allocation_still_to_spend == "£60,000"
)
56 changes: 56 additions & 0 deletions tests/unit/schemes/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,62 @@ def test_get_change_control_adjustment_when_no_revisions(self) -> None:

assert scheme.change_control_adjustment is None

def test_get_allocation_still_to_spend(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("110000"),
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("50000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.allocation_still_to_spend == Decimal("60000")

def test_get_allocation_still_to_spend_when_no_funding_allocation(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.SPENT_TO_DATE,
amount=Decimal("50000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.allocation_still_to_spend == Decimal("-50000")

def test_get_allocation_still_to_spend_when_no_spend_to_date(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("110000"),
source=DataSource.ATF4_BID,
)
)

assert scheme.allocation_still_to_spend == Decimal("110000")

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

assert scheme.allocation_still_to_spend == Decimal("0")


class TestMilestoneRevision:
@pytest.mark.parametrize(
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/schemes/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,31 @@ def test_set_change_control_adjustment(self) -> None:

assert context.change_control_adjustment == Decimal("10000")

def test_set_allocation_still_to_spend(self) -> None:
scheme = Scheme(id_=0, name="", authority_id=0)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("110000"),
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("50000"),
source=DataSource.ATF4_BID,
)
)

context = SchemeFundingContext.for_domain(scheme)

assert context.allocation_still_to_spend == Decimal("60000")


class TestSchemeRepr:
def test_create_domain(self) -> None:
Expand Down

0 comments on commit d069c5b

Please sign in to comment.