Skip to content

Commit

Permalink
[14.0][FIX] pms_helpdesk_mgmt: to list active properties
Browse files Browse the repository at this point in the history
  • Loading branch information
IrluiDev committed Sep 25, 2024
1 parent 2184f6d commit 0d76173
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 83 deletions.
149 changes: 92 additions & 57 deletions pms_helpdesk_mgmt/controllers/myaccount.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,124 @@
from odoo.http import request
from odoo.addons.helpdesk_mgmt.controllers.myaccount import CustomerPortalHelpdesk
from odoo.osv.expression import AND, OR
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
from collections import OrderedDict
from operator import itemgetter
from odoo import _, http
from odoo.exceptions import AccessError, MissingError

from odoo import http
from odoo.http import request
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):
values = super(CustomCustomerPortalHelpdesk, self)._prepare_home_portal_values(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L13

Added line #L13 was not covered by tests
counters
)

if "ticket_count" in counters:
helpdesk_model = request.env["helpdesk.ticket"].sudo()
active_property_ids = request.env.user.get_active_property_ids()
domain = []

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#L18-L20

Added lines #L18 - L20 were not covered by tests
if active_property_ids:
domain.append(("pms_property_id", "in", active_property_ids))

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L22

Added line #L22 was not covered by tests

ticket_count = (

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L24

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

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

return values

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L31

Added line #L31 was not covered by tests

@http.route(
["/my/tickets", "/my/tickets/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_tickets(self, **kw):
response = super(CustomCustomerPortalHelpdesk, self).portal_my_tickets(**kw)
page = response.qcontext.get('page', 1)
HelpdeskTicket = request.env["helpdesk.ticket"].sudo()

# Llamamos al método del padre para obtener los valores de la vista
values = super(CustomCustomerPortalHelpdesk, self)._prepare_portal_layout_values()
if not HelpdeskTicket.check_access_rights("read", raise_exception=False):
return request.redirect("/my")
def portal_my_tickets(self, page=1, **kw):
response = super(CustomCustomerPortalHelpdesk, self).portal_my_tickets(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L40

Added line #L40 was not covered by tests
page=page, **kw
)
domain = response.qcontext.get("domain", [])
response.qcontext.get("sortby")
response.qcontext.get("groupby")
order = response.qcontext.get("order")

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L43-L46

Added lines #L43 - L46 were not covered by tests

domain = response.qcontext.get('domain', [])
order = response.qcontext.get('order', '')
sortby = response.qcontext.get('sortby', {})
groupby = response.qcontext.get('groupby', '')

active_property_ids = request.env.user.get_active_property_ids()
active_property_ids = request.env.user.get_active_property_ids()

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L48

Added line #L48 was not covered by tests
if active_property_ids:
domain.append(("pms_property_id", "in", active_property_ids))

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L50

Added line #L50 was not covered by tests
HelpdeskTicket = request.env["helpdesk.ticket"].sudo()

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

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L52-L53

Added lines #L52 - L53 were not covered by tests

pager = portal_pager(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L55

Added line #L55 was not covered by tests
url="/my/tickets",
url_args={
"date_begin": response.qcontext.get('date_begin', {}),
"date_end": response.qcontext.get('date_end', {}),
"sortby": sortby,
"filterby": response.qcontext.get('filterby', ''),
"groupby": groupby,
"search": response.qcontext.get('search', ''),
"search_in": response.qcontext.get('search_in', ''),
},
url_args={},
total=ticket_count,
page=page,
step=self._items_per_page,
)

tickets = HelpdeskTicket.search(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L63

Added line #L63 was not covered by tests
domain,
order=order,
limit=self._items_per_page,
offset=pager["offset"],
domain, order=order, limit=self._items_per_page, offset=pager["offset"]
)
request.session["my_tickets_history"] = tickets.ids[:100]

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L66

Added line #L66 was not covered by tests

group = response.qcontext.get('group', None)
grouped_tickets = [tickets] if not group else [
request.env["helpdesk.ticket"].concat(*g)
for k, g in groupbyelem(tickets, itemgetter(group))
]
values.update(
group = response.qcontext.get("group", None)

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L68

Added line #L68 was not covered by tests
if group:
grouped_tickets = [
HelpdeskTicket.concat(*g)
for k, g in groupbyelem(tickets, itemgetter(group))
]
else:
grouped_tickets = [tickets] if tickets else []

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L75

Added line #L75 was not covered by tests

response.qcontext.update(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L77

Added line #L77 was not covered by tests
{
"date": response.qcontext.get('date_begin', {}),
"date_end": response.qcontext.get('date_end', {}),
"grouped_tickets": grouped_tickets,
"page_name": "ticket",
"default_url": "/my/tickets",
"pager": pager,
"searchbar_sortings": response.qcontext.get('searchbar_sortings', []),
"searchbar_groupby": response.qcontext.get('searchbar_groupby', []),
"searchbar_inputs": response.qcontext.get('searchbar_inputs', []),
"search_in": response.qcontext.get('search_in', ''),
"search": response.qcontext.get('search', ''),
"sortby": sortby,
"groupby": groupby,
"searchbar_filters": OrderedDict(sorted(response.qcontext.get('searchbar_filters', {}).items())),
"filterby": response.qcontext.get('filterby', ''),
"ticket_count": ticket_count,
}
)
return request.render("helpdesk_mgmt.portal_my_tickets", values)
return request.render(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L84

Added line #L84 was not covered by tests
"pms_helpdesk_mgmt.portal_my_tickets_inherited", response.qcontext
)

@http.route(
["/my/ticket/<int:ticket_id>"], type="http", auth="public", website=True
)
def portal_my_ticket(self, ticket_id, access_token=None, **kw):
HelpdeskTicket = request.env["helpdesk.ticket"].sudo()

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L92

Added line #L92 was not covered by tests

if access_token:
ticket_sudo = HelpdeskTicket.search(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L95

Added line #L95 was not covered by tests
[("id", "=", ticket_id), ("access_token", "=", access_token)]
)
else:
ticket_sudo = HelpdeskTicket.search([("id", "=", ticket_id)])

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L99

Added line #L99 was not covered by tests

if not ticket_sudo:
return request.redirect("/my")

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L102

Added line #L102 was not covered by tests

for attachment in ticket_sudo.attachment_ids:
attachment.generate_access_token()

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L105

Added line #L105 was not covered by tests

values = self._ticket_get_page_view_values(ticket_sudo, access_token, **kw)
return request.render("pms_helpdesk_mgmt.portal_helpdesk_ticket_page", values)

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#L107-L108

Added lines #L107 - L108 were not covered by tests

def _ticket_get_page_view_values(self, ticket, access_token, **kwargs):
closed_stages = (

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#L111

Added line #L111 was not covered by tests
request.env["helpdesk.ticket.stage"].sudo().search([("closed", "=", True)])
)

values = {

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L115

Added line #L115 was not covered by tests
"closed_stages": closed_stages,
"page_name": "ticket",
"ticket": ticket,
"user": request.env.user,
}

return self._get_page_view_values(

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

View check run for this annotation

Codecov / codecov/patch

pms_helpdesk_mgmt/controllers/myaccount.py#L122

Added line #L122 was not covered by tests
ticket, access_token, values, "my_tickets_history", False, **kwargs
)
75 changes: 49 additions & 26 deletions pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,37 @@
/>
</xpath>
</template>


<template
id="portal_my_home_inherited_form"
name="Portal My Home : Replace New Ticket Form"
inherit_id="helpdesk_mgmt.portal_my_home"
priority="40"
>
<xpath expr="//t[@t-call='portal.portal_docs_entry']" position="attributes">
<t t-call="portal.portal_docs_entry">
<t t-set="title">Tickets</t>
<t t-set="url" t-value="'/my/tickets'" />
<t t-set="placeholder_count" t-value="ticket_count" />
</t>
</xpath>
</template>

<template
id="portal_my_tickets"
id="portal_my_tickets_inherited"
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">
<p>No tickets found for your properties.</p>
</div>
</t>
</xpath>
</template>

<template
id="portal_ticket_list"
inherit_id="helpdesk_mgmt.portal_ticket_list"
name="Tickets List"
>
Expand All @@ -20,32 +48,28 @@
</xpath>
<xpath expr="//tr/td[position()=3]" position="after">
<td>
<span t-field="ticket.sudo().pms_property_id.name" />
<span t-field="ticket.pms_property_id.name" />
</td>
<td>
<span t-field="ticket.sudo().room_id.name" />
<span t-field="ticket.room_id.name" />
</td>
</xpath>
<xpath expr="//a[contains(@t-attf-href, '/my/ticket')]" position="replace">
<a t-attf-href="/my/ticket/#{ticket.id}?{{ keep_query() }}">
<span t-field="ticket.name" />
</a>
</xpath>
</template>

<template
id="portal_helpdesk_ticket_page"
inherit_id="helpdesk_mgmt.portal_helpdesk_ticket_page"
name="Ticket Portal Template"
>
<xpath expr="//span[@t-field='ticket.create_date']" position="after">
<div><strong>Property:</strong>
<span t-field="ticket.pms_property_id.name" /></div>
<span t-field="ticket.sudo().pms_property_id.name" /></div>
<div><strong>Room:</strong>
<span t-field="ticket.room_id.name" /></div>
<span t-field="ticket.sudo().room_id.name" /></div>
</xpath>
<xpath expr="//span[@t-field='ticket.category_id']" position="after">
<div><strong>Tag:</strong>
<span t-field="ticket.tag_ids" /></div>
<span t-field="ticket.sudo().tag_ids" /></div>
</xpath>
</template>

Expand All @@ -60,20 +84,19 @@
>
<div class="col-md-7 col-sm-8">
<label for="company_id">Company:</label>
<select
class="form-control"
id="company_id"
name="company_id"
required="required"
t-attf-domain="[('id', 'in', companies_active)]"
>
<option value="" disabled="disabled">Select a company</option>
<t t-foreach="companies" t-as="company">
<option t-att-value="company.id">
<t t-esc="company.name" />
</option>
</t>
</select>
<select
class="form-control"
id="company_id"
name="company_id"
required="required"
>
<option value="" disabled="disabled">Select a company</option>
<t t-foreach="companies" t-as="company">
<option t-att-value="company.id">
<t t-esc="company.name" />
</option>
</t>
</select>
</div>
<div class="col-md-7 col-sm-8">
<label for="pms_property_id">Property</label>
Expand Down

0 comments on commit 0d76173

Please sign in to comment.