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.

57 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This file is part of mail_attach_attachment,
  5. # an Odoo module.
  6. #
  7. # Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
  8. #
  9. # mail_attach_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_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_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
  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.model
  42. def get_mail_values(self, wizard, res_ids):
  43. res = super(MailComposeMessage, self).get_mail_values(wizard, res_ids)
  44. if wizard.object_attachment_ids.ids and wizard.model and\
  45. len(res_ids) == 1:
  46. for res_id in res_ids:
  47. if not res[res_id].get('attachment_ids'):
  48. res[res_id]['attachment_ids'] = []
  49. res[res_id]['attachment_ids'].extend(
  50. wizard.object_attachment_ids.ids)
  51. return res