~opencrea/+junk/aprobio

« back to all changes in this revision

Viewing changes to mail_attach_existing_attachment/wizard/mail_compose_message.py

  • Committer: joannes
  • Date: 2017-05-17 09:40:42 UTC
  • Revision ID: joannes@debian-20170517094042-47q3j6on72w2h1il
community module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#     This file is part of mail_attach_existing_attachment,
 
5
#     an Odoo module.
 
6
#
 
7
#     Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
 
8
#
 
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
 
13
#     later version.
 
14
#
 
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.
 
19
#
 
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/>.
 
23
#
 
24
##############################################################################
 
25
 
 
26
from odoo import models, fields, api
 
27
 
 
28
 
 
29
class MailComposeMessage(models.TransientModel):
 
30
    _inherit = 'mail.compose.message'
 
31
 
 
32
    @api.model
 
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
 
39
        return res
 
40
 
 
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')
 
46
 
 
47
    @api.multi
 
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)
 
53
        return res