generic contact form

This commit is contained in:
Tobias Brunner 2025-02-27 15:44:55 +01:00
parent eece05af74
commit 2cbcc4ba98
No known key found for this signature in database
9 changed files with 280 additions and 48 deletions

View file

@ -56,36 +56,48 @@ class OdooAPI:
def create_lead(self, lead, source="form"):
"""Create a lead in Odoo"""
try:
logger.info(
f"Attempting to create lead for {lead.name} from {lead.company}"
)
# Get provider name from offering if it exists
provider_name = ""
if hasattr(lead, "offering") and lead.offering:
provider_name = lead.offering.cloud_provider.name
logger.info(f"Attempting to create lead for {lead.name}")
# Prepare service description
service_details = []
if lead.service:
if hasattr(lead, "service") and lead.service:
service_details.append(f"Service: {lead.service.name}")
if provider_name:
service_details.append(f"Provider: {provider_name}")
if lead.plan:
service_details.append(f"Plan: {lead.plan.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": f"Servala - Interest in {lead.service.name}",
"name": lead_name,
"contact_name": lead.name,
"partner_name": lead.company,
"partner_name": (
lead.company if hasattr(lead, "company") and lead.company else ""
),
"email_from": lead.email,
"phone": lead.phone,
"phone": lead.phone if hasattr(lead, "phone") and lead.phone else "",
"description": (
f"{lead.message}<br/><br/>" + "<br/>".join(service_details)
if lead.message
@ -111,29 +123,50 @@ class OdooAPI:
logger.info(f"Successfully created lead in Odoo with ID: {odoo_lead_id}")
# Post message in chatter
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}</li>
<li><strong>Email:</strong> {lead.email}</li>
<li><strong>Phone:</strong> {lead.phone}</li>
</ul>
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",
}
<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(