diff --git a/mail_attach_existing_attachment/README.rst b/mail_attach_existing_attachment/README.rst new file mode 100644 index 00000000..50784be0 --- /dev/null +++ b/mail_attach_existing_attachment/README.rst @@ -0,0 +1,68 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Mail Attach Existing 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 + +Usage +===== + +To configure this module, you need to: + +* Adding some attachments on an object + +.. figure:: static/description/attachment.png + :alt: Attachment on purchase order + +* Then, by sending the object via email, you can select the attachment added earlier + +.. figure:: static/description/ex_mail_compose_message.png + :alt: Sends the Purchase Order by email + +.. 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 + +Known issues / Roadmap +====================== + +* The module only allows the addition of attachments linked to the object. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Credits +======= + +Contributors +------------ + +* Adrien Peiffer + +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. \ No newline at end of file diff --git a/mail_attach_existing_attachment/__init__.py b/mail_attach_existing_attachment/__init__.py new file mode 100644 index 00000000..02baef47 --- /dev/null +++ b/mail_attach_existing_attachment/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import wizard diff --git a/mail_attach_existing_attachment/__openerp__.py b/mail_attach_existing_attachment/__openerp__.py new file mode 100644 index 00000000..7ec7bbb6 --- /dev/null +++ b/mail_attach_existing_attachment/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This file is part of mail_attach_existing_attachment, +# an Odoo module. +# +# Copyright (c) 2015 ACSONE SA/NV () +# +# mail_attach_existing_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_existing_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_existing_attachment. +# If not, see . +# +############################################################################## +{ + 'name': "Mail Attach Existing Attachment", + 'summary': """ + Adding attachment on the object by sending this one""", + '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', + 'document', + ], + 'data': [ + 'wizard/mail_compose_message_view.xml', + ], +} diff --git a/mail_attach_existing_attachment/static/description/attachment.png b/mail_attach_existing_attachment/static/description/attachment.png new file mode 100644 index 00000000..15e101e1 Binary files /dev/null and b/mail_attach_existing_attachment/static/description/attachment.png differ diff --git a/mail_attach_existing_attachment/static/description/ex_mail_compose_message.png b/mail_attach_existing_attachment/static/description/ex_mail_compose_message.png new file mode 100644 index 00000000..5742434e Binary files /dev/null and b/mail_attach_existing_attachment/static/description/ex_mail_compose_message.png differ diff --git a/mail_attach_existing_attachment/tests/__init__.py b/mail_attach_existing_attachment/tests/__init__.py new file mode 100644 index 00000000..26c2cf04 --- /dev/null +++ b/mail_attach_existing_attachment/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_mail_attach_existing_attachment diff --git a/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py b/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py new file mode 100644 index 00000000..eed39bc3 --- /dev/null +++ b/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This file is part of mail_attach_existing_attachment, +# an Odoo module. +# +# Copyright (c) 2015 ACSONE SA/NV () +# +# mail_attach_existing_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_existing_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_existing_attachment. +# If not, see . +# +############################################################################## + +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_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']) diff --git a/mail_attach_existing_attachment/wizard/__init__.py b/mail_attach_existing_attachment/wizard/__init__.py new file mode 100644 index 00000000..12ddb2dc --- /dev/null +++ b/mail_attach_existing_attachment/wizard/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import mail_compose_message diff --git a/mail_attach_existing_attachment/wizard/mail_compose_message.py b/mail_attach_existing_attachment/wizard/mail_compose_message.py new file mode 100644 index 00000000..4c7d43f3 --- /dev/null +++ b/mail_attach_existing_attachment/wizard/mail_compose_message.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This file is part of mail_attach_existing_attachment, +# an Odoo module. +# +# Copyright (c) 2015 ACSONE SA/NV () +# +# mail_attach_existing_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_existing_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_existing_attachment. +# If not, see . +# +############################################################################## + +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 diff --git a/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml b/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml new file mode 100644 index 00000000..aa10025b --- /dev/null +++ b/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml @@ -0,0 +1,19 @@ + + + + + mail.compose.message.form (mail_attach_existing_attachment) + mail.compose.message + + + + +
+
+ +
+
+
+
+
+
\ No newline at end of file