Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] helpdesk_mgmt_timesheet: Ticket submit broken #504

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 26 additions & 11 deletions helpdesk_mgmt/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2023 Tecnativa - Víctor Martínez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# import odoo.tests
import odoo.tests
from odoo import http
from odoo.tests.common import new_test_user

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 +40,32 @@ 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": "test-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.WebRequest.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)


@odoo.tests.tagged("post_install", "-at_install")
class TestHelpdeskPortal(TestHelpdeskPortalBase):
def test_submit_ticket_01(self):
self.authenticate("test-basic-user", "test-basic-user")
self._submit_ticket()
Expand Down
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
1 change: 1 addition & 0 deletions helpdesk_mgmt_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"views/helpdesk_team_view.xml",
"views/helpdesk_ticket_view.xml",
"views/hr_timesheet_view.xml",
"views/helpdesk_project_task_view.xml",
"report/report_timesheet_templates.xml",
],
"demo": ["demo/helpdesk_mgmt_timesheet_demo.xml"],
Expand Down
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
22 changes: 22 additions & 0 deletions helpdesk_mgmt_timesheet/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 DEC (https://www.decgroupe.com)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import odoo.tests

from odoo.addons.helpdesk_mgmt.tests import test_helpdesk_portal


@odoo.tests.tagged("post_install", "-at_install")
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("test-portal", "test-portal")
self._submit_ticket(team=team_id.id)
tickets = self.get_new_tickets(self.portal_user)
self.assertIn(self.portal_ticket, tickets)
self.assertIn(team_id, tickets.mapped("team_id"))
17 changes: 17 additions & 0 deletions helpdesk_mgmt_timesheet/views/helpdesk_project_task_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<data>
<record id="view_task_form2_inherited" model="ir.ui.view">
<field name="name">project.task.form.ticket.inherited</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="hr_timesheet.view_task_form2_inherited" />
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='name']" position="after">
<field
name="ticket_id"
optional="hide"
groups="helpdesk_mgmt.group_helpdesk_user"
/>
</xpath>
</field>
</record>
</data>
8 changes: 6 additions & 2 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@
<field name="task_id" invisible="1" />
<field name="date" widget="date" invisible="1" />
<field name="date_time" string="Date" required="1" />
<field name="user_id" required="1" />
<field
name="user_id"
required="1"
widget="many2one_avatar_user"
/>
<field name="name" />
<field
name="unit_amount"
Expand Down Expand Up @@ -191,7 +195,7 @@
</div>
<group>
<field name="date" />
<field name="user_id" />
<field name="user_id" widget="many2one_avatar_user" />
<field name="name" />
<field
name="unit_amount"
Expand Down
Loading