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.

45 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models, _
  5. from odoo.exceptions import UserError
  6. class MailComposeMessage(models.TransientModel):
  7. _inherit = 'mail.compose.message'
  8. # The number of partner is needed to hide the 'print' button if
  9. # there is more than one partner
  10. partner_count = fields.Integer(
  11. string='Number of partners',
  12. compute='_compute_partner_count')
  13. @api.depends('partner_ids')
  14. def _compute_partner_count(self):
  15. for rec in self:
  16. rec.partner_count = len(rec.partner_ids)
  17. @api.multi
  18. def download_pdf(self):
  19. '''
  20. Download the email in pdf format, based on a QWeb report.
  21. '''
  22. self.ensure_one()
  23. if self.partner_count != 1:
  24. raise UserError(_("There must be only one recipient."))
  25. ctx = self.env.context.copy()
  26. ctx.update({'active_id': self.id,
  27. 'active_ids': [self.id],
  28. 'active_model': 'mail.compose.message'})
  29. return {
  30. 'name': 'mail_as_letter',
  31. 'model': 'mail.compose.message',
  32. 'res_id': self.id,
  33. 'type': 'ir.actions.report.xml',
  34. 'report_name':
  35. 'mail_as_letter.report_mail_print',
  36. 'report_type': 'qweb-pdf',
  37. 'context': ctx, }