From 2ccee63a8c8a3265fe0f65a78d7ba0f60445f010 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Wed, 16 Apr 2025 11:10:20 +0000 Subject: [PATCH] deem score calcualted with hubspot and sharepoint integration --- etl/hubSpotClient/hubspot.py | 15 ++++++++++++++- etl/hubspot_to_invoice.py | 8 ++++++-- etl/surveyPrice/surveyPrice.py | 17 +++++------------ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/etl/hubSpotClient/hubspot.py b/etl/hubSpotClient/hubspot.py index 64aea46..cf022e6 100644 --- a/etl/hubSpotClient/hubspot.py +++ b/etl/hubSpotClient/hubspot.py @@ -1,12 +1,14 @@ import hubspot from enum import Enum from hubspot.crm.deals import PublicObjectSearchRequest +from hubspot.crm.deals.models import SimplePublicObjectInput from etl.hubSpotClient.types import SubmissionInfoFromDeal class DealStage(Enum): SURVEYED_COMPLETE_NEEDS_SIGN_OFF = "1617223914" SURVEYED_NO_ACCESS_NEED_SIGN_OFF = "1617223915" CUSTOMER_CONTACTED = "888730834" + SURVEYED_COMPLETED_SIGNED_OFF = "1617223916" class HubSpotClient(): def __init__(self): @@ -69,4 +71,15 @@ class HubSpotClient(): print(f" - Label: {stage.label}") print(f" ID: {stage.id}") - + def move_deals_to_different_stage(self, list_of_deals_id, to_stage_id): + deal_properties = SimplePublicObjectInput( + properties={ + "dealstage": to_stage_id + } + ) + for deal_id in list_of_deals_id: + self.client.crm.deals.basic_api.update( + deal_id, + simple_public_object_input=deal_properties + ) + print(f"Deal {deal_id} moved to stage with ID {to_stage_id}.") diff --git a/etl/hubspot_to_invoice.py b/etl/hubspot_to_invoice.py index 156b2c7..d8473f7 100644 --- a/etl/hubspot_to_invoice.py +++ b/etl/hubspot_to_invoice.py @@ -28,10 +28,14 @@ output_path = os.path.abspath(lewis_view) sp.upload_to_sharepoint(output_path, lewis_view) +deal_ids = df["HUBSPOT_DEAL_ID"].tolist() + +sp.move_deals_to_completed(deal_ids) + # TODO: -# Move deal in hub spot Surveyoed complete signed off, if normal # Write documentation for tech demos from Khalims demo -# Look into getting solar working. ACIS and Lewis +# Look into getting 'solar' pricing working. ACIS and Lewis Billignham for examples # Figure out what to do if I see an address that isn't registered but surveyrod +# Review deem score with last weeks deem score values to ensure accuracy diff --git a/etl/surveyPrice/surveyPrice.py b/etl/surveyPrice/surveyPrice.py index 596c006..34eda07 100644 --- a/etl/surveyPrice/surveyPrice.py +++ b/etl/surveyPrice/surveyPrice.py @@ -132,6 +132,11 @@ class SurveyPrice(): self.all_hubspot_submissions = pd.DataFrame(all_deals) return self.all_hubspot_submissions + def move_deals_to_completed(self, deals): + hubspot = HubSpotClient() + hubspot.move_deals_to_different_stage(deals, DealStage.SURVEYED_COMPLETED_SIGNED_OFF.value) + + def get_all_surveyed_data_from_sharepoint(self): # TODO: rewrite the function so I pass in sharepointInstaller instead so I can re use the same function for # DIfferent installers @@ -301,15 +306,3 @@ class SurveyPrice(): sharepoint_path = parent_folder + "/" + date self.sharepoint_client.upload_file(file_path_to_upload, sharepoint_path, file_name) - - -# TODO -# Get it working for JJC first, with an idea to make it more diverse -# Add some TDD to ensure JJC values are correct -# The script can run weekly, for development I can just get one data -# Upload both the W.C. calculations and Rate Card to sharepoint -# Due considerations -> Piece of UI, as osmosis, dashboard upload and pushes site notes database and condition report to database. Link the two, make a due consideration report, due consideration report, propery_id () -# Property Tbale - -# Add hubspot deal id into pandas -# Deem score and move deal id to 'Surveyed Completed Signed off"