[CLN] global: apply ruff
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
===============================
|
||||
helpdesk_convert_ticket_to_task
|
||||
===============================
|
||||
# helpdesk_convert_ticket_to_task
|
||||
|
||||
This module aims to convert a ticket into a task.
|
||||
For this, it adds a button in the ticket view "Convert to task".
|
||||
This module changes the behavior of the buttons "create" and "create and edit" of the
|
||||
field `task` in a ticket form.
|
||||
|
||||
It automatically fills up many fields (check the function button_convert_to_task for details)
|
||||
|
||||
@@ -14,16 +12,16 @@ Use Odoo normal module installation procedure to install
|
||||
|
||||
# Known issues / Roadmap
|
||||
|
||||
A current limitation is that one task can be linked to many tickets.
|
||||
Thus, the above task fields are filled up at the creation of the task from a ticket form
|
||||
but are not updated when the linked tickets are updated.
|
||||
A current limitation is that one task can be linked to many tickets. Thus, the above
|
||||
task fields are filled up at the creation of the task from a ticket form but are not
|
||||
updated when the linked tickets are updated.
|
||||
|
||||
# Bug Tracker
|
||||
|
||||
Bugs are tracked on `our issues website <https://github.com/elabore-coop/helpdesk-tools/issues>`\_. In case of
|
||||
trouble, please check there if your issue has already been
|
||||
reported. If you spotted it first, help us smashing it by providing a
|
||||
detailed and welcomed feedback.
|
||||
Bugs are tracked on
|
||||
`our issues website <https://github.com/elabore-coop/helpdesk-tools/issues>`\_. In case
|
||||
of trouble, please check there if your issue has already been reported. If you spotted
|
||||
it first, help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
# Credits
|
||||
|
||||
|
@@ -13,10 +13,13 @@
|
||||
"base",
|
||||
"helpdesk_mgmt",
|
||||
"helpdesk_mgmt_project",
|
||||
"helpdesk_request_type", # to create the helpdesk.request.type model and have the field request_type_id in the helpdesk.ticket model
|
||||
"project_request_data", # to have the fields service_id and request_type_id in the project.task model
|
||||
# to create the helpdesk.request.type model and have the field request_type_id
|
||||
# in the helpdesk.ticket model
|
||||
"helpdesk_request_type",
|
||||
# to have the fields service_id and request_type_id in the project.task model
|
||||
"project_request_data",
|
||||
"project_task_add_very_high", # to have priority values 2 and 3 on tasks
|
||||
"helpdesk_transfer_timesheet_to_task" # to copy timesheets from ticket to task
|
||||
"helpdesk_transfer_timesheet_to_task", # to copy timesheets from ticket to task
|
||||
],
|
||||
"data": [
|
||||
"views/helpdesk_convert_ticket_to_task.xml",
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from odoo import _, models, api
|
||||
|
||||
|
||||
class HelpdeskTicket(models.Model):
|
||||
_inherit = "helpdesk.ticket"
|
||||
|
||||
@@ -7,42 +8,41 @@ class HelpdeskTicket(models.Model):
|
||||
user_ids = [self.user_id.id]
|
||||
task_service_id, request_type_id = self._match_task_service_and_request_type(
|
||||
ticket_category_id=self.category_id.id,
|
||||
ticket_request_type_id=self.request_type_id.id
|
||||
ticket_request_type_id=self.request_type_id.id,
|
||||
)
|
||||
|
||||
task = self.env["project.task"].create({
|
||||
"name": self.name,
|
||||
"description": self.description,
|
||||
"project_id": self.project_id.id,
|
||||
"user_ids": user_ids,
|
||||
"partner_id": self.partner_id.id,
|
||||
"service_id": task_service_id,
|
||||
"request_type_id": request_type_id,
|
||||
"priority": self.priority
|
||||
})
|
||||
task = self.env["project.task"].create(
|
||||
{
|
||||
"name": self.name,
|
||||
"description": self.description,
|
||||
"project_id": self.project_id.id,
|
||||
"user_ids": user_ids,
|
||||
"partner_id": self.partner_id.id,
|
||||
"service_id": task_service_id,
|
||||
"request_type_id": request_type_id,
|
||||
"priority": self.priority,
|
||||
}
|
||||
)
|
||||
|
||||
# copy chatter
|
||||
for msg in reversed(self.message_ids):
|
||||
msg.copy({
|
||||
'model': 'project.task',
|
||||
'res_id': task.id
|
||||
})
|
||||
msg.copy({"model": "project.task", "res_id": task.id})
|
||||
|
||||
# copy attachments inserted in the messages
|
||||
for attach in msg.attachment_ids:
|
||||
attach.copy({
|
||||
'res_model': 'project.task',
|
||||
'res_id': task.id,
|
||||
'res_name': task.name
|
||||
})
|
||||
attach.copy(
|
||||
{
|
||||
"res_model": "project.task",
|
||||
"res_id": task.id,
|
||||
"res_name": task.name,
|
||||
}
|
||||
)
|
||||
|
||||
# copy attachments not added in a message
|
||||
for attachment in self.attachment_ids:
|
||||
attachment.copy({
|
||||
'res_model': 'project.task',
|
||||
'res_id': task.id,
|
||||
'res_name': task.name
|
||||
})
|
||||
attachment.copy(
|
||||
{"res_model": "project.task", "res_id": task.id, "res_name": task.name}
|
||||
)
|
||||
|
||||
# copy subscribers
|
||||
task.message_subscribe(partner_ids=self.message_partner_ids.ids)
|
||||
@@ -52,7 +52,7 @@ class HelpdeskTicket(models.Model):
|
||||
ticket_url = f"{base_url}/web#id={self.id}&model=helpdesk.ticket&view_type=form"
|
||||
task_message = _(
|
||||
"This task has been converted from a ticket. You can find the original ticket <a href='%(ticket_url)s' target='_blank'>on this link</a>.",
|
||||
ticket_url=ticket_url
|
||||
ticket_url=ticket_url,
|
||||
)
|
||||
task.message_post(body=task_message)
|
||||
|
||||
@@ -60,15 +60,12 @@ class HelpdeskTicket(models.Model):
|
||||
task_url = f"{base_url}/web#id={task.id}&model=project.task&view_type=form"
|
||||
ticket_message = _(
|
||||
"This ticket has been converted into a task. You can find it <a href='%(task_url)s' target='_blank'>on this link</a>.",
|
||||
task_url=task_url
|
||||
task_url=task_url,
|
||||
)
|
||||
self.message_post(body=ticket_message)
|
||||
|
||||
# archive the ticket
|
||||
self.write({
|
||||
"active": False,
|
||||
"task_id": task.id
|
||||
})
|
||||
self.write({"active": False, "task_id": task.id})
|
||||
# transfer timesheets from ticket to task
|
||||
self._onchange_task_id()
|
||||
|
||||
@@ -81,23 +78,23 @@ class HelpdeskTicket(models.Model):
|
||||
}
|
||||
|
||||
def _match_task_service_and_request_type(
|
||||
self,
|
||||
ticket_category_id: int,
|
||||
ticket_request_type_id: int
|
||||
self, ticket_category_id: int, ticket_request_type_id: int
|
||||
) -> tuple[int, int]:
|
||||
"""
|
||||
This function permits to match the task service_id and request_type from the ticket category and request type
|
||||
"""
|
||||
helpdesk_ticket_category = self.env["helpdesk.ticket.category"].search(
|
||||
[("id", "=", ticket_category_id)],
|
||||
limit=1
|
||||
[("id", "=", ticket_category_id)], limit=1
|
||||
)
|
||||
task_service = self.env["task.service"].search(
|
||||
[("name", "=", helpdesk_ticket_category.name)]
|
||||
)
|
||||
task_service = self.env["task.service"].search([("name", "=", helpdesk_ticket_category.name)])
|
||||
|
||||
helpdesk_ticket_request_type = self.env["helpdesk.request.type"].search(
|
||||
[("id", "=", ticket_request_type_id)],
|
||||
limit=1
|
||||
[("id", "=", ticket_request_type_id)], limit=1
|
||||
)
|
||||
task_request_type = self.env["request.type"].search(
|
||||
[("name", "=", helpdesk_ticket_request_type.name)]
|
||||
)
|
||||
task_request_type = self.env["request.type"].search([("name", "=", helpdesk_ticket_request_type.name)])
|
||||
|
||||
return task_service.id, task_request_type.id
|
||||
|
Reference in New Issue
Block a user