From 6b3b76e9e7395a09750c527960157f3253dda1cc Mon Sep 17 00:00:00 2001 From: xtremxpert Date: Thu, 31 Oct 2024 13:33:53 -0400 Subject: [PATCH] fix for bemade_helpdesk_one_ticket_per_email/models/mail_thread.py --- .../models/mail_thread.py | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/bemade_helpdesk_one_ticket_per_email/models/mail_thread.py b/bemade_helpdesk_one_ticket_per_email/models/mail_thread.py index d8b62b5..cdcfd05 100644 --- a/bemade_helpdesk_one_ticket_per_email/models/mail_thread.py +++ b/bemade_helpdesk_one_ticket_per_email/models/mail_thread.py @@ -9,9 +9,35 @@ class MailThread(models.AbstractModel): @api.model def _message_route_process(self, message, message_dict, routes): - helpdesk_routes = [r for r in routes if r[0] in ('helpdesk.ticket', 'helpdesk.team')] - if len(helpdesk_routes) > 1: - _logger.info("Messages contained multiple helpdesk routes. Only the first one will be used.") - helpdesk_routes.pop(0) - routes = routes - helpdesk_routes - return super()._message_route_process(message, message_dict, routes) + """ + Process the routes for an incoming message, ensuring only one helpdesk route is used if multiple + helpdesk routes are detected. + + This override filters the routes to avoid processing a message multiple times for helpdesk models + (`helpdesk.ticket` and `helpdesk.team`). If multiple helpdesk routes are found, only the first one + is retained, and a log entry is created to indicate the adjustment. + + Parameters: + message (object): The incoming message object. + message_dict (dict): Dictionary of parsed message values. + routes (list): List of route tuples, each containing the target model and relevant information. + + Returns: + bool: Result of the `_message_route_process` from the superclass. + """ + try: + # Filter routes to keep only those related to helpdesk models if they are present + helpdesk_routes = [r for r in routes if r[0] in ('helpdesk.ticket', 'helpdesk.team')] + + if helpdesk_routes: + _logger.info("Messages contained helpdesk routes. Only the first one will be used.") + # Retain only the first helpdesk route + routes = [helpdesk_routes[0]] + + # Call the parent method with potentially modified routes + return super()._message_route_process(message, message_dict, routes) + + except Exception as e: + # Log the exception and raise it to ensure errors are traceable + _logger.error(f"An error occurred in _message_route_process: {str(e)}") + raise UserError("An unexpected error occurred while processing message routes. Please contact support.") \ No newline at end of file