[IMP] mail_attach_existing_attachment: black, isort, prettier

This commit is contained in:
Radovan Skolnik 2020-08-24 15:42:33 +02:00 committed by Alvaro
parent a6e003e62f
commit 7b5df9ee22
4 changed files with 55 additions and 51 deletions

View File

@ -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,
}

View File

@ -1,2 +1 @@
from . import test_mail_attach_existing_attachment

View File

@ -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"])

View File

@ -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