From b8316418e14ab044ab3fafe50c78e2884e4237e1 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Wed, 8 Jul 2026 14:45:03 +0000 Subject: [PATCH] Add planning-authority HubSpot deal properties to ETL sync Sync Planning Authority, Designated Area, Article 4 PD Rights, and Listed Building from HubSpot into hubspot_deal_data so downstream consumers of the existing HubSpot ETL process can read them. Co-Authored-By: Claude Sonnet 5 --- backend/app/db/models/hubspot_deal_data.py | 5 ++ etl/hubspot/hubspotDataTodB.py | 8 ++++ etl/hubspot/hubspot_deal_differ.py | 4 ++ etl/hubspot/tests/test_hubspot_data_to_db.py | 48 ++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/backend/app/db/models/hubspot_deal_data.py b/backend/app/db/models/hubspot_deal_data.py index 88bb5a69f..d5db4c20a 100644 --- a/backend/app/db/models/hubspot_deal_data.py +++ b/backend/app/db/models/hubspot_deal_data.py @@ -93,6 +93,11 @@ class HubspotDealData(SQLModel, table=True): last_outbound_email: Optional[datetime] = Field(default=None) last_submission_date: Optional[datetime] = Field(default=None) + planning_authority: Optional[str] = Field(default=None) + designated_area: Optional[str] = Field(default=None) + article_4_pd_rights: Optional[str] = Field(default=None) + listed_building: Optional[str] = Field(default=None) + created_at: Optional[datetime] = Field( sa_column=Column( DateTime(timezone=True), diff --git a/etl/hubspot/hubspotDataTodB.py b/etl/hubspot/hubspotDataTodB.py index 54c174c3f..82e50747d 100644 --- a/etl/hubspot/hubspotDataTodB.py +++ b/etl/hubspot/hubspotDataTodB.py @@ -302,6 +302,10 @@ class HubspotDataToDb: "last_submission_date": parse_hs_date( deal_data.get("last_submission_date") ), + "planning_authority": deal_data.get("planning_authority"), + "designated_area": deal_data.get("designated_area"), + "article_4_pd_rights": deal_data.get("article_pd_rights"), + "listed_building": deal_data.get("listed_building"), }.items(): setattr(existing, attr, value) @@ -407,6 +411,10 @@ class HubspotDataToDb: last_outbound_call=parse_hs_date(deal_data.get("last_outbound_call")), last_outbound_email=parse_hs_date(deal_data.get("last_outbound_email")), last_submission_date=parse_hs_date(deal_data.get("last_submission_date")), + planning_authority=deal_data.get("planning_authority"), + designated_area=deal_data.get("designated_area"), + article_4_pd_rights=deal_data.get("article_pd_rights"), + listed_building=deal_data.get("listed_building"), ) def _handle_existing_photo_upload( diff --git a/etl/hubspot/hubspot_deal_differ.py b/etl/hubspot/hubspot_deal_differ.py index 22d7fb83c..2aa2c3bf1 100644 --- a/etl/hubspot/hubspot_deal_differ.py +++ b/etl/hubspot/hubspot_deal_differ.py @@ -109,6 +109,10 @@ class HubspotDealDiffer: "measures_for_pibi_ordered": "measures_for_pibi_ordered", "property_halted_reason": "property_halted_reason", "technical_approved_measures_for_install": "technical_approved_measures_for_install", + "planning_authority": "planning_authority", + "designated_area": "designated_area", + "article_pd_rights": "article_4_pd_rights", + "listed_building": "listed_building", } for hs_field, db_field in FIELD_MAP.items(): diff --git a/etl/hubspot/tests/test_hubspot_data_to_db.py b/etl/hubspot/tests/test_hubspot_data_to_db.py index 8499ccd08..7d1693040 100644 --- a/etl/hubspot/tests/test_hubspot_data_to_db.py +++ b/etl/hubspot/tests/test_hubspot_data_to_db.py @@ -127,3 +127,51 @@ def test_build_new_deal__client_booking_reference_maps_to_job_no() -> None: ) assert new_deal.client_booking_reference == "AD0226519" + + +def test_build_new_deal__planning_fields_mapped() -> None: + new_deal = _make_instance()._build_new_deal( + deal_id="MOCK_DEAL_ID", + deal_data={ + "planning_authority": "Test Council", + "designated_area": "Conservation Area", + "article_pd_rights": "Removed", + "listed_building": "Grade II", + }, + listing=None, + company=None, + project=None, + ) + + assert new_deal.planning_authority == "Test Council" + assert new_deal.designated_area == "Conservation Area" + assert new_deal.article_4_pd_rights == "Removed" + assert new_deal.listed_building == "Grade II" + + +def test_update_existing_deal__planning_fields_overwritten() -> None: + existing = HubspotDealData( + deal_id="MOCK_DEAL_ID", + planning_authority="Old Council", + designated_area="Old Area", + article_4_pd_rights="Old Rights", + listed_building="Old Listing", + ) + deal_data = { + "planning_authority": "New Council", + "designated_area": "New Area", + "article_pd_rights": "New Rights", + "listed_building": "New Listing", + } + + _make_instance()._update_existing_deal( + existing=existing, + deal_data=deal_data, + listing=None, + company=None, + ) + + assert existing.planning_authority == "New Council" + assert existing.designated_area == "New Area" + assert existing.article_4_pd_rights == "New Rights" + assert existing.listed_building == "New Listing"