Skip to content

Commit

Permalink
Merge pull request #23 from Domatix/13.0-web
Browse files Browse the repository at this point in the history
13.0 web
  • Loading branch information
alvaro-domatix authored May 19, 2020
2 parents 50cd5d4 + 6c91fde commit f84a035
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 298 deletions.
2 changes: 1 addition & 1 deletion helpdesk_mgmt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"SDi Soluciones, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/helpdesk",
"depends": ["mail", "portal"],
"depends": ["mail", "portal", "website"],
"data": [
"data/helpdesk_data.xml",
"data/ir_cron.xml",
Expand Down
192 changes: 132 additions & 60 deletions helpdesk_mgmt/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,65 @@


class HelpdeskTicketController(http.Controller):
@http.route("/ticket/close", type="http", auth="user")
def support_ticket_close(self, **kw):
"""Close the support ticket"""
values = {}
for field_name, field_value in kw.items():
if field_name.endswith("_id"):
values[field_name] = int(field_value)
else:
values[field_name] = field_value
ticket = (
http.request.env["helpdesk.ticket"]
@http.route("/help", type="http", auth="public", website=True)
def render_public_ticket(self):
"""
:return: rendered template
"""

user_email = None
user_name = None
user_id = None
if not request.env.ref("base.public_user").id == request.env.user.id:
user_email = http.request.env.user.email
user_name = http.request.env.user.name
user_id = http.request.env.user.id
category_ids = (
http.request.env["helpdesk.ticket.category"]
.with_user(SUPERUSER_ID)
.search([("id", "=", values["ticket_id"])])
.search([("active", "=", True)])
)
ticket.stage_id = values.get("stage_id")

return werkzeug.utils.redirect("/my/ticket/" + str(ticket.id))

@http.route("/new/ticket", type="http", auth="user", website=True)
def create_new_ticket(self, **kw):
categories = http.request.env["helpdesk.ticket.category"].search(
[("active", "=", True)]
)
email = http.request.env.user.email
name = http.request.env.user.name
return http.request.render(
"helpdesk_mgmt.portal_create_ticket",
{"categories": categories, "email": email, "name": name},
{
"email": user_email,
"name": user_name,
"id_user": user_id,
"categories": category_ids,
},
)

@http.route("/submitted/ticket", type="http", auth="user", website=True, csrf=True)
@http.route("/help/ticket/submit", type="http", auth="public", website=True)
def submit_ticket(self, **kw):
vals = {
"""
Main submit endpoint which receives calls from public and private rendering
endpoints
:param kw: values
:return: a redirection to the thankyou endpoint
"""

values = {
"partner_name": kw.get("name"),
"company_id": http.request.env.user.company_id.id,
"category_id": kw.get("category"),
"partner_email": kw.get("email"),
"description": kw.get("description"),
"name": kw.get("subject"),
"attachment_ids": False,
"channel_id": request.env["helpdesk.ticket.channel"]
.with_user(SUPERUSER_ID)
.search([("name", "=", "Web")])
.id,
"partner_id": request.env["res.partner"]
.with_user(SUPERUSER_ID)
.search([("name", "=", kw.get("name")), ("email", "=", kw.get("email"))])
.id,
"company_id": http.request.env.user.company_id.id,
"channel_id": self._search_id_channel(),
"partner_id": self._search_id_partner(kw),
}
new_ticket = request.env["helpdesk.ticket"].with_user(SUPERUSER_ID).create(vals)

id_team = kw.get("id_team")
if id_team and str.isdigit(id_team):
values.update({"team_id": int(id_team)})

new_ticket = (
request.env["helpdesk.ticket"].with_user(SUPERUSER_ID).create(values)
)
new_ticket.message_subscribe(partner_ids=request.env.user.partner_id.ids)

if kw.get("attachment"):
for c_file in request.httprequest.files.getlist("attachment"):
data = c_file.read()
Expand All @@ -75,30 +83,65 @@ def submit_ticket(self, **kw):
"res_id": new_ticket.id,
}
)
return werkzeug.utils.redirect("/my/tickets")
return werkzeug.utils.redirect("/help/thankyou")

@http.route("/help/ticket/close", type="http", auth="user")
def support_ticket_close(self, **kw):
"""Close the support ticket"""
values = {}
for field_name, field_value in kw.items():
if field_name.endswith("_id"):
values[field_name] = int(field_value)
else:
values[field_name] = field_value
ticket = (
http.request.env["helpdesk.ticket"]
.with_user(SUPERUSER_ID)
.search([("id", "=", values["ticket_id"])])
)
ticket.stage_id = values.get("stage_id")

return werkzeug.utils.redirect("/my/ticket/%s" % str(ticket.id))

class HelpdeskTeamForm(http.Controller):
@http.route("/helpdesk/<string:endpoint>", type="http", auth="user", website=True)
@http.route("/help/thankyou", type="http", auth="public", website=True, csrf=True)
def thankyou_ticket(self):
return http.request.render("helpdesk_mgmt.portal_thankyou_ticket")

@http.route(
"/help/team/<string:endpoint>", type="http", auth="public", website=True
)
def create_new_team_ticket(self, endpoint):
team_id = self._team_exists(endpoint)
r = False # don't brake the flow ~~
user_email = None
user_name = None
user_id = None
if not request.env.ref("base.public_user").id == request.env.user.id:
user_email = http.request.env.user.email
user_name = http.request.env.user.name
user_id = http.request.env.user.id
category_ids = (
http.request.env["helpdesk.ticket.category"]
.with_user(SUPERUSER_ID)
.search([("active", "=", True)])
)
team_id = self._search_team_id(endpoint)
r = False # maybe some day someone'll make a cool error template
if team_id:
email = http.request.env.user.email
name = http.request.env.user.name
r = http.request.render(
"helpdesk_mgmt.portal_create_team_ticket",
{"email": email, "name": name, "id_team": team_id.id},
)

r = False
if team_id.alias_contact == "everyone" or user_id:
r = http.request.render(
"helpdesk_mgmt.portal_create_ticket",
{
"email": user_email,
"name": user_name,
"id_team": team_id.id,
"id_user": user_id,
"categories": category_ids,
},
)
return r

@http.route(
"/helpdesk/ticket/team/submit",
type="http",
auth="user",
website=True,
csrf=True,
"/help/ticket/team/submit", type="http", auth="user", website=True, csrf=True,
)
def submit_new_team_ticket(self, **kw):
values = {
Expand All @@ -108,12 +151,10 @@ def submit_new_team_ticket(self, **kw):
"partner_email": kw.get("email"),
"description": kw.get("description"),
"name": kw.get("subject"),
"team_id": kw.get("id_team"),
"team_id": int(kw.get("id_team")),
"attachment_ids": False,
"partner_id": request.env["res.partner"]
.with_user(SUPERUSER_ID)
.search([("name", "=", kw.get("name")), ("email", "=", kw.get("email"))])
.id,
"partner_id": self._search_id_partner(kw),
"channel_id": self._search_id_channel(),
}
new_ticket = (
request.env["helpdesk.ticket"].with_user(SUPERUSER_ID).create(values)
Expand All @@ -135,7 +176,38 @@ def submit_new_team_ticket(self, **kw):
return werkzeug.utils.redirect("/my/tickets")

@staticmethod
def _team_exists(endpoint: str):
return request.env["helpdesk.ticket.team"].search(
[("endpoint_webform", "=", endpoint), ("enable_webform", "=", True)]
def _search_id_partner(kw: dict) -> int:
id_partner = kw.get("id_partner")
if id_partner and str.isdigit(id_partner):
id_partner = int(id_partner)
else:
partner_id = (
request.env["res.partner"]
.with_user(SUPERUSER_ID)
.search([("email", "=", kw.get("email"))])
)
id_partner = partner_id[0].id if partner_id else None
return id_partner

@staticmethod
def _search_id_channel() -> int:
channel_id = (
request.env["helpdesk.ticket.channel"]
.with_user(SUPERUSER_ID)
.search([("name", "=", "Web")])
)
return channel_id[0].id if channel_id else None

def _search_id_team(self, endpoint: str) -> int:
team_id = self._search_team_id(endpoint)
return team_id[0].id if team_id else None

@staticmethod
def _search_team_id(endpoint: str):
return (
request.env["helpdesk.ticket.team"]
.with_user(SUPERUSER_ID)
.search(
[("endpoint_webform", "=", endpoint), ("enable_webform", "=", True)]
)
)
12 changes: 8 additions & 4 deletions helpdesk_mgmt/data/helpdesk_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
<field name="email_from">${object.company_id.partner_id.email}</field>
<field
name="email_cc"
>${not object.partner_id and object.partner_email or ''|safe},</field>
>${not object.partner_id and object.partner_email or ''|safe},
</field>
<field
name="subject"
>${object.company_id.name} Ticket Assignment (Ref ${object.number or 'n/a' })</field>
>${object.company_id.name} Ticket Assignment (Ref ${object.number or 'n/a' })
</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="auto_delete" eval="False" />
<field name="lang">${object.partner_id.lang}</field>
Expand All @@ -33,7 +35,8 @@
<field name="email_from">${object.company_id.partner_id.email}</field>
<field
name="email_cc"
>${not object.partner_id and object.partner_email or ''|safe},</field>
>${not object.partner_id and object.partner_email or ''|safe},
</field>
<field name="subject">The ticket ${object.number} has been closed.</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="auto_delete" eval="False" />
Expand Down Expand Up @@ -100,7 +103,8 @@
<field name="email_from">${object.company_id.partner_id.email}</field>
<field
name="email_cc"
>${not object.partner_id and object.partner_email or ''|safe},</field>
>${not object.partner_id and object.partner_email or ''|safe},
</field>
<field name="subject">The ticket ${object.number} stage has changed.</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="auto_delete" eval="False" />
Expand Down
1 change: 0 additions & 1 deletion helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def _compute_automatic_user_assignment(self):
:return: user_id: for debugging purposes, as computation methods
have to assign the value directly to the field
"""

if self.team_id.auto_assign_type != "manual" and not self.user_id:
if (
self.team_id.auto_assign_type == "fixed"
Expand Down
3 changes: 1 addition & 2 deletions helpdesk_mgmt/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _compute_endpoint_webform(self):
if record.env[record._name].search(domain):
_endpoint += "-{}".format(record.id)
record.endpoint_webform = _endpoint
record.endpoint_full_webform = "helpdesk/{}".format(
record.endpoint_full_webform = "help/team/{}".format(
record.endpoint_webform
)

Expand Down Expand Up @@ -108,7 +108,6 @@ def _compute_endpoint_webform(self):
@api.depends("ticket_ids", "ticket_ids.stage_id")
def _compute_todo_tickets(self):
for record in self:

_todo_ticket_ids = record.todo_ticket_ids.filtered(lambda x: not x.closed)
record.todo_ticket_count = len(_todo_ticket_ids)
record.todo_ticket_count_unassigned = len(
Expand Down
4 changes: 2 additions & 2 deletions helpdesk_mgmt/tests/test_helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_getters(self):
self.team_id._compute_endpoint_webform()
self.assertEqual(self.team_id.endpoint_webform, team_endpoint)
self.assertEqual(
self.team_id.endpoint_full_webform, "helpdesk/{}".format(team_endpoint)
self.team_id.endpoint_full_webform, "help/team/{}".format(team_endpoint)
)

_team_id = self.env["helpdesk.ticket.team"].create({"name": "Team 1"})
Expand All @@ -89,5 +89,5 @@ def test_getters(self):
)
self.assertEqual(
_team_id.endpoint_full_webform,
"helpdesk/{}-{}".format(team_endpoint, _team_id.id),
"help/team/{}-{}".format(team_endpoint, _team_id.id),
)
Loading

0 comments on commit f84a035

Please sign in to comment.