A blank stored surveyor also counts as unset in the amendment check 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-20 08:37:33 +00:00
parent 91dc359e0d
commit 1e38b44a9a

View file

@ -320,11 +320,11 @@ class HubspotDealDiffer:
new_survey_date = parse_hs_date(new_deal.get("confirmed_survey_date"))
new_survey_time = new_deal.get("confirmed_survey_time")
# HubSpot sends "" for an unset property; the DB stores None. Treat
# them as the same so a booked deal doesn't amend on every scrape.
raw_surveyor = new_deal.get("third_party_surveyor_identifier")
new_surveyor = (
raw_surveyor if raw_surveyor is not None and raw_surveyor.strip() else None
new_surveyor = HubspotDealDiffer._normalised_surveyor(
new_deal.get("third_party_surveyor_identifier")
)
old_surveyor = HubspotDealDiffer._normalised_surveyor(
old_deal.third_party_surveyor_identifier
)
logger.info(
"Abri job-amendment check: "
@ -336,7 +336,7 @@ class HubspotDealDiffer:
new_survey_date,
old_deal.confirmed_survey_time,
new_survey_time,
old_deal.third_party_surveyor_identifier,
old_surveyor,
new_surveyor,
)
@ -354,7 +354,7 @@ class HubspotDealDiffer:
if old_deal.confirmed_survey_time != new_survey_time:
return True
return old_deal.third_party_surveyor_identifier != new_surveyor
return old_surveyor != new_surveyor
@staticmethod
def check_for_abri_tenant_data_fetch(
@ -420,6 +420,14 @@ class HubspotDealDiffer:
old_outcome = (old_deal.outcome or "").lower()
return new_outcome == "surveyed" and old_outcome != "surveyed"
@staticmethod
def _normalised_surveyor(value: Optional[str]) -> Optional[str]:
# HubSpot sends "" for an unset property and the DB stores whatever
# the scrape wrote, so blank and missing must compare as equal.
if value is None or not value.strip():
return None
return value
@staticmethod
def _is_abandoned(
number_of_attempts: Optional[str], outcome: Optional[str]