You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.2 KiB

  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. from openerp import models, fields, api
  26. class MailComposeMessage(models.TransientModel):
  27. _inherit = 'mail.compose.message'
  28. @api.model
  29. def default_get(self, fields_list):
  30. res = super(MailComposeMessage, self).default_get(fields_list)
  31. if res.get('res_id') and res.get('model') and \
  32. res.get('composition_mode', '') != 'mass_mail' and\
  33. not res.get('can_attach_attachment'):
  34. res['can_attach_attachment'] = True # pragma: no cover
  35. return res
  36. can_attach_attachment = fields.Boolean(string='Can Attach Attachment')
  37. object_attachment_ids = fields.Many2many(
  38. comodel_name='ir.attachment',
  39. relation='mail_compose_message_ir_attachments_object_rel',
  40. column1='wizard_id', column2='attachment_id', string='Attachments')
  41. @api.multi
  42. def get_mail_values(self, res_ids):
  43. res = super(MailComposeMessage, self).get_mail_values(res_ids)
  44. if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
  45. res[res_ids[0]].setdefault('attachment_ids', []).extend(
  46. self.object_attachment_ids.ids)
  47. return res