Browse Source

ADD mail_force_queue

Force outgoing emails to be queued instead of sent immediately.
Queued emails are sent by 'Email Queue Manager' cron.
pull/242/head
eLBati 7 years ago
committed by Holger Brunn
parent
commit
0f9deb0e7a
  1. 62
      mail_force_queue/README.rst
  2. 4
      mail_force_queue/__init__.py
  3. 21
      mail_force_queue/__manifest__.py
  4. 7
      mail_force_queue/models/__init__.py
  5. 19
      mail_force_queue/models/mail_message.py
  6. 11
      mail_force_queue/models/res_company.py
  7. 14
      mail_force_queue/models/res_config.py
  8. BIN
      mail_force_queue/static/description/icon.png
  9. 5
      mail_force_queue/tests/__init__.py
  10. 61
      mail_force_queue/tests/test_mail_notification.py
  11. 16
      mail_force_queue/views/res_config_view.xml

62
mail_force_queue/README.rst

@ -0,0 +1,62 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3
==================
Email: force queue
==================
Force outgoing emails to be queued instead of sent immediately.
Queued emails are sent by 'Email Queue Manager' cron.
This also solves possible TransactionRollbackError while deleting outgoing email (see `https://github.com/odoo/odoo/issues/22148
<https://github.com/odoo/odoo/issues/22148>`_.)
Usage
=====
Go to 'General Settings' and set 'Force Mail queue'
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

4
mail_force_queue/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import models

21
mail_force_queue/__manifest__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Email: force queue",
"summary": "Force outgoing emails to be queued",
"version": "10.0.0.2.0",
"category": "Discuss",
"website": "https://github.com/OCA/social",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"mail",
],
"data": [
"views/res_config_view.xml",
],
}

7
mail_force_queue/models/__init__.py

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import mail_message
from . import res_company
from . import res_config

19
mail_force_queue/models/mail_message.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import models, api
class Message(models.Model):
_inherit = 'mail.message'
@api.model
def create(self, values):
if self.env.user.company_id.force_mail_queue:
mail_notify_force_send = self.env.context.get(
'mail_notify_force_send', False)
return super(Message, self.with_context(
mail_notify_force_send=mail_notify_force_send)).create(values)
else:
return super(Message, self).create(values)

11
mail_force_queue/models/res_company.py

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import models, fields
class ResCompany(models.Model):
_inherit = "res.company"
force_mail_queue = fields.Boolean("Force Mail queue")

14
mail_force_queue/models/res_config.py

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import fields, models
class BaseConfigSettings(models.TransientModel):
_inherit = 'base.config.settings'
force_mail_queue = fields.Boolean(
related="company_id.force_mail_queue", string="Force Mail queue",
help="Force outgoing emails to be queued instead of sent immediately. "
"Queued emails are sent by 'Email Queue Manager' cron")

BIN
mail_force_queue/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

5
mail_force_queue/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import test_mail_notification

61
mail_force_queue/tests/test_mail_notification.py

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import odoo.tests.common as common
class TestMailNotification(common.TransactionCase):
def setUp(self):
super(TestMailNotification, self).setUp()
self.partner_obj = self.env['res.partner']
self.env.user.company_id.force_mail_queue = True
def test_get_signature_footer(self):
vals = {
'name': 'p1@example.com',
'email': 'p1@example.com',
}
partner1 = self.partner_obj.create(vals)
body = 'this is the body'
subject = 'this is the subject'
res = partner1.message_post(
subject=subject,
body=body,
content_subtype="plaintext",
partner_ids=[partner1.id],
)
mail = self.env['mail.mail'].search([
('mail_message_id', '=', res.id)
])
# default behaviour: outgoing mail queued
self.assertTrue(mail)
self.assertEqual(mail.state, 'outgoing')
res = partner1.with_context(mail_notify_force_send=True).message_post(
subject=subject,
body=body,
content_subtype="plaintext",
partner_ids=[partner1.id],
)
mail = self.env['mail.mail'].search([
('mail_message_id', '=', res.id)
])
# force send immediately: outgoing email is sent and deleted
self.assertFalse(mail)
res = partner1.with_context(mail_notify_force_send=False).message_post(
subject=subject,
body=body,
content_subtype="plaintext",
partner_ids=[partner1.id],
)
mail = self.env['mail.mail'].search([
('mail_message_id', '=', res.id)
])
# do not send immediately
self.assertTrue(mail)
self.assertEqual(mail.state, 'outgoing')

16
mail_force_queue/views/res_config_view.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_general_configuration_mail_force_queue" model="ir.ui.view">
<field name="name">view_general_configuration_mail_force_queue</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='email']" position='inside'>
<div>
<field name="force_mail_queue" class="oe_inline"/>
<label for="force_mail_queue"/>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save