Skip to content

Commit

Permalink
[15.0][ADD] heldespk_mgmt: Helpdesk stages per teams
Browse files Browse the repository at this point in the history
TT45710
  • Loading branch information
carolinafernandez-tecnativa committed Nov 6, 2023
1 parent 77cdcc6 commit ba39992
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 16 deletions.
5 changes: 0 additions & 5 deletions helpdesk_mgmt/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ def _prepare_submit_ticket_vals(self, **kw):
"partner_id": request.env.user.partner_id.id,
"partner_name": request.env.user.partner_id.name,
"partner_email": request.env.user.partner_id.email,
# Need to set stage_id so that the _track_template() method is called
# and the mail is sent automatically if applicable
"stage_id": request.env["helpdesk.ticket"]
.with_company(company.id)
.default_get(["stage_id"])["stage_id"],
}
if company.helpdesk_mgmt_portal_select_team and kw.get("team"):
team = (
Expand Down
17 changes: 15 additions & 2 deletions helpdesk_mgmt/controllers/myaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def portal_my_tickets(
searchbar_filters = {
"all": {"label": _("All"), "domain": []},
}
for stage in request.env["helpdesk.ticket.stage"].search([]):
for stage in request.env["helpdesk.ticket.stage"].search(
[
"|",
("team_ids", "=", HelpdeskTicket.team_id.id),
("team_ids", "=", False),
]
):
searchbar_filters[str(stage.id)] = {
"label": stage.name,
"domain": [("stage_id", "=", stage.id)],
Expand Down Expand Up @@ -183,8 +189,15 @@ def portal_my_ticket(self, ticket_id, access_token=None, **kw):

def _ticket_get_page_view_values(self, ticket, access_token, **kwargs):
closed_stages = request.env["helpdesk.ticket.stage"].search(
[("close_from_portal", "=", True)]
[
"&",
"|",
("team_ids", "=", ticket.team_id.id),
("team_ids", "=", False),
("close_from_portal", "=", True),
]
)

values = {
"closed_stages": closed_stages, # used to display close buttons
"page_name": "ticket",
Expand Down
53 changes: 44 additions & 9 deletions helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,39 @@ class HelpdeskTicket(models.Model):
_mail_post_access = "read"
_inherit = ["mail.thread.cc", "mail.activity.mixin", "portal.mixin"]

def _get_default_stage_id(self):
return self.env["helpdesk.ticket.stage"].search([], limit=1).id
@api.depends("team_id")
def _compute_stage_ids(self):
for ticket in self.filtered(lambda ticket: ticket.team_id):
if ticket.team_id:
ticket.stage_id = ticket.team_id._determine_stage()[ticket.team_id.id]
else:
ticket.stage_id = (

Check warning on line 19 in helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L19

Added line #L19 was not covered by tests
self.env["helpdesk.ticket.stage"]
.search([("team_ids", "=", False)], order="sequence", limit=1)
.id
)

@api.model
def _read_group_stage_ids(self, stages, domain, order):
stage_ids = self.env["helpdesk.ticket.stage"].search([])
return stage_ids
search_domain = [("id", "in", stages.ids)]

Check warning on line 27 in helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L27

Added line #L27 was not covered by tests
if self.env.context.get("default_team_id"):
search_domain = [

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

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L29

Added line #L29 was not covered by tests
"|",
"|",
("team_ids", "=", False),
("team_ids", "in", self.env.context["default_team_id"]),
] + search_domain
return stages.search(search_domain, order=order)

Check warning on line 35 in helpdesk_mgmt/models/helpdesk_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L35

Added line #L35 was not covered by tests

def _default_team_id(self):
team_id = (
self.env["helpdesk.ticket.team"]
.search([("user_ids", "in", self.env.uid)], limit=1)
.id
)
if not team_id:
team_id = self.env["helpdesk.ticket.team"].search([], limit=1).id
return team_id

number = fields.Char(string="Ticket number", default="/", readonly=True)
name = fields.Char(string="Title", required=True)
Expand All @@ -31,16 +57,21 @@ def _read_group_stage_ids(self, stages, domain, order):
user_ids = fields.Many2many(
comodel_name="res.users", related="team_id.user_ids", string="Users"
)

stage_id = fields.Many2one(
comodel_name="helpdesk.ticket.stage",
"helpdesk.ticket.stage",
string="Stage",
group_expand="_read_group_stage_ids",
default=_get_default_stage_id,
tracking=True,
compute="_compute_stage_ids",
store=True,
readonly=False,
ondelete="restrict",
index=True,
tracking=True,
group_expand="_read_group_stage_ids",
copy=False,
index=True,
domain="['|',('team_ids', '=', team_id),('team_ids','=',False)]",
)

partner_id = fields.Many2one(comodel_name="res.partner", string="Contact")
partner_name = fields.Char()
partner_email = fields.Char(string="Email")
Expand Down Expand Up @@ -70,6 +101,7 @@ def _read_group_stage_ids(self, stages, domain, order):
team_id = fields.Many2one(
comodel_name="helpdesk.ticket.team",
string="Team",
default=_default_team_id,
)
priority = fields.Selection(
selection=[
Expand Down Expand Up @@ -130,6 +162,9 @@ def create(self, vals_list):
vals["number"] = self._prepare_ticket_number(vals)
if vals.get("user_id") and not vals.get("assigned_date"):
vals["assigned_date"] = fields.Datetime.now()
if vals.get("team_id"):
team = self.env["helpdesk.ticket.team"].browse(vals["team_id"])
vals["stage_id"] = team._determine_stage()[team.id].id
return super().create(vals_list)

def copy(self, default=None):
Expand Down
6 changes: 6 additions & 0 deletions helpdesk_mgmt/models/helpdesk_ticket_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class HelpdeskTicketStage(models.Model):
string="Company",
default=lambda self: self.env.company,
)
team_ids = fields.Many2many(
comodel_name="helpdesk.ticket.team",
relation="team_stage_rel",
string="Helpdesk Teams",
help="Specific team that uses this stage. If it is empty all teams could uses",
)

@api.onchange("closed")
def _onchange_closed(self):
Expand Down
10 changes: 10 additions & 0 deletions helpdesk_mgmt/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class HelpdeskTeam(models.Model):
help="Allow to select this team when creating a new ticket in the portal.",
)

def _determine_stage(self):
result = dict.fromkeys(self.ids, self.env["helpdesk.ticket.stage"])
for team in self:
result[team.id] = self.env["helpdesk.ticket.stage"].search(
["|", ("team_ids", "=", False), ("team_ids", "in", team.id)],
order="sequence",
limit=1,
)
return result

@api.depends("ticket_ids", "ticket_ids.stage_id")
def _compute_todo_tickets(self):
ticket_model = self.env["helpdesk.ticket"]
Expand Down
1 change: 1 addition & 0 deletions helpdesk_mgmt/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

* Pedro M. Baeza
* Víctor Martínez
* Carolina Fernandez

* `ID42 Sistemas <https://www.id42.com.br>`_:

Expand Down
1 change: 1 addition & 0 deletions helpdesk_mgmt/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>Víctor Martínez</li>
<li>Carolina Fernandez</li>
</ul>
</li>
<li><a class="reference external" href="https://www.id42.com.br">ID42 Sistemas</a>:<ul>
Expand Down
3 changes: 3 additions & 0 deletions helpdesk_mgmt/views/helpdesk_ticket_stage_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/>
<separator />
<field name="name" filter_domain="[('name', 'ilike', self)]" />
<field name="team_ids" />
<field name="company_id" groups="base.group_multi_company" />
<group>
<filter
Expand Down Expand Up @@ -49,6 +50,7 @@
<group name="main_left">
<field name="sequence" />
<field name="mail_template_id" />
<field name="team_ids" widget="many2many_tags" />
<field
name="company_id"
groups="base.group_multi_company"
Expand Down Expand Up @@ -77,6 +79,7 @@
<field name="sequence" widget="handle" />
<field name="name" />
<field name="mail_template_id" />
<field name="team_ids" widget="many2many_tags" />
<field
name="company_id"
optional="hide"
Expand Down

0 comments on commit ba39992

Please sign in to comment.