Skip to content

Commit

Permalink
[MIG] mail_server_by_user: migrate to V17
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Nov 29, 2024
1 parent 081ba34 commit a079175
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 39 deletions.
6 changes: 1 addition & 5 deletions mail_server_by_user/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
{
"name": "Email Server By User",
"summary": "Email Server By User",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": ("ForgeFlow, " "Odoo Community Association (OCA)"),
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": ["base", "mail"],
"development_status": "Alpha",
"maintainers": ["ChrisOForgeFlow"],
"data": [],
"qweb": [],
"demo": [],
}
11 changes: 9 additions & 2 deletions mail_server_by_user/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
class MailMail(models.Model):
_inherit = "mail.mail"

def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
def _send(
self,
auto_commit=False,
raise_exception=False,
smtp_session=None,
alias_domain_id=False,
):
mail_server_model = self.env["ir.mail_server"].sudo()
for rec in self:
if rec.email_from:
Expand All @@ -19,8 +25,9 @@ def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
and rec.mail_server_id.id != mail_server_suggested.id
):
rec.mail_server_id = mail_server_suggested.id
return super(MailMail, self)._send(
return super()._send(
auto_commit=auto_commit,
raise_exception=raise_exception,
smtp_session=smtp_session,
alias_domain_id=alias_domain_id,
)
27 changes: 2 additions & 25 deletions mail_server_by_user/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,7 @@
class MailThread(models.AbstractModel):
_inherit = "mail.thread"

def _notify_thread_by_email(
self,
message,
recipients_data,
msg_vals=False,
mail_auto_delete=True,
model_description=False,
force_email_company=False,
force_email_lang=False,
resend_existing=False,
force_send=True,
send_after_commit=True,
subtitles=None,
**kwargs,
):
def _notify_thread_by_email(self, message, recipients_data, **kwargs):
mail_server_model = self.env["ir.mail_server"].sudo()
if message.email_from:
mail_server_suggested = mail_server_model.search(
Expand All @@ -33,17 +19,8 @@ def _notify_thread_by_email(
and message.mail_server_id.id != mail_server_suggested.id
):
message.mail_server_id = mail_server_suggested.id
return super(MailThread, self)._notify_thread_by_email(
return super()._notify_thread_by_email(
message,
recipients_data,
msg_vals=msg_vals,
mail_auto_delete=mail_auto_delete,
model_description=model_description,
force_email_company=force_email_company,
force_email_lang=force_email_lang,
resend_existing=resend_existing,
force_send=force_send,
send_after_commit=send_after_commit,
subtitles=subtitles,
**kwargs,
)
11 changes: 4 additions & 7 deletions mail_server_by_user/tests/test_mail_server_by_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

class TestIrMailServer(TransactionCase):
def setUp(self):
super(TestIrMailServer, self).setUp()
super().setUp()
self.smtp_server_model = self.env["ir.mail_server"]
self.parameter_model = self.env["ir.config_parameter"]
# self.default_template = self.env.ref("mail.message_notification_email")
# self.paynow_template = self.env.ref("mail.mail_notification_paynow")
self.server_1 = self.smtp_server_model.create(
{
"name": "localhost",
Expand Down Expand Up @@ -95,13 +93,11 @@ def _send_mail(self, message=None, mail_server_id=None, smtp_server=None):
if message is None:
message = self.message
connect = MagicMock()
self.smtp_server_model._patch_method("connect", connect)
self.patch(type(self.smtp_server_model), "connect", connect)
try:
self.smtp_server_model.send_email(message, mail_server_id, smtp_server)
except Exception as e:
_logger.debug(str(e))
finally:
self.smtp_server_model._revert_method("connect")
call_args = connect.call_args
return call_args

Expand All @@ -120,7 +116,8 @@ def test_send_email_change_smtp_server(self):
self.message.replace_header("From", self.user3.login)
call_args = self._send_mail()
mail_server_id = call_args.kwargs.get("mail_server_id", False)
# With this module, you always get mail server on call, only test when is not installed
# With this module, you always get mail server on call, only test when
# is not installed
if not self.env["ir.module.module"].search(
[("name", "=", "mail_outbound_static"), ("state", "=", "installed")]
):
Expand Down
Binary file removed pandoc-3.1.9-1-amd64.deb
Binary file not shown.

0 comments on commit a079175

Please sign in to comment.