mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
fix for hubspot deal properties not updated when they were unset
This commit is contained in:
parent
b4ee59c82e
commit
0a97c2d21f
3 changed files with 42 additions and 3 deletions
|
|
@ -95,8 +95,12 @@ class HubspotDataToDb:
|
|||
with db_read_session() as session:
|
||||
deal_id = deal_data.get("hs_object_id")
|
||||
|
||||
self._sync_owner_to_db(deal_data.get("coordinator_user"), hubspot_client, session)
|
||||
self._sync_owner_to_db(deal_data.get("designer_user"), hubspot_client, session)
|
||||
self._sync_owner_to_db(
|
||||
deal_data.get("coordinator_user"), hubspot_client, session
|
||||
)
|
||||
self._sync_owner_to_db(
|
||||
deal_data.get("designer_user"), hubspot_client, session
|
||||
)
|
||||
|
||||
statement = select(HubspotDealData).where(
|
||||
HubspotDealData.deal_id == deal_id
|
||||
|
|
@ -256,7 +260,7 @@ class HubspotDataToDb:
|
|||
),
|
||||
"domna_survey_date": parse_hs_date(deal_data.get("osmosis_survey_date")),
|
||||
}.items():
|
||||
setattr(existing, attr, value or getattr(existing, attr))
|
||||
setattr(existing, attr, value)
|
||||
|
||||
def _build_new_deal(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ def handler(body: dict[str, Any], context: Any) -> None:
|
|||
|
||||
payload = HubspotTriggerOrchestratorTriggerRequest.model_validate(body)
|
||||
hubspot_deal_id: str = payload.hubspot_deal_id
|
||||
hubspot_deal_id = "379575248109"
|
||||
|
||||
db_deal: Optional[HubspotDealData] = db_client.find_deal_with_deal_id(
|
||||
hubspot_deal_id
|
||||
|
|
|
|||
34
etl/hubspot/tests/test_hubspot_data_to_db.py
Normal file
34
etl/hubspot/tests/test_hubspot_data_to_db.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from etl.hubspot.hubspotDataTodB import HubspotDataToDb
|
||||
from backend.app.db.models.hubspot_deal_data import HubspotDealData
|
||||
|
||||
|
||||
def _make_instance() -> HubspotDataToDb:
|
||||
return HubspotDataToDb.__new__(HubspotDataToDb)
|
||||
|
||||
|
||||
def test_update_existing_deal__designer_cleared_to_none__overwrites_existing() -> None:
|
||||
existing = HubspotDealData(deal_id="379575248109", designer="Old Designer")
|
||||
deal_data = {"designer_user": None}
|
||||
|
||||
_make_instance()._update_existing_deal(
|
||||
existing=existing,
|
||||
deal_data=deal_data,
|
||||
listing=None,
|
||||
company=None,
|
||||
)
|
||||
|
||||
assert existing.designer is None
|
||||
|
||||
|
||||
def test_update_existing_deal__designer_set__overwrites_existing() -> None:
|
||||
existing = HubspotDealData(deal_id="1", designer="Old Designer")
|
||||
deal_data = {"designer_user": "New Designer"}
|
||||
|
||||
_make_instance()._update_existing_deal(
|
||||
existing=existing,
|
||||
deal_data=deal_data,
|
||||
listing=None,
|
||||
company=None,
|
||||
)
|
||||
|
||||
assert existing.designer == "New Designer"
|
||||
Loading…
Add table
Reference in a new issue