Feat: End-to-End Test & Bidirectional Vertical Sync [30e88f42]
- Implemented comprehensive E2E test covering full roundtrip and manual overrides. - Enhanced to detect manual Vertical changes in SuperOffice and sync them to Company Explorer. - Updated to handle industry overrides from CRM and auto-persist Person/Contact data for robust cascade updates.
This commit is contained in:
@@ -37,6 +37,12 @@ def process_job(job, so_client: SuperOfficeClient):
|
||||
# Define what we care about (Strategic triggers for re-evaluation)
|
||||
# Company: Name/Department (Identity), Urls (Source), Numbers (Matching)
|
||||
relevant_contact = ["name", "department", "urladdress", "number1", "number2"]
|
||||
# Add Vertical UDF to relevant changes
|
||||
if settings.UDF_VERTICAL:
|
||||
relevant_contact.append(settings.UDF_VERTICAL.lower())
|
||||
# Also catch generic "userdefinedfields" if specific key not present
|
||||
relevant_contact.append("userdefinedfields")
|
||||
|
||||
# Person: JobTitle (Persona Logic), Position (Role Logic)
|
||||
relevant_person = ["jobtitle", "position"]
|
||||
|
||||
@@ -100,6 +106,9 @@ def process_job(job, so_client: SuperOfficeClient):
|
||||
# 1b. Fetch full contact details for 'Double Truth' check (Master Data Sync)
|
||||
crm_name = None
|
||||
crm_website = None
|
||||
crm_industry_name = None
|
||||
contact_details = None
|
||||
|
||||
try:
|
||||
contact_details = so_client.get_contact(contact_id)
|
||||
if contact_details:
|
||||
@@ -107,6 +116,28 @@ def process_job(job, so_client: SuperOfficeClient):
|
||||
crm_website = contact_details.get("UrlAddress")
|
||||
if not crm_website and "Urls" in contact_details and contact_details["Urls"]:
|
||||
crm_website = contact_details["Urls"][0].get("Value")
|
||||
|
||||
# Extract Vertical (if set in SO)
|
||||
if settings.UDF_VERTICAL:
|
||||
udfs = contact_details.get("UserDefinedFields", {})
|
||||
so_vertical_val = udfs.get(settings.UDF_VERTICAL)
|
||||
|
||||
if so_vertical_val:
|
||||
# Normalize "[I:23]" -> "23"
|
||||
val_str = str(so_vertical_val)
|
||||
if val_str.startswith("[I:"):
|
||||
val_str = val_str.split(":")[1].strip("]")
|
||||
|
||||
# Reverse Map ID -> Name
|
||||
try:
|
||||
vertical_map = json.loads(settings.VERTICAL_MAP_JSON)
|
||||
vertical_map_rev = {str(v): k for k, v in vertical_map.items()}
|
||||
if val_str in vertical_map_rev:
|
||||
crm_industry_name = vertical_map_rev[val_str]
|
||||
logger.info(f"Detected CRM Vertical Override: {so_vertical_val} -> {crm_industry_name}")
|
||||
except Exception as ex:
|
||||
logger.error(f"Error mapping vertical ID {val_str}: {ex}")
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch contact details for {contact_id}: {e}")
|
||||
|
||||
@@ -117,7 +148,8 @@ def process_job(job, so_client: SuperOfficeClient):
|
||||
"so_person_id": person_id,
|
||||
"job_title": payload.get("JobTitle"),
|
||||
"crm_name": crm_name,
|
||||
"crm_website": crm_website
|
||||
"crm_website": crm_website,
|
||||
"crm_industry_name": crm_industry_name
|
||||
}
|
||||
|
||||
# Simple Basic Auth for internal API
|
||||
|
||||
Reference in New Issue
Block a user