diff --git a/pms_helpdesk_mgmt/__manifest__.py b/pms_helpdesk_mgmt/__manifest__.py index 9cb2b329a4..6f3b05793b 100644 --- a/pms_helpdesk_mgmt/__manifest__.py +++ b/pms_helpdesk_mgmt/__manifest__.py @@ -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": { diff --git a/pms_helpdesk_mgmt/controllers/main.py b/pms_helpdesk_mgmt/controllers/main.py index b6c8050784..8a3567150a 100644 --- a/pms_helpdesk_mgmt/controllers/main.py +++ b/pms_helpdesk_mgmt/controllers/main.py @@ -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__) @@ -18,13 +18,18 @@ def get_companies(self): user = request.env.user allowed_pms_property_ids = user.get_active_property_ids() if allowed_pms_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") 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([]) - 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} + @http.route("/get_properties", type="json", auth="user") def get_properties(self, company_id): properties = ( @@ -52,13 +57,12 @@ def create_new_ticket(self, **kw): user_belongs_to_group = user.has_group( "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") all_room_ids = [ room_id for property in properties for room_id in property.room_ids.ids ] @@ -93,5 +97,3 @@ def _prepare_submit_ticket_vals(self, **kw): } ) return vals - - diff --git a/pms_helpdesk_mgmt/controllers/myaccount.py b/pms_helpdesk_mgmt/controllers/myaccount.py index 67dc4c6e8c..2397503fe1 100644 --- a/pms_helpdesk_mgmt/controllers/myaccount.py +++ b/pms_helpdesk_mgmt/controllers/myaccount.py @@ -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( counters ) - + helpdesk_model = request.env["helpdesk.ticket"].sudo() 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"] = ( + 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 @http.route( @@ -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( - 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 HelpdeskTicket = request.env["helpdesk.ticket"].sudo() - 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)] - 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 = { + "all": {"label": _("All"), "domain": []}, + } + for stage in request.env["helpdesk.ticket.stage"].search([]): + searchbar_filters[str(stage.id)] = { + "label": stage.name, + "domain": [("stage_id", "=", stage.id)], + } + + searchbar_groupby = self._ticket_get_searchbar_groupby() + + if not sortby: + sortby = "date" + order = searchbar_sortings[sortby]["order"] + + if not filterby: + filterby = "all" + domain = searchbar_filters.get(filterby, searchbar_filters.get("all"))["domain"] + + if not groupby: + groupby = "none" + + if date_begin and date_end: + domain += [ + ("create_date", ">", date_begin), + ("create_date", "<=", date_end), + ] + + if search: + domain += self._ticket_get_search_domain(search_in, search) + + domain = AND([domain, property_ids_active_domain]) + tickets = HelpdeskTicket.search(domain, order=order) + request.session["my_tickets_history"] = tickets.ids[:100] - group = response.qcontext.get("group", None) + groupby_mapping = self._ticket_get_groupby_mapping() + group = groupby_mapping.get(groupby) + 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] else: - grouped_tickets = [tickets] if tickets else [] + grouped_tickets = [] - response.qcontext.update( + values.update( { + "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) @http.route( ["/my/ticket/"], type="http", auth="public", website=True diff --git a/pms_helpdesk_mgmt/demo/helpdesk_demo.xml b/pms_helpdesk_mgmt/demo/helpdesk_demo.xml index 931e0cc145..22752dad83 100644 --- a/pms_helpdesk_mgmt/demo/helpdesk_demo.xml +++ b/pms_helpdesk_mgmt/demo/helpdesk_demo.xml @@ -1,10 +1,5 @@ - - - - + diff --git a/pms_helpdesk_mgmt/models/helpdesk_ticket.py b/pms_helpdesk_mgmt/models/helpdesk_ticket.py index be1138241d..ffe956da95 100644 --- a/pms_helpdesk_mgmt/models/helpdesk_ticket.py +++ b/pms_helpdesk_mgmt/models/helpdesk_ticket.py @@ -2,8 +2,7 @@ # Copyright (C) 2024 Oso Tranquilo # Copyright (C) 2024 Consultores Hoteleros Integrales # 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): @@ -11,9 +10,9 @@ 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( @@ -29,14 +28,17 @@ def _get_default_pms_property(self): user = self.env.user active_property_ids = user.get_active_property_ids() if active_property_ids: - return active_property_ids[0] + return active_property_ids[0] return None @api.onchange("company_id") def _onchange_company_id(self): if self.company_id: allowed_pms_property_ids = self.env.user.get_active_property_ids() - 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 return { @@ -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 = ( + False # Reinicia la propiedad si no hay compañía seleccionada + ) return {"domain": {"pms_property_id": []}} @api.onchange("pms_property_id") @@ -64,8 +68,7 @@ def _onchange_property_id(self): else: return {"domain": {"room_id": []}} - 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) diff --git a/pms_helpdesk_mgmt/securitty/helpdesk_security_pms.xml b/pms_helpdesk_mgmt/security/helpdesk_security_pms.xml similarity index 100% rename from pms_helpdesk_mgmt/securitty/helpdesk_security_pms.xml rename to pms_helpdesk_mgmt/security/helpdesk_security_pms.xml diff --git a/pms_helpdesk_mgmt/security/ir.model.access.csv b/pms_helpdesk_mgmt/security/ir.model.access.csv new file mode 100644 index 0000000000..bf178c39e9 --- /dev/null +++ b/pms_helpdesk_mgmt/security/ir.model.access.csv @@ -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 diff --git a/pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml b/pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml index 0e1e629611..0b97c6050a 100644 --- a/pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml +++ b/pms_helpdesk_mgmt/views/helpdesk_ticket_templates.xml @@ -24,10 +24,7 @@ -