Skip to content

Commit

Permalink
[FIX] helpdesk_mgmt: format email when receive it from new message ma…
Browse files Browse the repository at this point in the history
…il gateway

Before, email was like '"Name" <name@company.com>'
Now, email is like 'name@company.com'
To field partner_email into model helpdesk.ticket
  • Loading branch information
mathben committed Jul 23, 2023
1 parent 7f7adf7 commit 6911bdf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from odoo import _, api, fields, models, tools
from odoo.exceptions import AccessError

Expand Down Expand Up @@ -206,6 +208,14 @@ def _track_template(self, tracking):
)
return res

def _extract_email(self, label):
emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", label)
if len(emails) == 1:
return emails[0]
elif not emails:
return ""
return emails

@api.model
def message_new(self, msg, custom_values=None):
"""Override message_new from mail gateway so we can set correct
Expand All @@ -216,7 +226,7 @@ def message_new(self, msg, custom_values=None):
defaults = {
"name": msg.get("subject") or _("No Subject"),
"description": msg.get("body"),
"partner_email": msg.get("from"),
"partner_email": self._extract_email(msg.get("from")),
"partner_id": msg.get("author_id"),
}
defaults.update(custom_values)
Expand Down

0 comments on commit 6911bdf

Please sign in to comment.