Skip to content

Commit

Permalink
[14.0][FIX] pms_helpdesk_mgmt: web control bar allows filtering and g…
Browse files Browse the repository at this point in the history
…rouping of tickets
  • Loading branch information
IrluiDev committed Sep 27, 2024
1 parent 59a0789 commit 4501410
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 77 deletions.
3 changes: 2 additions & 1 deletion pms_helpdesk_mgmt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"data": [
"views/helpdesk_ticket_views.xml",
"views/helpdesk_ticket_templates.xml",
"securitty/helpdesk_security_pms.xml",
"security/helpdesk_security_pms.xml",
"security/ir.model.access.csv",
],
"demo": ["demo/helpdesk_demo.xml"],
"assets": {
Expand Down
22 changes: 12 additions & 10 deletions pms_helpdesk_mgmt/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import odoo.http as http
from odoo.http import request
from odoo.exceptions import UserError, AccessError

from odoo.addons.helpdesk_mgmt.controllers.main import HelpdeskTicketController

_logger = logging.getLogger(__name__)
Expand All @@ -18,13 +18,18 @@ def get_companies(self):
user = request.env.user
allowed_pms_property_ids = user.get_active_property_ids()

Check warning on line 19 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L18-L19

Added lines #L18 - L19 were not covered by tests
if allowed_pms_property_ids:
properties = request.env['pms.property'].sudo().browse(allowed_pms_property_ids)
companies = properties.mapped('company_id')
properties = (

Check warning on line 21 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L21

Added line #L21 was not covered by tests
request.env["pms.property"].sudo().browse(allowed_pms_property_ids)
)
companies = properties.mapped("company_id")

Check warning on line 24 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L24

Added line #L24 was not covered by tests
else:
companies = request.env['res.company'].sudo().search([]) # Si no hay propiedades activas, lista todas las compañías
companies = request.env["res.company"].sudo().search([])

Check warning on line 26 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L26

Added line #L26 was not covered by tests

companies_data = [{"id": company.id, "name": company.name} for company in companies]
companies_data = [
{"id": company.id, "name": company.name} for company in companies
]
return {"companies": companies_data}

Check warning on line 31 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L31

Added line #L31 was not covered by tests

@http.route("/get_properties", type="json", auth="user")
def get_properties(self, company_id):
properties = (

Check warning on line 35 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L35

Added line #L35 was not covered by tests
Expand Down Expand Up @@ -52,13 +57,12 @@ def create_new_ticket(self, **kw):
user_belongs_to_group = user.has_group(

Check warning on line 57 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L55-L57

Added lines #L55 - L57 were not covered by tests
"helpdesk_mgmt.group_helpdesk_user_team"
) or user.has_group("helpdesk_mgmt.group_helpdesk_manager")
assigned_companies = user.company_ids
company = request.env.company
tag_model = http.request.env["helpdesk.ticket.tag"]
tags = tag_model.with_company(company.id).search([("active", "=", True)])
allowed_pms_property_ids = user.get_active_property_ids()
properties = request.env['pms.property'].sudo().browse(allowed_pms_property_ids)
companies = properties.mapped('company_id')
properties = request.env["pms.property"].sudo().browse(allowed_pms_property_ids)
companies = properties.mapped("company_id")

Check warning on line 65 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L60-L65

Added lines #L60 - L65 were not covered by tests
all_room_ids = [
room_id for property in properties for room_id in property.room_ids.ids
]
Expand Down Expand Up @@ -93,5 +97,3 @@ def _prepare_submit_ticket_vals(self, **kw):
}
)
return vals

Check warning on line 99 in pms_helpdesk_mgmt/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/main.py#L99

Added line #L99 was not covered by tests


140 changes: 98 additions & 42 deletions pms_helpdesk_mgmt/controllers/myaccount.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
from collections import OrderedDict
from operator import itemgetter

from odoo import http
from odoo import _, http
from odoo.http import request
from odoo.osv.expression import AND
from odoo.tools import groupby as groupbyelem

from odoo.addons.helpdesk_mgmt.controllers.myaccount import CustomerPortalHelpdesk
from odoo.addons.portal.controllers.portal import pager as portal_pager


class CustomCustomerPortalHelpdesk(CustomerPortalHelpdesk):
def _prepare_home_portal_values(self, counters):
active_property_ids = request.env.user.get_active_property_ids()
values = super(CustomCustomerPortalHelpdesk, self)._prepare_home_portal_values(

Check warning on line 15 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L14-L15

Added lines #L14 - L15 were not covered by tests
counters
)

helpdesk_model = request.env["helpdesk.ticket"].sudo()

Check warning on line 18 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L18

Added line #L18 was not covered by tests
if "ticket_count" in counters:
helpdesk_model = request.env["helpdesk.ticket"].sudo()
active_property_ids = request.env.user.get_active_property_ids()
domain = []
if active_property_ids:
domain.append(("pms_property_id", "in", active_property_ids))

ticket_count = (
helpdesk_model.search_count(domain)
values["ticket_count"] = (

Check warning on line 20 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L20

Added line #L20 was not covered by tests
helpdesk_model.search_count(
[
("pms_property_id", "in", active_property_ids),
]
)
if helpdesk_model.check_access_rights("read", raise_exception=False)
else 0
)
values["ticket_count"] = ticket_count

return values

Check warning on line 29 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L29

Added line #L29 was not covered by tests

@http.route(
Expand All @@ -36,54 +34,112 @@ def _prepare_home_portal_values(self, counters):
auth="user",
website=True,
)
def portal_my_tickets(self, page=1, **kw):
def portal_my_tickets(
self,
page=1,
date_begin=None,
date_end=None,
sortby=None,
filterby=None,
search=None,
search_in=None,
groupby=None,
**kw
):
response = super(CustomCustomerPortalHelpdesk, self).portal_my_tickets(

Check warning on line 49 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L49

Added line #L49 was not covered by tests
page=page, **kw
page=page,
date_begin=date_begin,
date_end=date_end,
sortby=sortby,
filterby=filterby,
search=search,
search_in=search_in,
groupby=groupby,
**kw
)
domain = response.qcontext.get("domain", [])
response.qcontext.get("sortby")
response.qcontext.get("groupby")
order = response.qcontext.get("order")

active_property_ids = request.env.user.get_active_property_ids()
if active_property_ids:
domain.append(("pms_property_id", "in", active_property_ids))
values = response.qcontext

Check warning on line 60 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L60

Added line #L60 was not covered by tests

HelpdeskTicket = request.env["helpdesk.ticket"].sudo()

Check warning on line 62 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L62

Added line #L62 was not covered by tests
ticket_count = HelpdeskTicket.search_count(domain)

pager = portal_pager(
url="/my/tickets",
url_args={},
total=ticket_count,
page=page,
step=self._items_per_page,
)
active_property_ids = request.env.user.get_active_property_ids()
property_ids_active_domain = [("pms_property_id", "in", active_property_ids)]

Check warning on line 65 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L64-L65

Added lines #L64 - L65 were not covered by tests

tickets = HelpdeskTicket.search(
domain, order=order, limit=self._items_per_page, offset=pager["offset"]
searchbar_sortings = dict(
sorted(
self._ticket_get_searchbar_sortings().items(),
key=lambda item: item[1]["sequence"],
)
)

searchbar_filters = {

Check warning on line 74 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L74

Added line #L74 was not covered by tests
"all": {"label": _("All"), "domain": []},
}
for stage in request.env["helpdesk.ticket.stage"].search([]):
searchbar_filters[str(stage.id)] = {

Check warning on line 78 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L78

Added line #L78 was not covered by tests
"label": stage.name,
"domain": [("stage_id", "=", stage.id)],
}

searchbar_groupby = self._ticket_get_searchbar_groupby()

Check warning on line 83 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L83

Added line #L83 was not covered by tests

if not sortby:
sortby = "date"
order = searchbar_sortings[sortby]["order"]

Check warning on line 87 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L86-L87

Added lines #L86 - L87 were not covered by tests

if not filterby:
filterby = "all"
domain = searchbar_filters.get(filterby, searchbar_filters.get("all"))["domain"]

Check warning on line 91 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L90-L91

Added lines #L90 - L91 were not covered by tests

if not groupby:
groupby = "none"

Check warning on line 94 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L94

Added line #L94 was not covered by tests

if date_begin and date_end:
domain += [

Check warning on line 97 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L97

Added line #L97 was not covered by tests
("create_date", ">", date_begin),
("create_date", "<=", date_end),
]

if search:
domain += self._ticket_get_search_domain(search_in, search)

Check warning on line 103 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L103

Added line #L103 was not covered by tests

domain = AND([domain, property_ids_active_domain])
tickets = HelpdeskTicket.search(domain, order=order)

Check warning on line 106 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L105-L106

Added lines #L105 - L106 were not covered by tests

request.session["my_tickets_history"] = tickets.ids[:100]

Check warning on line 108 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L108

Added line #L108 was not covered by tests

group = response.qcontext.get("group", None)
groupby_mapping = self._ticket_get_groupby_mapping()
group = groupby_mapping.get(groupby)

Check warning on line 111 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L110-L111

Added lines #L110 - L111 were not covered by tests

if group:
grouped_tickets = [
HelpdeskTicket.concat(*g)
request.env["helpdesk.ticket"].concat(*g)
for k, g in groupbyelem(tickets, itemgetter(group))
]
elif tickets:
grouped_tickets = [tickets]

Check warning on line 119 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L119

Added line #L119 was not covered by tests
else:
grouped_tickets = [tickets] if tickets else []
grouped_tickets = []

Check warning on line 121 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L121

Added line #L121 was not covered by tests

response.qcontext.update(
values.update(

Check warning on line 123 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L123

Added line #L123 was not covered by tests
{
"date": date_begin,
"date_end": date_end,
"grouped_tickets": grouped_tickets,
"pager": pager,
"ticket_count": ticket_count,
"page_name": "ticket",
"default_url": "/my/tickets",
"searchbar_sortings": searchbar_sortings,
"searchbar_groupby": searchbar_groupby,
"searchbar_inputs": self._ticket_get_searchbar_inputs(),
"search_in": search_in,
"search": search,
"sortby": sortby,
"groupby": groupby,
"filterby": filterby,
"searchbar_filters": OrderedDict(sorted(searchbar_filters.items())),
}
)
return request.render(
"pms_helpdesk_mgmt.portal_my_tickets_inherited", response.qcontext
)

return request.render("pms_helpdesk_mgmt.portal_my_tickets", values)

Check warning on line 142 in pms_helpdesk_mgmt/controllers/myaccount.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L142

Added line #L142 was not covered by tests

@http.route(
["/my/ticket/<int:ticket_id>"], type="http", auth="public", website=True
Expand Down
7 changes: 1 addition & 6 deletions pms_helpdesk_mgmt/demo/helpdesk_demo.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" ?>
<odoo noupdate="1">
<!-- User Demo -->
<!-- <record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4,ref('group_helpdesk_user'))]" />
</record> -->
<!-- Categories -->
<odoo noupdate="0">
<record id="helpdesk_mgmt.helpdesk_category_1" model="helpdesk.ticket.category">
<field eval="&quot;IT Software&quot;" name="name" />
<field eval="&quot;1&quot;" name="active" />
Expand Down
23 changes: 13 additions & 10 deletions pms_helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
# Copyright (C) 2024 Oso Tranquilo <informatica@gmail.com>
# Copyright (C) 2024 Consultores Hoteleros Integrales <www.aldahotels.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import api, fields, models


class PmsHelpdeskTicket(models.Model):

_inherit = "helpdesk.ticket"

pms_property_id = fields.Many2one(
'pms.property',
string="PMS Property",
string="Property",
help="The property linked to this ticket.",
comodel_name="pms.property",
required=True,
)
room_id = fields.Many2one(
Expand All @@ -29,14 +28,17 @@ def _get_default_pms_property(self):
user = self.env.user
active_property_ids = user.get_active_property_ids()

Check warning on line 29 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L28-L29

Added lines #L28 - L29 were not covered by tests
if active_property_ids:
return active_property_ids[0]
return active_property_ids[0]
return None

Check warning on line 32 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L31-L32

Added lines #L31 - L32 were not covered by tests

@api.onchange("company_id")
def _onchange_company_id(self):
if self.company_id:
allowed_pms_property_ids = self.env.user.get_active_property_ids()

Check warning on line 37 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L37

Added line #L37 was not covered by tests
if self.pms_property_id and self.pms_property_id.company_id != self.company_id:
if (
self.pms_property_id
and self.pms_property_id.company_id != self.company_id
):
self.pms_property_id = False

Check warning on line 42 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L42

Added line #L42 was not covered by tests

return {

Check warning on line 44 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L44

Added line #L44 was not covered by tests
Expand All @@ -48,7 +50,9 @@ def _onchange_company_id(self):
}
}
else:
self.pms_property_id = False # Reinicia la propiedad si no hay compañía seleccionada
self.pms_property_id = (

Check warning on line 53 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L53

Added line #L53 was not covered by tests
False # Reinicia la propiedad si no hay compañía seleccionada
)
return {"domain": {"pms_property_id": []}}

Check warning on line 56 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L56

Added line #L56 was not covered by tests

@api.onchange("pms_property_id")
Expand All @@ -64,8 +68,7 @@ def _onchange_property_id(self):
else:
return {"domain": {"room_id": []}}

Check warning on line 69 in pms_helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/models/helpdesk_ticket.py#L69

Added line #L69 was not covered by tests


def write(self, vals):
if 'partner_id' not in vals or not vals.get('partner_id'):
vals['partner_id'] = self.env.uid
if "partner_id" not in vals or not vals.get("partner_id"):
vals["partner_id"] = self.env.uid
return super(PmsHelpdeskTicket, self).write(vals)
3 changes: 3 additions & 0 deletions pms_helpdesk_mgmt/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
user_access_pms_ticket,user_access_pms_ticket,model_helpdesk_ticket,pms.group_pms_user,1,1,1,0
manager_access_pms_ticket,manager_access_pms_ticket,model_helpdesk_ticket,pms.group_pms_manager,1,1,1,1
9 changes: 4 additions & 5 deletions pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
</xpath>
</template>

<template
id="portal_my_tickets_inherited"
inherit_id="helpdesk_mgmt.portal_my_tickets"
>
<template id="portal_my_tickets" inherit_id="helpdesk_mgmt.portal_my_tickets">
<xpath expr="//t[@t-if='not grouped_tickets']" position="attributes">
<t t-if="not grouped_tickets">
<div class="alert alert-warning mt8" role="alert">
Expand All @@ -43,12 +40,14 @@
name="Tickets List"
>
<xpath expr="//tr/th[position()=3]" position="after">
<th t-if="groupby =='category'">Title</th>
<th t-if="groupby =='stage'">Title</th>
<th>Property</th>
<th>Room</th>
</xpath>
<xpath expr="//tr/td[position()=3]" position="after">
<td>
<span t-field="ticket.pms_property_id.name" />
<span t-esc="ticket.pms_property_id.name" />
</td>
<td>
<span t-field="ticket.room_id.name" />
Expand Down
3 changes: 0 additions & 3 deletions pms_helpdesk_mgmt/views/helpdesk_ticket_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk_mgmt.ticket_view_form" />
<field name="arch" type="xml">
<!-- <xpath expr="//field[@name='company_id']" position="attributes">
<attribute name="domain">[('active', '=', True)]</attribute>
</xpath> -->
<xpath expr="//field[@name='company_id']" position="after">
<field name="pms_property_id" options="{'no_create': True}" />
<field
Expand Down

0 comments on commit 4501410

Please sign in to comment.