diff --git a/backend/app/db/models/hubspot_deal_data.py b/backend/app/db/models/hubspot_deal_data.py index 1d7607e0..758f688d 100644 --- a/backend/app/db/models/hubspot_deal_data.py +++ b/backend/app/db/models/hubspot_deal_data.py @@ -65,8 +65,8 @@ class HubspotDealData(SQLModel, table=True): server_default=text("(NOW() AT TIME ZONE 'utc')"), nullable=False, ), - default=None, # Nullable in db but optional here as value is set on db save for new record - ) + default=func.now(), + ) # Nullable in db but optional here as value is set on db save for new record updated_at: Optional[datetime] = Field( sa_column=Column( @@ -75,5 +75,5 @@ class HubspotDealData(SQLModel, table=True): onupdate=func.now(), nullable=False, ), - default=None, # Nullable in db but optional here as value is set on db save for new record - ) + default=func.now(), + ) # Nullable in db but optional here as value is set on db save for new record diff --git a/etl/hubspot/hubspotDataTodB.py b/etl/hubspot/hubspotDataTodB.py index 65fad572..a50c99da 100644 --- a/etl/hubspot/hubspotDataTodB.py +++ b/etl/hubspot/hubspotDataTodB.py @@ -31,7 +31,7 @@ class HubspotDataToDb: records = self.read_org_table(limit) return [org.name for org in records if org.name] - def upsert_company(self, company_data: CompanyData) -> Organisation: + def upsert_organisation(self, company_data: CompanyData) -> Organisation: """Upserts a company record. Updates if hubspot_company_id exists, otherwise creates new.""" with db_read_session() as session: hubspot_id = company_data.get("hs_object_id") diff --git a/etl/hubspot/hubspot_deal_differ.py b/etl/hubspot/hubspot_deal_differ.py index 42def3b2..4db303ab 100644 --- a/etl/hubspot/hubspot_deal_differ.py +++ b/etl/hubspot/hubspot_deal_differ.py @@ -8,6 +8,7 @@ class HubspotDealDiffer: COORDINATION_COMPLETE: List[str] = [ "v1 ioe/mtp complete", "v2 ioe/mtp complete", + "v3 ioe/mtp complete", ] RETROFIT_DESIGN_COMPLETE = "uploaded" LODGEMENT_COMPLETE: List[str] = ["lodgement complete", "measures lodged"] @@ -72,6 +73,7 @@ class HubspotDealDiffer: "lodgement_status": "lodgement_status", "design_type": "design_type", "surveyor": "surveyor", + "confirmed_survey_time": "confirmed_survey_time", } for hs_field, db_field in FIELD_MAP.items(): @@ -101,10 +103,6 @@ class HubspotDealDiffer: if old_value != new_value: return True - # --- Time field --- - if old_deal.confirmed_survey_time != new_deal.get("confirmed_survey_time"): - return True - # No differences found return False diff --git a/etl/hubspot/scripts/onboarding/new_organisation.py b/etl/hubspot/scripts/onboarding/new_organisation.py index f8c6ba7a..0785949a 100644 --- a/etl/hubspot/scripts/onboarding/new_organisation.py +++ b/etl/hubspot/scripts/onboarding/new_organisation.py @@ -22,7 +22,7 @@ companies_to_add_or_ensure_it_exists = [ for company in companies_to_add_or_ensure_it_exists: company_info: CompanyData = hubspot.get_company_information(company.value) - dbRead.upsert_company(company_info) + dbRead.upsert_organisation(company_info) dbRead = HubspotDataToDb() diff --git a/etl/hubspot/scripts/scraper/main.py b/etl/hubspot/scripts/scraper/main.py index 8fa71bf7..31945705 100644 --- a/etl/hubspot/scripts/scraper/main.py +++ b/etl/hubspot/scripts/scraper/main.py @@ -45,7 +45,7 @@ def handler(body: dict[str, Any], context: Any) -> None: if company: company_data: CompanyData = hubspot_client.get_company_information(company) db_client: HubspotDataToDb = HubspotDataToDb() - db_client.upsert_company(company_data) + db_client.upsert_organisation(company_data) db_client.upsert_deal(hubspot_deal, company, listing, hubspot_client) else: