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" <[email protected]>'
Now, email is like '[email protected]'
To field partner_email into model helpdesk.ticket
  • Loading branch information
mathben committed Jul 23, 2023
1 parent 7f7adf7 commit efecb5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 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,16 @@ def _track_template(self, tracking):
)
return res

def _extract_email(self, label):
if not label:
return ""

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

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L213

Added line #L213 was not covered by tests
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

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

View check run for this annotation

Codecov / codecov/patch

helpdesk_mgmt/models/helpdesk_ticket.py#L218-L219

Added lines #L218 - L219 were not covered by tests

@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 +228,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
1 change: 1 addition & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_helpdesk_ticket_message_new(self):
"message_id": msg_id,
"subject": title,
"email_from": "Bob <[email protected]>",
"from": "Bob <[email protected]>",
"to": "[email protected]",
"cc": "[email protected]",
"recipients": "[email protected][email protected]",
Expand Down

0 comments on commit efecb5f

Please sign in to comment.