2015-08-17 10:44:04 +02:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# This file is part of mail_attach_existing_attachment,
|
|
|
|
# an Odoo module.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2020-08-24 15:42:33 +02:00
|
|
|
from odoo import api, fields, models
|
2015-08-17 10:44:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MailComposeMessage(models.TransientModel):
|
2020-08-24 15:42:33 +02:00
|
|
|
_inherit = "mail.compose.message"
|
2015-08-17 10:44:04 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def default_get(self, fields_list):
|
|
|
|
res = super(MailComposeMessage, self).default_get(fields_list)
|
2020-08-24 15:42:33 +02:00
|
|
|
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
|
2015-08-17 10:44:04 +02:00
|
|
|
return res
|
|
|
|
|
2020-08-24 15:42:33 +02:00
|
|
|
can_attach_attachment = fields.Boolean(string="Can Attach Attachment")
|
2015-08-17 10:44:04 +02:00
|
|
|
object_attachment_ids = fields.Many2many(
|
2020-08-24 15:42:33 +02:00
|
|
|
comodel_name="ir.attachment",
|
|
|
|
relation="mail_compose_message_ir_attachments_object_rel",
|
|
|
|
column1="wizard_id",
|
|
|
|
column2="attachment_id",
|
|
|
|
string="Object Attachments",
|
|
|
|
)
|
2015-08-17 10:44:04 +02:00
|
|
|
|
2016-06-13 01:54:13 +02:00
|
|
|
@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:
|
2020-08-24 15:42:33 +02:00
|
|
|
res[res_ids[0]].setdefault("attachment_ids", []).extend(
|
|
|
|
self.object_attachment_ids.ids
|
|
|
|
)
|
2015-08-17 10:44:04 +02:00
|
|
|
return res
|