From 2d0bc67731239d045c6f7106ba87e6a7b640b2ff Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 8 Apr 2026 15:59:29 +0000 Subject: [PATCH] =?UTF-8?q?diff=20checker=20for=20pashub=20trigger=20?= =?UTF-8?q?=F0=9F=9F=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hubspot_deal_differ.py | 133 ++++++++++-------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/backend/hubspot_trigger_orchestrator/hubspot_deal_differ.py b/backend/hubspot_trigger_orchestrator/hubspot_deal_differ.py index 8f96ce73..1dd4ed51 100644 --- a/backend/hubspot_trigger_orchestrator/hubspot_deal_differ.py +++ b/backend/hubspot_trigger_orchestrator/hubspot_deal_differ.py @@ -4,67 +4,12 @@ from backend.app.db.models.organisation import HubspotDealData class HubspotDealDiffer: - - @staticmethod - def check_for_pashub_trigger( - new_deal: Dict[str, str], old_deal: HubspotDealData - ) -> bool: - """ - Case 1: PasHub Link is updated - Case 2: Coordination is completed (and PasHub Link is populated) - Case 3: Design is completed (and PasHub Link is populated) - Case 4: Lodgement is completed (and PasHub Link is populated) - """ - COORDINATION_COMPLETE: List[str] = [ - "v1 ioe/mtp complete", - "v2 ioe/mtp complete", - ] - RETROFIT_DESIGN_COMPLETE = "uploaded" - LODGEMENT_COMPLETE: List[str] = ["lodgement complete", "measures lodged"] - - new_pashub_link: str = new_deal.get("pashub_link", "") - - # Case 1 - if not new_pashub_link: - return False - - if not old_deal.pashub_link: - return True - - if old_deal.pashub_link != new_pashub_link: - return True - - # Case 2 - new_coordination_status: str = new_deal.get("coordination_status", "") - - if ( - new_coordination_status - and new_coordination_status in COORDINATION_COMPLETE - and new_coordination_status != old_deal.coordination_status - ): - return True - - # Case 3 - new_design_status: str = new_deal.get("design_status", "") - - if ( - new_design_status - and new_design_status == RETROFIT_DESIGN_COMPLETE - and new_design_status != old_deal.design_status - ): - return True - - # Case 4 - new_lodgement_status: str = new_deal.get("lodgement_status", "") - - if ( - new_lodgement_status - and new_lodgement_status in LODGEMENT_COMPLETE - and new_lodgement_status != old_deal.lodgement_status - ): - return True - - return False + COORDINATION_COMPLETE: List[str] = [ + "v1 ioe/mtp complete", + "v2 ioe/mtp complete", + ] + RETROFIT_DESIGN_COMPLETE = "uploaded" + LODGEMENT_COMPLETE: List[str] = ["lodgement complete", "measures lodged"] @staticmethod def check_for_db_update_trigger( @@ -74,3 +19,69 @@ class HubspotDealDiffer: old_deal: HubspotDealData, ) -> bool: raise NotImplementedError + + @staticmethod + def check_for_pashub_trigger( + new_deal: Dict[str, str], old_deal: HubspotDealData + ) -> bool: + new_pashub_link: str = new_deal.get("pashub_link", "") + + if not HubspotDealDiffer._has_valid_pashub_link(new_pashub_link): + return False + + if HubspotDealDiffer._new_or_updated_pashub_link(new_pashub_link, old_deal): + return True + + if HubspotDealDiffer._coordination_completed(new_deal, old_deal): + return True + + if HubspotDealDiffer._design_completed(new_deal, old_deal): + return True + + if HubspotDealDiffer._lodgement_completed(new_deal, old_deal): + return True + + return False + + @staticmethod + def _has_valid_pashub_link(new_pashub_link: str) -> bool: + return bool(new_pashub_link) + + @staticmethod + def _new_or_updated_pashub_link( + new_pashub_link: str, old_deal: HubspotDealData + ) -> bool: + if not old_deal.pashub_link: + return True + return old_deal.pashub_link != new_pashub_link + + @staticmethod + def _coordination_completed( + new_deal: Dict[str, str], old_deal: HubspotDealData + ) -> bool: + new_status: str = new_deal.get("coordination_status", "") + return ( + new_status != "" + and new_status in HubspotDealDiffer.COORDINATION_COMPLETE + and new_status != old_deal.coordination_status + ) + + @staticmethod + def _design_completed(new_deal: Dict[str, str], old_deal: HubspotDealData) -> bool: + new_status: str = new_deal.get("design_status", "") + return ( + new_status != "" + and new_status == HubspotDealDiffer.RETROFIT_DESIGN_COMPLETE + and new_status != old_deal.design_status + ) + + @staticmethod + def _lodgement_completed( + new_deal: Dict[str, str], old_deal: HubspotDealData + ) -> bool: + new_status: str = new_deal.get("lodgement_status", "") + return ( + new_status != "" + and new_status in HubspotDealDiffer.LODGEMENT_COMPLETE + and new_status != old_deal.lodgement_status + )