niwayandm commited on
Commit
31b36e7
·
1 Parent(s): e438386

Add new properties to deals, tickes and companies

Browse files
python/hubspot_companies.py CHANGED
@@ -90,6 +90,7 @@ COMPANY_PROPERTIES = [
90
  "hs_analytics_source",
91
  "hs_analytics_latest_source",
92
  "hs_object_source_detail_1",
 
93
  ]
94
 
95
  # -----------------------------------------------------------------------------
@@ -375,6 +376,7 @@ def map_company_data_for_db(companies: List[Dict]) -> List[Dict]:
375
  "record_source_detail_1": c.get("hs_object_source_detail_1"),
376
  "original_traffic_source": c.get("hs_analytics_source"),
377
  "latest_traffic_source": c.get("hs_analytics_latest_source"),
 
378
  }
379
  mapped.append(enrich_supabase_row(base_row))
380
  return mapped
 
90
  "hs_analytics_source",
91
  "hs_analytics_latest_source",
92
  "hs_object_source_detail_1",
93
+ "average_deal_closed_days",
94
  ]
95
 
96
  # -----------------------------------------------------------------------------
 
376
  "record_source_detail_1": c.get("hs_object_source_detail_1"),
377
  "original_traffic_source": c.get("hs_analytics_source"),
378
  "latest_traffic_source": c.get("hs_analytics_latest_source"),
379
+ "average_deal_closed_days": try_parse_int(c.get("average_deal_closed_days")),
380
  }
381
  mapped.append(enrich_supabase_row(base_row))
382
  return mapped
python/hubspot_deals.py CHANGED
@@ -71,7 +71,8 @@ DEAL_PROPERTIES = [
71
  "hs_object_source_label",
72
  "hs_object_source_detail_1",
73
  "dealtype",
74
- "hs_lastmodifieddate", # for mapping/debugging
 
75
  "lastmodifieddate",
76
  ]
77
 
@@ -335,6 +336,7 @@ def read_deals_by_ids(
335
  "record_source": p.get("hs_object_source_label"),
336
  "record_source_detail_1": p.get("hs_object_source_detail_1"),
337
  "dealtype": p.get("dealtype"),
 
338
  "company_id": company_id,
339
  })
340
 
 
71
  "hs_object_source_label",
72
  "hs_object_source_detail_1",
73
  "dealtype",
74
+ "days_to_close",
75
+ "hs_lastmodifieddate",
76
  "lastmodifieddate",
77
  ]
78
 
 
336
  "record_source": p.get("hs_object_source_label"),
337
  "record_source_detail_1": p.get("hs_object_source_detail_1"),
338
  "dealtype": p.get("dealtype"),
339
+ "days_to_close": try_parse_int(p.get("days_to_close")),
340
  "company_id": company_id,
341
  })
342
 
python/hubspot_tickets.py CHANGED
@@ -28,7 +28,7 @@ from supabase import create_client
28
  from hubspot.crm.tickets import ApiException as TicketsApiException
29
 
30
  from hubspot_utils import (
31
- parse_ts, try_parse_int, deduplicate_by_key,
32
  )
33
  from supabase_utils import (
34
  batched_insert, update_sync_metadata,
@@ -85,6 +85,10 @@ TICKET_PROPERTIES = [
85
  "source_type",
86
  "hs_object_source_label",
87
  "hs_object_source_detail_1",
 
 
 
 
88
  ]
89
 
90
  # -----------------------------------------------------------------------------
@@ -284,6 +288,16 @@ def read_tickets_by_ids(
284
  if ts_ms is not None and (max_ts_ms is None or ts_ms > max_ts_ms):
285
  max_ts_ms = ts_ms
286
 
 
 
 
 
 
 
 
 
 
 
287
  tickets.append({
288
  "ticket_id": try_parse_int(record.id),
289
  "subject": p.get("subject"),
@@ -299,6 +313,10 @@ def read_tickets_by_ids(
299
  "source": p.get("source_type"),
300
  "record_source": p.get("hs_object_source_label"),
301
  "record_source_detail_1": p.get("hs_object_source_detail_1"),
 
 
 
 
302
  "hubspot_owner_id": try_parse_int(p.get("hubspot_owner_id")),
303
  "hubspot_created_at": parse_ts(p.get("createdate")),
304
  "hubspot_created_by": try_parse_int(p.get("hs_created_by_user_id")),
 
28
  from hubspot.crm.tickets import ApiException as TicketsApiException
29
 
30
  from hubspot_utils import (
31
+ parse_ts, try_parse_int, try_parse_float, deduplicate_by_key,
32
  )
33
  from supabase_utils import (
34
  batched_insert, update_sync_metadata,
 
85
  "source_type",
86
  "hs_object_source_label",
87
  "hs_object_source_detail_1",
88
+ "hs_is_closed",
89
+ "last_sales_reply",
90
+ "time_to_first_agent_reply",
91
+ "time_to_close",
92
  ]
93
 
94
  # -----------------------------------------------------------------------------
 
288
  if ts_ms is not None and (max_ts_ms is None or ts_ms > max_ts_ms):
289
  max_ts_ms = ts_ms
290
 
291
+ if try_parse_float(p.get("time_to_first_agent_reply")) is None:
292
+ time_to_first_agent_reply = None
293
+ else:
294
+ time_to_first_agent_reply = try_parse_float(p.get("time_to_first_agent_reply")) / 1000
295
+
296
+ if try_parse_float(p.get("time_to_close")) is None:
297
+ time_to_close = None
298
+ else:
299
+ time_to_close = try_parse_float(p.get("time_to_close")) / 1000
300
+
301
  tickets.append({
302
  "ticket_id": try_parse_int(record.id),
303
  "subject": p.get("subject"),
 
313
  "source": p.get("source_type"),
314
  "record_source": p.get("hs_object_source_label"),
315
  "record_source_detail_1": p.get("hs_object_source_detail_1"),
316
+ "is_closed": p.get("hs_is_closed"),
317
+ "last_sales_reply": p.get("last_sales_reply"),
318
+ "time_to_first_agent_reply": time_to_first_agent_reply,
319
+ "time_to_close": time_to_close,
320
  "hubspot_owner_id": try_parse_int(p.get("hubspot_owner_id")),
321
  "hubspot_created_at": parse_ts(p.get("createdate")),
322
  "hubspot_created_by": try_parse_int(p.get("hs_created_by_user_id")),