1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# This file is part of mail_attach_existing_attachment,
7
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
9
# mail_attach_existing_attachment is free software:
10
# you can redistribute it and/or modify it under the terms of the GNU
11
# Affero General Public License as published by the Free Software
12
# Foundation,either version 3 of the License, or (at your option) any
15
# mail_attach_existing_attachment is distributed
16
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18
# PURPOSE. See the GNU Affero General Public License for more details.
20
# You should have received a copy of the GNU Affero General Public License
21
# along with mail_attach_existing_attachment.
22
# If not, see <http://www.gnu.org/licenses/>.
24
##############################################################################
26
from odoo import models, fields, api
29
class MailComposeMessage(models.TransientModel):
30
_inherit = 'mail.compose.message'
33
def default_get(self, fields_list):
34
res = super(MailComposeMessage, self).default_get(fields_list)
35
if res.get('res_id') and res.get('model') and \
36
res.get('composition_mode', '') != 'mass_mail' and\
37
not res.get('can_attach_attachment'):
38
res['can_attach_attachment'] = True # pragma: no cover
41
can_attach_attachment = fields.Boolean(string='Can Attach Attachment')
42
object_attachment_ids = fields.Many2many(
43
comodel_name='ir.attachment',
44
relation='mail_compose_message_ir_attachments_object_rel',
45
column1='wizard_id', column2='attachment_id', string='Attachments')
48
def get_mail_values(self, res_ids):
49
res = super(MailComposeMessage, self).get_mail_values(res_ids)
50
if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
51
res[res_ids[0]].setdefault('attachment_ids', []).extend(
52
self.object_attachment_ids.ids)