Browse Source

[ADD] Add mail attach existing attachment module

pull/4/head
Adrien Peiffer (ACSONE) 10 years ago
parent
commit
d4100283fc
  1. 44
      mail_attach_attachment/README.rst
  2. 2
      mail_attach_attachment/__init__.py
  3. 40
      mail_attach_attachment/__openerp__.py
  4. 3
      mail_attach_attachment/tests/__init__.py
  5. 49
      mail_attach_attachment/tests/test_mail_attach_attachment.py
  6. 2
      mail_attach_attachment/wizard/__init__.py
  7. 57
      mail_attach_attachment/wizard/mail_compose_message.py
  8. 19
      mail_attach_attachment/wizard/mail_compose_message_view.xml

44
mail_attach_attachment/README.rst

@ -0,0 +1,44 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Mail Attach Attachment
======================
This module was written to add the possibility to add attachments located on
the object by sending it by email with the mail compose message wizard
Installation
============
To install this module, you need to:
* Click on install
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_attach_attachment%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>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.

2
mail_attach_attachment/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import wizard

40
mail_attach_attachment/__openerp__.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of mail_attach_attachment,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# mail_attach_attachment is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# mail_attach_attachment is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with mail_attach_attachment.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': "Mail Attach Attachment",
'summary': """
Adding attachment on the object by sending this one""",
'author': "ACSONE SA/NV,Odoo Community Association (OCA)",
'website': "http://acsone.eu",
'category': 'Uncategorized',
'version': '8.0.0.0.1',
'license': 'AGPL-3',
'depends': [
'mail',
],
'data': [
'wizard/mail_compose_message_view.xml',
],
}

3
mail_attach_attachment/tests/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import test_mail_attach_attachment

49
mail_attach_attachment/tests/test_mail_attach_attachment.py

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of mail_attach_attachment,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# mail_attach_attachment is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# mail_attach_attachment is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with mail_attach_attachment.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests import common
class TestAttachAttachment(common.TransactionCase):
def setUp(self):
super(TestAttachAttachment, self).setUp()
self.partner_obj = self.env['res.partner']
self.partner_01 = self.env.ref('base.res_partner_1')
def test_send_email_attachment(self):
attach1 = self.env['ir.attachment'].create({
'name': 'Attach1', 'datas_fname': 'Attach1',
'datas': 'bWlncmF0aW9uIHRlc3Q=',
'res_model': 'res.partner', 'res_id': self.partner_01.id})
vals = {'model': 'res.partner',
'partner_ids': [(6, 0, [self.partner_01.id])],
'res_id': self.partner_01.id,
'object_attachment_ids': [(6, 0, [attach1.id])]
}
mail = self.env['mail.compose.message'].create(vals)
values = mail.get_mail_values(mail, [self.partner_01.id])
self.assertTrue(attach1.id in
values[self.partner_01.id]['attachment_ids'])

2
mail_attach_attachment/wizard/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import mail_compose_message

57
mail_attach_attachment/wizard/mail_compose_message.py

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of mail_attach_attachment,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# mail_attach_attachment is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# mail_attach_attachment is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with mail_attach_attachment.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
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)
if res.get('res_id') and res.get('model') and \
res.get('composition_mode', '') != 'mass_mail' and\
not res.get('can_attach_attachment'):
res['can_attach_attachment'] = True
return res
can_attach_attachment = fields.Boolean(string='Can Attach Attachment')
object_attachment_ids = fields.Many2many(
comodel_name='ir.attachment',
relation='mail_compose_message_ir_attachments_object_rel',
column1='wizard_id', column2='attachment_id', string='Attachments')
@api.model
def get_mail_values(self, wizard, res_ids):
res = super(MailComposeMessage, self).get_mail_values(wizard, res_ids)
if wizard.object_attachment_ids.ids and wizard.model and\
len(res_ids) == 1:
for res_id in res_ids:
if not res[res_id].get('attachment_ids'):
res[res_id]['attachment_ids'] = []
res[res_id]['attachment_ids'].extend(
wizard.object_attachment_ids.ids)
return res

19
mail_attach_attachment/wizard/mail_compose_message_view.xml

@ -0,0 +1,19 @@
<?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_attach_attachment)</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="//field[@name='attachment_ids']" position="after">
<field name="can_attach_attachment" invisible="1"/>
<div attrs="{'invisible': [('can_attach_attachment', '=', False)]}">
<br />
<field name="object_attachment_ids" widget="many2many_checkboxes" domain="[('res_model', '=', model), ('res_id', '=', res_id)]" />
</div>
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save