diff --git a/helpdesk_mgmt/__manifest__.py b/helpdesk_mgmt/__manifest__.py index 8dcaea5819..a5bb12ffff 100644 --- a/helpdesk_mgmt/__manifest__.py +++ b/helpdesk_mgmt/__manifest__.py @@ -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", diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index bb51b1dfc5..c0d75cbcc2 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -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() @@ -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/", 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/", 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 = { @@ -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) @@ -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)] + ) ) diff --git a/helpdesk_mgmt/data/helpdesk_data.xml b/helpdesk_mgmt/data/helpdesk_data.xml index 1c7fcdb2f3..f7c0bb003f 100644 --- a/helpdesk_mgmt/data/helpdesk_data.xml +++ b/helpdesk_mgmt/data/helpdesk_data.xml @@ -15,10 +15,12 @@ ${object.company_id.partner_id.email} ${not object.partner_id and object.partner_email or ''|safe}, + >${not object.partner_id and object.partner_email or ''|safe}, + ${object.company_id.name} Ticket Assignment (Ref ${object.number or 'n/a' }) + >${object.company_id.name} Ticket Assignment (Ref ${object.number or 'n/a' }) + ${object.partner_id.id} ${object.partner_id.lang} @@ -33,7 +35,8 @@ ${object.company_id.partner_id.email} ${not object.partner_id and object.partner_email or ''|safe}, + >${not object.partner_id and object.partner_email or ''|safe}, + The ticket ${object.number} has been closed. ${object.partner_id.id} @@ -100,7 +103,8 @@ ${object.company_id.partner_id.email} ${not object.partner_id and object.partner_email or ''|safe}, + >${not object.partner_id and object.partner_email or ''|safe}, + The ticket ${object.number} stage has changed. ${object.partner_id.id} diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index c05038283e..50124626fb 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -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" diff --git a/helpdesk_mgmt/models/helpdesk_ticket_team.py b/helpdesk_mgmt/models/helpdesk_ticket_team.py index 7c0012afca..c2430f816d 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_team.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_team.py @@ -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 ) @@ -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( diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py b/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py index bca0a36b47..815b2ad223 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py @@ -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"}) @@ -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), ) diff --git a/helpdesk_mgmt/views/helpdesk_ticket_templates.xml b/helpdesk_mgmt/views/helpdesk_ticket_templates.xml index 6f404e6aaa..dc5c2961d0 100644 --- a/helpdesk_mgmt/views/helpdesk_ticket_templates.xml +++ b/helpdesk_mgmt/views/helpdesk_ticket_templates.xml @@ -11,10 +11,8 @@ t-if="page_name == 'ticket' or ticket" t-attf-class="breadcrumb-item #{'active ' if not ticket else ''}" > - Tickets + Tickets + Tickets