Skip to content

Commit

Permalink
Make scheme domain attributes read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Aug 30, 2024
1 parent 9ded22e commit b9cff0a
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 31 deletions.
50 changes: 41 additions & 9 deletions schemes/domain/schemes/funding.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,21 @@ def allocation_still_to_spend(self) -> int:
class BidStatusRevision:
# TODO: domain identifier should be mandatory for transient instances
def __init__(self, id_: int | None, effective: DateRange, status: BidStatus):
self.id = id_
self.effective = effective
self.status = status
self._id = id_
self._effective = effective
self._status = status

@property
def id(self) -> int | None:
return self._id

@property
def effective(self) -> DateRange:
return self._effective

@property
def status(self) -> BidStatus:
return self._status


@unique
Expand All @@ -118,11 +130,31 @@ class BidStatus(Enum):
class FinancialRevision:
# TODO: domain identifier should be mandatory for transient instances
def __init__(self, id_: int | None, effective: DateRange, type_: FinancialType, amount: int, source: DataSource):
self.id = id_
self.effective = effective
self.type = type_
self.amount = amount
self.source = source
self._id = id_
self._effective = effective
self._type = type_
self._amount = amount
self._source = source

@property
def id(self) -> int | None:
return self._id

@property
def effective(self) -> DateRange:
return self._effective

@property
def type(self) -> FinancialType:
return self._type

@property
def amount(self) -> int:
return self._amount

@property
def source(self) -> DataSource:
return self._source

@property
def is_current_funding_allocation(self) -> bool:
Expand All @@ -133,7 +165,7 @@ def is_current_spend_to_date(self) -> bool:
return self.type == FinancialType.SPEND_TO_DATE and self.effective.date_to is None

def close(self, effective_date_to: datetime) -> None:
self.effective = DateRange(self.effective.date_from, effective_date_to)
self._effective = DateRange(self.effective.date_from, effective_date_to)


@unique
Expand Down
38 changes: 31 additions & 7 deletions schemes/domain/schemes/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,39 @@ def __init__(
status_date: date,
source: DataSource,
):
self.id = id_
self.effective = effective
self.milestone = milestone
self.observation_type = observation_type
self.status_date = status_date
self.source = source
self._id = id_
self._effective = effective
self._milestone = milestone
self._observation_type = observation_type
self._status_date = status_date
self._source = source

@property
def id(self) -> int | None:
return self._id

@property
def effective(self) -> DateRange:
return self._effective

@property
def milestone(self) -> Milestone:
return self._milestone

@property
def observation_type(self) -> ObservationType:
return self._observation_type

@property
def status_date(self) -> date:
return self._status_date

@property
def source(self) -> DataSource:
return self._source

def close(self, effective_date_to: datetime) -> None:
self.effective = DateRange(self.effective.date_from, effective_date_to)
self._effective = DateRange(self.effective.date_from, effective_date_to)


class Milestone(IntEnum):
Expand Down
30 changes: 25 additions & 5 deletions schemes/domain/schemes/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,31 @@ def __init__(
value: Decimal,
observation_type: ObservationType,
):
self.id = id_
self.effective = effective
self.type_measure = type_measure
self.value = value
self.observation_type = observation_type
self._id = id_
self._effective = effective
self._type_measure = type_measure
self._value = value
self._observation_type = observation_type

@property
def id(self) -> int | None:
return self._id

@property
def effective(self) -> DateRange:
return self._effective

@property
def type_measure(self) -> OutputTypeMeasure:
return self._type_measure

@property
def value(self) -> Decimal:
return self._value

@property
def observation_type(self) -> ObservationType:
return self._observation_type


class OutputType(IntEnum):
Expand Down
36 changes: 30 additions & 6 deletions schemes/domain/schemes/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,36 @@ def __init__(
type_: SchemeType,
funding_programme: FundingProgramme,
):
self.id = id_
self.effective = effective
self.name = name
self.authority_id = authority_id
self.type = type_
self.funding_programme = funding_programme
self._id = id_
self._effective = effective
self._name = name
self._authority_id = authority_id
self._type = type_
self._funding_programme = funding_programme

@property
def id(self) -> int | None:
return self._id

@property
def effective(self) -> DateRange:
return self._effective

@property
def name(self) -> str:
return self._name

@property
def authority_id(self) -> int:
return self._authority_id

@property
def type(self) -> SchemeType:
return self._type

@property
def funding_programme(self) -> FundingProgramme:
return self._funding_programme


@unique
Expand Down
18 changes: 15 additions & 3 deletions schemes/domain/schemes/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def needs_review(self, reporting_window: ReportingWindow) -> bool:
class AuthorityReview:
# TODO: domain identifier should be mandatory for transient instances
def __init__(self, id_: int | None, review_date: datetime, source: DataSource):
self.id = id_
self.review_date = review_date
self.source = source
self._id = id_
self._review_date = review_date
self._source = source

@property
def id(self) -> int | None:
return self._id

@property
def review_date(self) -> datetime:
return self._review_date

@property
def source(self) -> DataSource:
return self._source
6 changes: 5 additions & 1 deletion schemes/domain/schemes/schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

class Scheme:
def __init__(self, id_: int, reference: str):
self.id = id_
self._id = id_
self._reference = reference
self._overview = SchemeOverview()
self._funding = SchemeFunding()
self._milestones = SchemeMilestones()
self._outputs = SchemeOutputs()
self._reviews = SchemeReviews()

@property
def id(self) -> int:
return self._id

@property
def reference(self) -> str:
return self._reference
Expand Down

0 comments on commit b9cff0a

Please sign in to comment.