Implement support requests via Odoo

This commit is contained in:
Tobias Kunze 2025-06-22 19:04:45 +02:00
parent 6e88969677
commit 631f726691
11 changed files with 144 additions and 1 deletions

View file

@ -66,3 +66,5 @@ SERVALA_ODOO_DB=''
SERVALA_ODOO_URL=''
SERVALA_ODOO_USERNAME=''
SERVALA_ODOO_PASSWORD=''
# Helpdesk team ID for support tickets in Odoo. Defaults to 5.
SERVALA_ODOO_HELPDESK_TEAM_ID='5'

View file

@ -58,6 +58,7 @@ class Organization(ServalaModelMixin, models.Model):
details = "{base}details/"
services = "{base}services/"
instances = "{base}instances/"
support = "{base}support/"
@cached_property
def slug(self):

View file

@ -93,3 +93,24 @@ class User(ServalaModelMixin, PermissionsMixin, AbstractBaseUser):
)
if result:
return result[0]
def get_or_create_odoo_contact(self, organization):
if (
not organization.billing_entity
or not organization.billing_entity.odoo_company_id
):
return None
if existing_contact := self.get_odoo_contact(organization):
return existing_contact["id"]
partner_data = {
"name": f"{self.first_name} {self.last_name}".strip() or self.email,
"email": self.email,
"company_type": "person",
"type": "contact",
"parent_id": organization.billing_entity.odoo_company_id,
}
contact_id = odoo.CLIENT.execute("res.partner", "create", [partner_data])
return contact_id

View file

@ -1,4 +1,5 @@
from .organization import OrganizationForm
from .profile import UserProfileForm
from .support import SupportForm
__all__ = ["OrganizationForm", "UserProfileForm"]
__all__ = ["OrganizationForm", "UserProfileForm", "SupportForm"]

View file

@ -0,0 +1,10 @@
from django import forms
from django.utils.translation import gettext_lazy as _
class SupportForm(forms.Form):
message = forms.CharField(
label=_("Message"),
widget=forms.Textarea(attrs={"rows": 8}),
help_text=_("Please describe your issue or question in detail."),
)

View file

@ -0,0 +1,43 @@
{% extends "frontend/base.html" %}
{% load i18n %}
{% block html_title %}
{% block page_title %}
{% translate "Support" %}
{% endblock page_title %}
{% endblock html_title %}
{% block content %}
<section class="section">
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-content">
<div class="card-body">
<h5>{% translate "Get Support" %}</h5>
<p class="text-muted">
{% translate "Need help? Submit your question or issue below and our support team will get back to you." %}
</p>
<form method="post">
{% csrf_token %}
{% translate "Submit Support Request" as form_submit_label %}
{% include "includes/form.html" with form=form %}
</form>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-header">
<h4>{% translate "Support Information" %}</h4>
</div>
<div class="card-body">
<p class="small text-muted">
{% translate "When you submit a support request, it will be sent to our support team who will respond via email." %}
</p>
<p class="small text-muted">{% translate "For urgent issues, please contact us directly." %}</p>
</div>
</div>
</div>
</div>
</section>
{% endblock content %}

View file

@ -32,6 +32,13 @@
</span>
</a>
</li>
<li class="menu-item">
<a href="{{ request.organization.urls.support }}" class='menu-link'>
<span>
<i class="bi bi-question-circle"></i>
{% translate "Support" %}</span>
</a>
</li>
</ul>
</div>
</nav>

View file

@ -61,6 +61,11 @@ urlpatterns = [
views.ServiceInstanceDeleteView.as_view(),
name="organization.instance.delete",
),
path(
"support/",
views.SupportView.as_view(),
name="organization.support",
),
]
),
),

View file

@ -14,6 +14,7 @@ from .service import (
ServiceListView,
ServiceOfferingDetailView,
)
from .support import SupportView
__all__ = [
"IndexView",
@ -29,6 +30,7 @@ __all__ = [
"ServiceListView",
"ServiceOfferingDetailView",
"ProfileView",
"SupportView",
"custom_404",
"custom_403",
"custom_500",

View file

@ -0,0 +1,50 @@
from django.conf import settings
from django.contrib import messages
from django.shortcuts import redirect
from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView
from servala.core.odoo import CLIENT
from servala.frontend.forms.support import SupportForm
from servala.frontend.views.mixins import OrganizationViewMixin
class SupportView(OrganizationViewMixin, FormView):
form_class = SupportForm
template_name = "frontend/organizations/support.html"
def form_valid(self, form):
message = form.cleaned_data["message"]
organization = self.organization
user = self.request.user
try:
partner_id = user.get_or_create_odoo_contact(organization)
if not partner_id:
raise Exception("Could not get or create Odoo contact for user")
ticket_data = {
"name": f"Servala Support - Organization {organization.name}",
"team_id": settings.ODOO["HELPDESK_TEAM_ID"],
"partner_id": partner_id,
"sale_order_id": organization.odoo_sale_order_id,
"description": message,
}
CLIENT.execute("helpdesk.ticket", "create", [ticket_data])
messages.success(
self.request,
_(
"Your support request has been submitted successfully. We will contact you shortly."
),
)
except Exception as e:
messages.error(
self.request,
_(
"There was an error submitting your support request. Please try again or contact us directly."
),
)
print(f"Error creating helpdesk ticket: {e}")
return redirect(self.request.path)

View file

@ -131,6 +131,7 @@ ODOO = {
"DB": os.environ.get("SERVALA_ODOO_DB"),
"USERNAME": os.environ.get("SERVALA_ODOO_USERNAME"),
"PASSWORD": os.environ.get("SERVALA_ODOO_PASSWORD"),
"HELPDESK_TEAM_ID": int(os.environ.get("SERVALA_ODOO_HELPDESK_TEAM_ID", "5")),
}
#######################################