Skip to content

Commit

Permalink
Add changed date to property manager in housing company detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
indigane committed Aug 27, 2024
1 parent 1c4cb46 commit 9adc7ea
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
18 changes: 18 additions & 0 deletions backend/hitas/models/housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ def release_date(self) -> Optional[datetime.date]:
# Release date was not found
return None

@property
def property_manager_changed_at(self) -> Optional[datetime.datetime]:
latest_logentry: LogEntry = (
LogEntry.objects.get_for_object(self)
.annotate(changes_as_json=Cast("changes", output_field=models.JSONField()))
.filter(
action__in=[LogEntry.Action.UPDATE, LogEntry.Action.CREATE],
changes_as_json__property_manager__isnull=False,
)
# Ignore cases where property manager was not actually changed
.exclude(changes_as_json__property_manager__0=F("changes_as_json__property_manager__1"))
.order_by("-timestamp", "-id")
.first()
)
if latest_logentry is not None:
return latest_logentry.timestamp
return None

class Meta:
verbose_name = _("Housing company")
verbose_name_plural = _("Housing companies")
Expand Down
1 change: 1 addition & 0 deletions backend/hitas/tests/apis/test_api_housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def test__api__housing_company__retrieve(api_client: HitasAPIClient, apt_with_nu
"email": hc1.property_manager.email,
"modified_at": serializers.DateTimeField().to_representation(hc1.property_manager.modified_at),
},
"property_manager_changed_at": serializers.DateTimeField().to_representation(hc1.property_manager_changed_at),
"acquisition_price": float(hc1.acquisition_price),
"primary_loan": float(hc1.primary_loan),
"sales_price_catalogue_confirmation_date": str(hc1.sales_price_catalogue_confirmation_date),
Expand Down
2 changes: 2 additions & 0 deletions backend/hitas/views/housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class HousingCompanyDetailSerializer(EnumSupportSerializerMixin, HitasModelSeria
building_type = ReadOnlyBuildingTypeSerializer()
developer = ReadOnlyDeveloperSerializer()
property_manager = ReadOnlyPropertyManagerSerializer(allow_null=True, required=False)
property_manager_changed_at = serializers.DateTimeField(read_only=True)
acquisition_price = HitasDecimalField()
notes = serializers.CharField(required=False, allow_blank=True)
archive_id = serializers.IntegerField(source="id", read_only=True)
Expand Down Expand Up @@ -348,6 +349,7 @@ class Meta:
"building_type",
"developer",
"property_manager",
"property_manager_changed_at",
"acquisition_price",
"primary_loan",
"sales_price_catalogue_confirmation_date",
Expand Down
7 changes: 7 additions & 0 deletions backend/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5652,6 +5652,13 @@ components:
property_manager:
nullable: true
$ref: "#/components/schemas/ReadOnlyPropertyManager"
property_manager_changed_at:
description: When the property manager was last changed
type: string
nullable: true
readOnly: true
format: date-time
example: 1985-12-10T00:00:00+00:00
summary:
description: Summary data for this housing company across all apartments
type: object
Expand Down
1 change: 1 addition & 0 deletions frontend/src/common/schemas/housingCompany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const HousingCompanyDetailsSchema = object({
building_type: CodeSchema,
developer: CodeSchema,
property_manager: PropertyManagerSchema.nullable(),
property_manager_changed_at: string().optional(),
acquisition_price: number(),
primary_loan: number().optional(),
sales_price_catalogue_confirmation_date: string().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ const LoadedHousingCompanyDetails = (): React.JSX.Element => {
)}
{housingCompany.property_manager ? (
<div className="detail-field-metadata">
Päivitetty viimeksi:{" "}
Vaihdettu:{" "}
{housingCompany.property_manager.modified_at
? formatDate(housingCompany.property_manager.modified_at)
: "tieto puuttuu"}
, muokattu:{" "}
{housingCompany.property_manager_changed_at
? formatDate(housingCompany.property_manager_changed_at)
: "tieto puuttuu"}
</div>
) : null}
</div>
Expand Down

0 comments on commit 9adc7ea

Please sign in to comment.