diff --git a/mail_attach_existing_attachment/__manifest__.py b/mail_attach_existing_attachment/__manifest__.py index c907555..ef31957 100644 --- a/mail_attach_existing_attachment/__manifest__.py +++ b/mail_attach_existing_attachment/__manifest__.py @@ -22,21 +22,14 @@ # ############################################################################## { - 'name': "Mail Attach Existing Attachment", - 'summary': "Adding attachment on the object by sending this one", - 'author': "ACSONE SA/NV, " - "Tecnativa, " - "Odoo Community Association (OCA)", - 'website': "https://github.com/OCA/social", - 'category': 'Social Network', - 'version': '12.0.1.0.0', - 'license': 'AGPL-3', - 'depends': [ - 'mail', - 'document', - ], - 'data': [ - 'wizard/mail_compose_message_view.xml', - ], - 'installable': True, + "name": "Mail Attach Existing Attachment", + "summary": "Adding attachment on the object by sending this one", + "author": "ACSONE SA/NV, " "Tecnativa, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "category": "Social Network", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "depends": ["mail", "document"], + "data": ["wizard/mail_compose_message_view.xml"], + "installable": True, } diff --git a/mail_attach_existing_attachment/tests/__init__.py b/mail_attach_existing_attachment/tests/__init__.py index fc1e8e4..01f264c 100644 --- a/mail_attach_existing_attachment/tests/__init__.py +++ b/mail_attach_existing_attachment/tests/__init__.py @@ -1,2 +1 @@ - 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 index a6730e7..43d59b3 100644 --- a/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py +++ b/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py @@ -26,28 +26,34 @@ from odoo.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['res.partner'].create({ - 'name': 'Partner 1', - 'email': 'partner1@example.org', - 'is_company': True, - 'parent_id': False, - }) + self.partner_obj = self.env["res.partner"] + self.partner_01 = self.env["res.partner"].create( + { + "name": "Partner 1", + "email": "partner1@example.org", + "is_company": True, + "parent_id": False, + } + ) 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) + 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([self.partner_01.id]) - self.assertTrue(attach1.id in - values[self.partner_01.id]['attachment_ids']) + self.assertTrue(attach1.id in values[self.partner_01.id]["attachment_ids"]) diff --git a/mail_attach_existing_attachment/wizard/mail_compose_message.py b/mail_attach_existing_attachment/wizard/mail_compose_message.py index 5b4b32e..d42d9d5 100644 --- a/mail_attach_existing_attachment/wizard/mail_compose_message.py +++ b/mail_attach_existing_attachment/wizard/mail_compose_message.py @@ -22,32 +22,38 @@ # ############################################################################## -from odoo import models, fields, api +from odoo import api, fields, models class MailComposeMessage(models.TransientModel): - _inherit = 'mail.compose.message' + _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 # pragma: no cover + 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 # pragma: no cover return res - can_attach_attachment = fields.Boolean(string='Can Attach Attachment') + 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='Object Attachments') + comodel_name="ir.attachment", + relation="mail_compose_message_ir_attachments_object_rel", + column1="wizard_id", + column2="attachment_id", + string="Object Attachments", + ) @api.multi def get_mail_values(self, res_ids): res = super(MailComposeMessage, self).get_mail_values(res_ids) if self.object_attachment_ids.ids and self.model and len(res_ids) == 1: - res[res_ids[0]].setdefault('attachment_ids', []).extend( - self.object_attachment_ids.ids) + res[res_ids[0]].setdefault("attachment_ids", []).extend( + self.object_attachment_ids.ids + ) return res