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.

52 lines
2.2 KiB

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