Skip to content

Commit

Permalink
[FIX] helpdesk_mgmt_timesheet: Ticket submit broken
Browse files Browse the repository at this point in the history
If `helpdesk_mgmt_project` is installed without
`helpdesk_mgmt_timesheet`, an `AttributeError` is raised when submitting
a new ticket
  • Loading branch information
ypapouin authored and vincent-hatakeyama committed Sep 14, 2023
1 parent 748d985 commit c683d2e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion helpdesk_mgmt/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _prepare_submit_ticket_vals(self, **kw):
"partner_name": request.env.user.partner_id.name,
"partner_email": request.env.user.partner_id.email,
}
if company.helpdesk_mgmt_portal_select_team:
if company.helpdesk_mgmt_portal_select_team and kw.get("team"):
team = (
http.request.env["helpdesk.ticket.team"]
.sudo()
Expand Down
47 changes: 24 additions & 23 deletions helpdesk_mgmt/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from odoo.addons.base.tests.common import HttpCaseWithUserPortal


class TestHelpdeskPortal(HttpCaseWithUserPortal):
class TestHelpdeskPortalBase(HttpCaseWithUserPortal):
"""Test controllers defined for portal mode.
This is mostly for basic coverage; we don't go as far as fully validating
HTML produced by our routes.
Expand Down Expand Up @@ -39,18 +39,31 @@ def setUp(self):
def get_new_tickets(self, user):
return self.env["helpdesk.ticket"].with_user(user).search([])

def _submit_ticket(self):
resp = self.url_open(
"/submitted/ticket",
data={
"category": self.env.ref("helpdesk_mgmt.helpdesk_category_1").id,
"csrf_token": http.Request.csrf_token(self),
"subject": self.new_ticket_title,
"description": "\n".join(self.new_ticket_desc_lines),
},
)
def _create_ticket(self, partner, ticket_title, **values):
"""Create a ticket submitted by the specified partner."""
data = {
"name": ticket_title,
"description": "portal-ticket-description",
"partner_id": partner.id,
"partner_email": partner.email,
"partner_name": partner.name,
}
data.update(**values)
return self.env["helpdesk.ticket"].create(data)

def _submit_ticket(self, **values):
data = {
"category": self.env.ref("helpdesk_mgmt.helpdesk_category_1").id,
"csrf_token": http.Request.csrf_token(self),
"subject": self.new_ticket_title,
"description": "\n".join(self.new_ticket_desc_lines),
}
data.update(**values)
resp = self.url_open("/submitted/ticket", data=data)
self.assertEqual(resp.status_code, 200)


class TestHelpdeskPortal(TestHelpdeskPortalBase):
def test_submit_ticket_01(self):
self.authenticate("test-basic-user", "test-basic-user")
self._submit_ticket()
Expand Down Expand Up @@ -190,15 +203,3 @@ def _call_close_ticket(self, ticket, stage):
self.assertTrue(resp.is_redirect) # http://127.0.0.1:8069/my/ticket/<ticket-id>
self.assertTrue(resp.headers["Location"].endswith(f"/my/ticket/{ticket.id}"))
return resp

def _create_ticket(self, partner, ticket_title):
"""Create a ticket submitted by the specified partner."""
return self.env["helpdesk.ticket"].create(
{
"name": ticket_title,
"description": "portal-ticket-description",
"partner_id": partner.id,
"partner_email": partner.email,
"partner_name": partner.name,
}
)
1 change: 0 additions & 1 deletion helpdesk_mgmt_project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models
from . import controllers
1 change: 1 addition & 0 deletions helpdesk_mgmt_timesheet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from . import models
from . import controllers
File renamed without changes.
1 change: 1 addition & 0 deletions helpdesk_mgmt_timesheet/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# For copyright and license notices, see __manifest__.py file in root directory
###############################################################################
from . import test_helpdesk_mgmt_timesheet
from . import test_helpdesk_portal
from . import test_helpdesk_timesheet_time_control
19 changes: 19 additions & 0 deletions helpdesk_mgmt_timesheet/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 DEC (https://www.decgroupe.com)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.addons.helpdesk_mgmt.tests import test_helpdesk_portal


class TestHelpdeskPortal(test_helpdesk_portal.TestHelpdeskPortalBase):
""" """

def setUp(self):
super().setUp()
self.env.company.helpdesk_mgmt_portal_select_team = True

def test_submit_ticket_team(self):
team_id = self.env.ref("helpdesk_mgmt.helpdesk_team_2")
self.authenticate("portal", "portal")
self._submit_ticket(team=team_id.id)
tickets = self.get_new_tickets(self.user_portal)
self.assertIn(self.portal_ticket, tickets)
self.assertIn(team_id, tickets.mapped("team_id"))

0 comments on commit c683d2e

Please sign in to comment.