[IMP] mail_attach_existing_attachment: black, isort, prettier
This commit is contained in:
parent
a6e003e62f
commit
7b5df9ee22
@ -22,21 +22,14 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
{
|
{
|
||||||
'name': "Mail Attach Existing Attachment",
|
"name": "Mail Attach Existing Attachment",
|
||||||
'summary': "Adding attachment on the object by sending this one",
|
"summary": "Adding attachment on the object by sending this one",
|
||||||
'author': "ACSONE SA/NV, "
|
"author": "ACSONE SA/NV, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"Tecnativa, "
|
"website": "https://github.com/OCA/social",
|
||||||
"Odoo Community Association (OCA)",
|
"category": "Social Network",
|
||||||
'website': "https://github.com/OCA/social",
|
"version": "12.0.1.0.0",
|
||||||
'category': 'Social Network',
|
"license": "AGPL-3",
|
||||||
'version': '12.0.1.0.0',
|
"depends": ["mail", "document"],
|
||||||
'license': 'AGPL-3',
|
"data": ["wizard/mail_compose_message_view.xml"],
|
||||||
'depends': [
|
"installable": True,
|
||||||
'mail',
|
|
||||||
'document',
|
|
||||||
],
|
|
||||||
'data': [
|
|
||||||
'wizard/mail_compose_message_view.xml',
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1 @@
|
|||||||
|
|
||||||
from . import test_mail_attach_existing_attachment
|
from . import test_mail_attach_existing_attachment
|
||||||
|
@ -26,28 +26,34 @@ from odoo.tests import common
|
|||||||
|
|
||||||
|
|
||||||
class TestAttachExistingAttachment(common.TransactionCase):
|
class TestAttachExistingAttachment(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAttachExistingAttachment, self).setUp()
|
super(TestAttachExistingAttachment, self).setUp()
|
||||||
self.partner_obj = self.env['res.partner']
|
self.partner_obj = self.env["res.partner"]
|
||||||
self.partner_01 = self.env['res.partner'].create({
|
self.partner_01 = self.env["res.partner"].create(
|
||||||
'name': 'Partner 1',
|
{
|
||||||
'email': 'partner1@example.org',
|
"name": "Partner 1",
|
||||||
'is_company': True,
|
"email": "partner1@example.org",
|
||||||
'parent_id': False,
|
"is_company": True,
|
||||||
})
|
"parent_id": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_send_email_attachment(self):
|
def test_send_email_attachment(self):
|
||||||
attach1 = self.env['ir.attachment'].create({
|
attach1 = self.env["ir.attachment"].create(
|
||||||
'name': 'Attach1', 'datas_fname': 'Attach1',
|
{
|
||||||
'datas': 'bWlncmF0aW9uIHRlc3Q=',
|
"name": "Attach1",
|
||||||
'res_model': 'res.partner', 'res_id': self.partner_01.id})
|
"datas_fname": "Attach1",
|
||||||
vals = {'model': 'res.partner',
|
"datas": "bWlncmF0aW9uIHRlc3Q=",
|
||||||
'partner_ids': [(6, 0, [self.partner_01.id])],
|
"res_model": "res.partner",
|
||||||
'res_id': 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)
|
)
|
||||||
|
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])
|
values = mail.get_mail_values([self.partner_01.id])
|
||||||
self.assertTrue(attach1.id in
|
self.assertTrue(attach1.id in values[self.partner_01.id]["attachment_ids"])
|
||||||
values[self.partner_01.id]['attachment_ids'])
|
|
||||||
|
@ -22,32 +22,38 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from odoo import models, fields, api
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class MailComposeMessage(models.TransientModel):
|
class MailComposeMessage(models.TransientModel):
|
||||||
_inherit = 'mail.compose.message'
|
_inherit = "mail.compose.message"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(MailComposeMessage, self).default_get(fields_list)
|
res = super(MailComposeMessage, self).default_get(fields_list)
|
||||||
if res.get('res_id') and res.get('model') and \
|
if (
|
||||||
res.get('composition_mode', '') != 'mass_mail' and\
|
res.get("res_id")
|
||||||
not res.get('can_attach_attachment'):
|
and res.get("model")
|
||||||
res['can_attach_attachment'] = True # pragma: no cover
|
and res.get("composition_mode", "") != "mass_mail"
|
||||||
|
and not res.get("can_attach_attachment")
|
||||||
|
):
|
||||||
|
res["can_attach_attachment"] = True # pragma: no cover
|
||||||
return res
|
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(
|
object_attachment_ids = fields.Many2many(
|
||||||
comodel_name='ir.attachment',
|
comodel_name="ir.attachment",
|
||||||
relation='mail_compose_message_ir_attachments_object_rel',
|
relation="mail_compose_message_ir_attachments_object_rel",
|
||||||
column1='wizard_id', column2='attachment_id',
|
column1="wizard_id",
|
||||||
string='Object Attachments')
|
column2="attachment_id",
|
||||||
|
string="Object Attachments",
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def get_mail_values(self, res_ids):
|
def get_mail_values(self, res_ids):
|
||||||
res = super(MailComposeMessage, self).get_mail_values(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:
|
if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
|
||||||
res[res_ids[0]].setdefault('attachment_ids', []).extend(
|
res[res_ids[0]].setdefault("attachment_ids", []).extend(
|
||||||
self.object_attachment_ids.ids)
|
self.object_attachment_ids.ids
|
||||||
|
)
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user