def action_invite(self): """ Process the wizard content and proceed with sending the related email(s), rendering any template patterns on the fly if needed """ self.ensure_one() Partner = self.env['res.partner'] # compute partners and emails, try to find partners for given emails valid_partners = self.partner_ids valid_emails = [] for email in emails_split.split(self.emails or ''): partner = False email_normalized = tools.email_normalize(email) if email_normalized: limit = None if self.survey_users_login_required else 1 partner = Partner.search( [('email_normalized', '=', email_normalized)], limit=limit) if partner: valid_partners |= partner else: email_formatted = tools.email_split_and_format(email) if email_formatted: valid_emails.extend(email_formatted) if not valid_partners and not valid_emails: raise UserError(_("Please enter at least one valid recipient.")) answers = self._prepare_answers(valid_partners, valid_emails) for answer in answers: self._send_mail(answer) return {'type': 'ir.actions.act_window_close'}
def _message_get_suggested_recipients(self): recipients = super(MailCCMixin, self)._message_get_suggested_recipients() for record in self: if record.email_cc: for email in tools.email_split_and_format(record.email_cc): record._message_add_suggested_recipient( recipients, email=email, reason=_('CC Email')) return recipients
def send_get_mail_to(self, partner=None): """Forge the email_to with the following heuristic: - if 'partner', recipient specific (Partner Name <email>) - else fallback on mail.email_to splitting """ self.ensure_one() if partner: email_to = [formataddr((partner.name or 'False', partner.email or 'False'))] else: email_to = tools.email_split_and_format(self.email_to) return email_to
def _onchange_emails(self): if self.emails and (self.survey_users_login_required and not self.survey_id.users_can_signup): raise UserError( _('This survey does not allow external people to participate. You should create user accounts or update survey access mode accordingly.' )) if not self.emails: return valid, error = [], [] emails = list(set(emails_split.split(self.emails or ""))) for email in emails: email_check = tools.email_split_and_format(email) if not email_check: error.append(email) else: valid.extend(email_check) if error: raise UserError( _("Some emails you just entered are incorrect: %s") % (', '.join(error))) self.emails = '\n'.join(valid)
def _send_prepare_values(self, partner=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param Model partner: specific recipient partner """ self.ensure_one() body = self._send_prepare_body() body_alternative = tools.html2plaintext(body) if partner: email_to = [ tools.formataddr((partner.name or 'False', partner.email or 'False')) ] else: email_to = tools.email_split_and_format(self.email_to) res = { 'body': body, 'body_alternative': body_alternative, 'email_to': email_to, } return res