Overhaul Forms

This commit is contained in:
Tobias Brunner 2025-03-03 14:30:05 +01:00
parent 25b91fb01b
commit 091e62b03c
16 changed files with 384 additions and 384 deletions

View file

@ -53,56 +53,21 @@ class OdooAPI:
logger.debug("Full error details:", exc_info=True)
raise
def create_lead(self, lead, source="form"):
def create_lead(self, lead, lead_title=""):
"""Create a lead in Odoo"""
try:
logger.info(f"Attempting to create lead for {lead.name}")
# Prepare service description
service_details = []
if hasattr(lead, "service") and lead.service:
service_details.append(f"Service: {lead.service.name}")
# Get provider name from offering if it exists
if (
hasattr(lead, "offering")
and lead.offering
and hasattr(lead.offering, "cloud_provider")
):
provider_name = lead.offering.cloud_provider.name
service_details.append(f"Provider: {provider_name}")
if hasattr(lead, "plan") and lead.plan:
service_details.append(f"Plan: {lead.plan.name}")
if source == "form":
service_details.append(f"Source: Servala Website")
elif source == "osbapi":
service_details.append(f"Source: OSB API")
elif source == "contact_form":
service_details.append(f"Source: Contact Form")
# Prepare lead name based on whether it's a service lead or generic contact
if hasattr(lead, "service") and lead.service:
lead_name = f"Servala - Interest in {lead.service.name}"
else:
lead_name = "Servala - Website Contact"
# Prepare lead data
lead_data = {
"name": lead_name,
"name": "Servala" + lead_title,
"contact_name": lead.name,
"partner_name": (
lead.company if hasattr(lead, "company") and lead.company else ""
),
"email_from": lead.email,
"phone": lead.phone if hasattr(lead, "phone") and lead.phone else "",
"description": (
f"{lead.message}<br/><br/>" + "<br/>".join(service_details)
if lead.message
else "<br/>".join(service_details)
),
"description": lead.message,
"type": "lead",
"campaign_id": settings.ODOO_CONFIG["campaign_id"],
"source_id": settings.ODOO_CONFIG["source_id"],
@ -122,60 +87,6 @@ class OdooAPI:
odoo_lead_id = Lead.create(lead_data)
logger.info(f"Successfully created lead in Odoo with ID: {odoo_lead_id}")
# Post message in chatter
if hasattr(lead, "service") and lead.service:
# For service-related leads
message_data = {
"body": f"""
<p>Thank you for your interest in the service <strong>{lead.service.name}</strong>.
We recorded the following information and will get back to you soon:</p><br/>
<p>Contact Details:</p>
<ul>
<li><strong>Name:</strong> {lead.name}</li>
<li><strong>Company:</strong> {lead.company if hasattr(lead, "company") and lead.company else "N/A"}</li>
<li><strong>Email:</strong> {lead.email}</li>
<li><strong>Phone:</strong> {lead.phone if hasattr(lead, "phone") and lead.phone else "N/A"}</li>
</ul>
<p>Service Details:<p>
<ul>
<li><strong>Service:</strong> {lead.service.name}</li>
{f'<li><strong>Provider:</strong> {provider_name}</li>' if provider_name else ''}
{f'<li><strong>Plan:</strong> {lead.plan.name}</li>' if lead.plan else ''}
</ul>
""",
"message_type": "comment",
"subtype_xmlid": "mail.mt_comment",
}
else:
# For contact form submissions
message_data = {
"body": f"""
<p>Thank you for contacting Servala by VSHN.<br/>
We recorded the following information and will get back to you soon:</p><br/>
<p>Contact Details:</p>
<ul>
<li><strong>Name:</strong> {lead.name}</li>
<li><strong>Email:</strong> {lead.email}</li>
{f'<li><strong>Phone:</strong> {lead.phone}</li>' if lead.phone else ''}
{f'<li><strong>Company:</strong> {lead.company}</li>' if lead.company else ''}
{f'<li><strong>Message:</strong> {lead.message}</li>' if lead.message else ''}
</ul>
""",
"message_type": "comment",
"subtype_xmlid": "mail.mt_comment",
}
# Post the message
self.odoo.env["crm.lead"].browse(odoo_lead_id).message_post(
body=message_data["body"],
message_type=message_data["message_type"],
subtype_xmlid=message_data["subtype_xmlid"],
)
logger.info(f"Successfully posted message to lead {odoo_lead_id}")
return odoo_lead_id
except odoorpc.error.RPCError as e: