Browse Source

Merge pull request #53 from acsone/8.0-add-mail_optional_autofollow-ape

[8.0][ADD] Add mail_optional_autofollow module
pull/55/head
Pedro M. Baeza 9 years ago
parent
commit
f13f5f6bfa
  1. 1
      .gitignore
  2. 55
      mail_optional_autofollow/README.rst
  3. 4
      mail_optional_autofollow/__init__.py
  4. 21
      mail_optional_autofollow/__openerp__.py
  5. BIN
      mail_optional_autofollow/static/description/autofollow.png
  6. BIN
      mail_optional_autofollow/static/description/icon.png
  7. 5
      mail_optional_autofollow/tests/__init__.py
  8. 45
      mail_optional_autofollow/tests/test_mail_optional_autofollow.py
  9. 4
      mail_optional_autofollow/wizard/__init__.py
  10. 29
      mail_optional_autofollow/wizard/mail_compose_message.py
  11. 15
      mail_optional_autofollow/wizard/mail_compose_message_view.xml

1
.gitignore

@ -1,3 +1,4 @@
*~
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

55
mail_optional_autofollow/README.rst

@ -0,0 +1,55 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
========================
Mail optional autofollow
========================
This module adds the possibility to choose if you want to automatically
add new recipients as followers on mail.compose.message.
Usage
=====
To use this module, you need to use the autofollow recipients checkbox on mail.compose.message:
Technically, this field is initialized to true if there is a
'mail_post_autofollow' key in the current context
.. figure:: static/description/autofollow.png
:alt: autofollow recipients checkbox
.. 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/8.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 smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/social/issues/new?body=module:%20mail_optional_autofollow%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
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_optional_autofollow/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import wizard

21
mail_optional_autofollow/__openerp__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "Mail optional autofollow",
'summary': """
Choose if you want to automatically add new recipients as followers
on mail.compose.message""",
'author': 'ACSONE SA/NV,'
'Odoo Community Association (OCA)',
'website': "http://acsone.eu",
'category': 'Social Network',
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'mail',
],
'data': [
'wizard/mail_compose_message_view.xml',
],
}

BIN
mail_optional_autofollow/static/description/autofollow.png

After

Width: 903  |  Height: 155  |  Size: 16 KiB

BIN
mail_optional_autofollow/static/description/icon.png

After

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

5
mail_optional_autofollow/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_mail_optional_autofollow

45
mail_optional_autofollow/tests/test_mail_optional_autofollow.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
class TestAttachExistingAttachment(common.TransactionCase):
def setUp(self):
super(TestAttachExistingAttachment, self).setUp()
self.partner_obj = self.env['res.partner']
self.partner_01 = self.env.ref('base.res_partner_11')
self.partner_02 = self.env.ref('base.res_partner_address_20')
def test_send_email_attachment(self):
ctx = self.env.context.copy()
ctx.update({
'default_model': 'res.partner',
'default_res_id': self.partner_01.id,
'default_composition_mode': 'comment',
})
mail_compose = self.env['mail.compose.message']
values = mail_compose.with_context(ctx)\
.onchange_template_id(False, 'comment', 'res.partner',
self.partner_01.id)['value']
values['partner_ids'] = [(4, self.partner_02.id)]
compose_id = mail_compose.with_context(ctx).create(values)
compose_id.autofollow_recipients = False
compose_id.with_context(ctx).send_mail()
res = self.env["mail.followers"].search(
[('res_model', '=', 'res.partner'),
('res_id', '=', self.partner_01.id),
('partner_id', '=', self.partner_02.id)])
# I check if the recipient isn't a follower
self.assertEqual(len(res.ids), 0)
compose_id = mail_compose.with_context(ctx).create(values)
compose_id.autofollow_recipients = True
compose_id.with_context(ctx).send_mail()
res = self.env["mail.followers"].search(
[('res_model', '=', 'res.partner'),
('res_id', '=', self.partner_01.id),
('partner_id', '=', self.partner_02.id)])
# I check if the recipient is a follower
self.assertEqual(len(res.ids), 1)

4
mail_optional_autofollow/wizard/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import mail_compose_message

29
mail_optional_autofollow/wizard/mail_compose_message.py

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api
class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message'
@api.model
def default_get(self, fields_list):
res = super(MailComposeMessage, self).default_get(fields_list)
res.setdefault(
'autofollow_recipients',
self.env.context.get('mail_post_autofollow', False))
return res
autofollow_recipients = fields.Boolean(
string='Make recipients followers',
help="""if checked, the additional recipients will be added as\
followers on the related object""")
@api.multi
def send_mail(self):
for wizard in self:
super(MailComposeMessage, wizard.with_context(
mail_post_autofollow=wizard.autofollow_recipients)).send_mail()
return {'type': 'ir.actions.act_window_close'}

15
mail_optional_autofollow/wizard/mail_compose_message_view.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record model="ir.ui.view" id="email_compose_message_wizard_inherit_form">
<field name="name">mail.compose.message.form (mail_optional_autofollow)</field>
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<xpath expr="//div[field[@name='partner_ids']]" position="after">
<field name="autofollow_recipients" />
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save