[30388f42] fix: Stabilize competitor-analysis and content-engine services
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
import datetime
|
||||
from config import settings
|
||||
import logging
|
||||
|
||||
@@ -185,7 +186,58 @@ class SuperOfficeClient:
|
||||
logger.error(f"❌ API Search Error for {query_string}: {e.response.text}")
|
||||
return None
|
||||
|
||||
return all_results
|
||||
return all_results
|
||||
|
||||
def find_contact_by_criteria(self, name=None, email=None):
|
||||
"""Searches for a contact by name or email."""
|
||||
if name:
|
||||
query = f"Contact?$filter=name eq '{name}'"
|
||||
elif email:
|
||||
# Note: This depends on the specific SO API version/setup for email filtering
|
||||
query = f"Contact?$filter=email/address eq '{email}'"
|
||||
else:
|
||||
return None
|
||||
|
||||
results = self.search(query)
|
||||
# Handle OData 'value' wrap if search doesn't do it
|
||||
return results[0] if results else None
|
||||
|
||||
def create_contact(self, name: str, url: str = None, org_nr: str = None):
|
||||
"""Creates a new contact."""
|
||||
payload = {
|
||||
"Name": name,
|
||||
"UrlAddress": url,
|
||||
"OrgNr": org_nr
|
||||
}
|
||||
return self._post("Contact", payload)
|
||||
|
||||
def create_person(self, first_name: str, last_name: str, contact_id: int, email: str = None):
|
||||
"""Creates a new person linked to a contact."""
|
||||
payload = {
|
||||
"Firstname": first_name,
|
||||
"Lastname": last_name,
|
||||
"ContactId": contact_id
|
||||
}
|
||||
if email:
|
||||
payload["Emails"] = [{"Value": email, "Description": "Primary", "IsPrimary": True}]
|
||||
|
||||
return self._post("Person", payload)
|
||||
|
||||
def create_sale(self, title: str, contact_id: int, person_id: int = None, amount: float = 0.0):
|
||||
"""Creates a new sale."""
|
||||
payload = {
|
||||
"Heading": title,
|
||||
"ContactId": contact_id,
|
||||
"Amount": amount,
|
||||
"Saledate": datetime.datetime.utcnow().isoformat() + "Z",
|
||||
"Probablity": 50,
|
||||
"Status": "Open"
|
||||
}
|
||||
if person_id:
|
||||
payload["PersonId"] = person_id
|
||||
|
||||
return self._post("Sale", payload)
|
||||
|
||||
def create_project(self, name: str, contact_id: int, person_id: int = None):
|
||||
"""Creates a new project linked to a contact, and optionally adds a person."""
|
||||
payload = {
|
||||
@@ -206,7 +258,6 @@ class SuperOfficeClient:
|
||||
|
||||
def create_appointment(self, subject: str, description: str, contact_id: int, person_id: int = None):
|
||||
"""Creates a new appointment (to simulate a sent activity)."""
|
||||
import datetime
|
||||
now = datetime.datetime.utcnow().isoformat() + "Z"
|
||||
|
||||
# SuperOffice UI limit: 42 chars.
|
||||
|
||||
Reference in New Issue
Block a user