Skip to content

Commit

Permalink
GH-7: Correct allocation still to spend calculation
Browse files Browse the repository at this point in the history
Needed to add change control adjustment.

Also correct tests to use FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION when
source is DataSource.CHANGE_CONTROL.
  • Loading branch information
markhobson committed Nov 21, 2023
1 parent d77a5dc commit 57b2da5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 17 deletions.
3 changes: 2 additions & 1 deletion schemes/schemes/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def change_control_adjustment(self) -> Decimal | None:
def allocation_still_to_spend(self) -> Decimal:
funding_allocation = self.funding_allocation or Decimal(0)
spend_to_date = self.spend_to_date or Decimal(0)
return funding_allocation - spend_to_date
change_control_adjustment = self.change_control_adjustment or Decimal(0)
return funding_allocation + change_control_adjustment - spend_to_date


class SchemeType(Enum):
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_scheme_funding(app_client: AppClient, oidc_client: OidcClient, app: Fla
FinancialRevisionRepr(
effective_date_from="2020-01-01",
effective_date_to=None,
type="funding allocation",
type="change control funding reallocation",
amount="10000",
source="change control",
),
Expand All @@ -88,7 +88,7 @@ def test_scheme_funding(app_client: AppClient, oidc_client: OidcClient, app: Fla
funding_component = SchemePage(app, page).open(1).open_funding()

assert (
funding_component.funding_allocation == 110,000"
funding_component.funding_allocation == 100,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"
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_scheme_shows_funding(schemes: SchemeRepository, client: FlaskClient) ->
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
Expand All @@ -139,7 +139,7 @@ def test_scheme_shows_funding(schemes: SchemeRepository, client: FlaskClient) ->
scheme_page = SchemePage(client).open(1)

assert (
scheme_page.funding.funding_allocation == 110,000"
scheme_page.funding.funding_allocation == 100,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"
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_scheme_shows_zero_funding(schemes: SchemeRepository, client: FlaskClien
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("0"),
source=DataSource.CHANGE_CONTROL,
)
Expand Down
70 changes: 60 additions & 10 deletions tests/unit/schemes/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_get_funding_allocation_sums_amounts(self) -> None:
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("200000"),
source=DataSource.CHANGE_CONTROL,
source=DataSource.ATF4E_BID,
)
)

Expand Down Expand Up @@ -269,7 +269,7 @@ def test_get_spend_to_date_sums_amounts(self) -> None:
effective_date_to=None,
type=FinancialType.SPENT_TO_DATE,
amount=Decimal("200000"),
source=DataSource.CHANGE_CONTROL,
source=DataSource.ATF4E_BID,
)
)

Expand Down Expand Up @@ -346,7 +346,7 @@ def test_get_change_control_adjustment_sums_amounts(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
Expand All @@ -355,7 +355,7 @@ def test_get_change_control_adjustment_sums_amounts(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 2, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("20000"),
source=DataSource.CHANGE_CONTROL,
)
Expand All @@ -369,7 +369,7 @@ def test_get_change_control_adjustment_selects_source(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
Expand All @@ -392,7 +392,7 @@ def test_get_change_control_adjustment_selects_latest_revision(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=date(2020, 1, 31),
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
Expand All @@ -401,7 +401,7 @@ def test_get_change_control_adjustment_selects_latest_revision(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 2, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("20000"),
source=DataSource.CHANGE_CONTROL,
)
Expand Down Expand Up @@ -435,7 +435,7 @@ def test_get_allocation_still_to_spend(self) -> None:
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("110000"),
amount=Decimal("100000"),
source=DataSource.ATF4_BID,
)
)
Expand All @@ -448,6 +448,15 @@ def test_get_allocation_still_to_spend(self) -> None:
source=DataSource.ATF4_BID,
)
)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
)

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

Expand All @@ -462,8 +471,17 @@ def test_get_allocation_still_to_spend_when_no_funding_allocation(self) -> None:
source=DataSource.ATF4_BID,
)
)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
)

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

def test_get_allocation_still_to_spend_when_no_spend_to_date(self) -> None:
scheme = Scheme(id_=1, name="Wirral Package", authority_id=2)
Expand All @@ -472,13 +490,45 @@ def test_get_allocation_still_to_spend_when_no_spend_to_date(self) -> None:
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
amount=Decimal("110000"),
amount=Decimal("100000"),
source=DataSource.ATF4_BID,
)
)
scheme.update_financial(
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
)

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

def test_get_allocation_still_to_spend_when_no_change_control_adjustment(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("100000"),
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("50000")

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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/schemes/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_set_change_control_adjustment(self) -> None:
FinancialRevision(
effective_date_from=date(2020, 1, 1),
effective_date_to=None,
type=FinancialType.FUNDING_ALLOCATION,
type=FinancialType.CHANGE_CONTROL_FUNDING_REALLOCATION,
amount=Decimal("10000"),
source=DataSource.CHANGE_CONTROL,
)
Expand Down

0 comments on commit 57b2da5

Please sign in to comment.