Skip to content

Commit

Permalink
[14.0][FIX] helpdesk_mgmt_project: improve performance counting tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorant committed Jun 30, 2023
1 parent cc15c8f commit f07075f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions helpdesk_mgmt_project/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Contributors

* Manuel Regidor

* `ALBA Software <https://www.albasoft.com>`_:

* Rafa Morant

Maintainers
~~~~~~~~~~~

Expand Down
19 changes: 15 additions & 4 deletions helpdesk_mgmt_project/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ class ProjectProject(models.Model):

@api.depends("ticket_ids", "ticket_ids.stage_id")
def _compute_ticket_count(self):
HelpdeskTicket = self.env["helpdesk.ticket"]
domain = [("project_id", "in", self.ids)]
fields = ["project_id"]
groupby = ["project_id"]
counts = {
pr["project_id"][0]: pr["project_id_count"]
for pr in HelpdeskTicket.read_group(domain, fields, groupby)
}
domain.append(("closed", "=", False))
counts_todo = {
pr["project_id"][0]: pr["project_id_count"]
for pr in HelpdeskTicket.read_group(domain, fields, groupby)
}
for record in self:
record.ticket_count = len(record.ticket_ids)
record.todo_ticket_count = len(
record.ticket_ids.filtered(lambda ticket: not ticket.closed)
)
record.ticket_count = counts.get(record.id, 0)
record.todo_ticket_count = counts_todo.get(record.id, 0)
24 changes: 18 additions & 6 deletions helpdesk_mgmt_project/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@ class ProjectTask(models.Model):

@api.depends("ticket_ids", "ticket_ids.stage_id")
def _compute_ticket_count(self):
HelpdeskTicket = self.env["helpdesk.ticket"]
invname = "task_id"
domain = [(invname, "in", self.ids)]
fields = [invname]
groupby = [invname]
counts = {
pr[invname][0]: pr[f"{invname}_count"]
for pr in HelpdeskTicket.read_group(domain, fields, groupby)
}
domain.append(("closed", "=", False))
counts_todo = {
pr[invname][0]: pr[f"{invname}_count"]
for pr in HelpdeskTicket.read_group(domain, fields, groupby)
}
for record in self:
record.ticket_count = len(record.ticket_ids)
record.todo_ticket_count = len(
record.ticket_ids.filtered(lambda ticket: not ticket.closed)
)
record.ticket_count = counts.get(record.id, 0)
record.todo_ticket_count = counts_todo.get(record.id, 0)

def action_view_ticket(self):
result = self.env["ir.actions.act_window"]._for_xml_id(
"helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard"
)
# choose the view_mode accordingly
if not self.ticket_ids or len(self.ticket_ids) > 1:
if not self.ticket_ids or self.ticket_count > 1:
result["domain"] = "[('id','in',%s)]" % (self.ticket_ids.ids)
res = self.env.ref("helpdesk_mgmt.ticket_view_tree", False)
tree_view = [(res and res.id or False, "tree")]
Expand All @@ -41,7 +53,7 @@ def action_view_ticket(self):
]
else:
result["views"] = tree_view
elif len(self.ticket_ids) == 1:
elif self.ticket_count == 1:
res = self.env.ref("helpdesk_mgmt.ticket_view_form", False)
form_view = [(res and res.id or False, "form")]
if "views" in result:
Expand Down
4 changes: 4 additions & 0 deletions helpdesk_mgmt_project/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
* `Sygel <https://www.sygel.es>`_:

* Manuel Regidor

* `ALBA Software <https://www.albasoft.com>`_:

* Rafa Morant
6 changes: 5 additions & 1 deletion helpdesk_mgmt_project/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Helpdesk Project</title>
<style type="text/css">

Expand Down Expand Up @@ -421,6 +421,10 @@ <h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<li>Manuel Regidor</li>
</ul>
</li>
<li><a class="reference external" href="https://www.albasoft.com">ALBA Software</a>:<ul>
<li>Rafa Morant</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down

0 comments on commit f07075f

Please sign in to comment.