diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index fd8dad0543..58f912d748 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -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() diff --git a/helpdesk_mgmt/tests/test_helpdesk_portal.py b/helpdesk_mgmt/tests/test_helpdesk_portal.py index 0286dfe1e0..d5aac7f04c 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_portal.py +++ b/helpdesk_mgmt/tests/test_helpdesk_portal.py @@ -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. @@ -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() @@ -190,15 +203,3 @@ def _call_close_ticket(self, ticket, stage): self.assertTrue(resp.is_redirect) # http://127.0.0.1:8069/my/ticket/ 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, - } - ) diff --git a/helpdesk_mgmt_project/__init__.py b/helpdesk_mgmt_project/__init__.py index f7209b1710..0650744f6b 100644 --- a/helpdesk_mgmt_project/__init__.py +++ b/helpdesk_mgmt_project/__init__.py @@ -1,2 +1 @@ from . import models -from . import controllers diff --git a/helpdesk_mgmt_timesheet/__init__.py b/helpdesk_mgmt_timesheet/__init__.py index 00188672cc..53d7ef73ac 100644 --- a/helpdesk_mgmt_timesheet/__init__.py +++ b/helpdesk_mgmt_timesheet/__init__.py @@ -2,3 +2,4 @@ # For copyright and license notices, see __manifest__.py file in root directory ############################################################################### from . import models +from . import controllers diff --git a/helpdesk_mgmt_project/controllers/__init__.py b/helpdesk_mgmt_timesheet/controllers/__init__.py similarity index 100% rename from helpdesk_mgmt_project/controllers/__init__.py rename to helpdesk_mgmt_timesheet/controllers/__init__.py diff --git a/helpdesk_mgmt_project/controllers/main.py b/helpdesk_mgmt_timesheet/controllers/main.py similarity index 100% rename from helpdesk_mgmt_project/controllers/main.py rename to helpdesk_mgmt_timesheet/controllers/main.py diff --git a/helpdesk_mgmt_timesheet/tests/__init__.py b/helpdesk_mgmt_timesheet/tests/__init__.py index 5f539c1884..cd8409ca6d 100644 --- a/helpdesk_mgmt_timesheet/tests/__init__.py +++ b/helpdesk_mgmt_timesheet/tests/__init__.py @@ -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 diff --git a/helpdesk_mgmt_timesheet/tests/test_helpdesk_portal.py b/helpdesk_mgmt_timesheet/tests/test_helpdesk_portal.py new file mode 100644 index 0000000000..fc1e41c9f4 --- /dev/null +++ b/helpdesk_mgmt_timesheet/tests/test_helpdesk_portal.py @@ -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"))