From: Christophe Simonis Date: Sun, 1 Jun 2014 08:56:39 +0000 (+0200) Subject: [MERGE] forward port of branch saas-3 up to revid faace84 X-Git-Tag: InsPy_8.0_01~90^2~21^2~23 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=36f9af78aa2f56ddba85fe22e812938c253d3f94;p=odoo%2Fodoo.git [MERGE] forward port of branch saas-3 up to revid faace84 --- 36f9af78aa2f56ddba85fe22e812938c253d3f94 diff --cc addons/email_template/email_template.py index 7321d9d,3f202ff..51ebf96 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@@ -391,37 -386,6 +391,37 @@@ class email_template(osv.osv) }) return {'value': result} + def generate_recipients_batch(self, cr, uid, results, template_id, res_ids, context=None): + """Generates the recipients of the template. Default values can ben generated + instead of the template values if requested by template or context. + Emails (email_to, email_cc) can be transformed into partners if requested + in the context. """ + if context is None: + context = {} + template = self.browse(cr, uid, template_id, context=context) + + if template.use_default_to or context.get('tpl_force_default_to'): + ctx = dict(context, thread_model=template.model) + default_recipients = self.pool['mail.thread'].message_get_default_recipients(cr, uid, res_ids, context=ctx) + for res_id, recipients in default_recipients.iteritems(): + results[res_id].pop('partner_to', None) + results[res_id].update(recipients) + + for res_id, values in results.iteritems(): + partner_ids = values.get('partner_ids', list()) + if context and context.get('tpl_partners_only'): + mails = tools.email_split(values.pop('email_to', '')) + tools.email_split(values.pop('email_cc', '')) + for mail in mails: + partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context) + partner_ids.append(partner_id) + partner_to = values.pop('partner_to', '') + if partner_to: + # placeholders could generate '', 3, 2 due to some empty field values - tpl_partner_ids = [pid for pid in partner_to.split(',') if pid] ++ tpl_partner_ids = [int(pid) for pid in partner_to.split(',') if pid] + partner_ids += self.pool['res.partner'].exists(cr, SUPERUSER_ID, tpl_partner_ids, context=context) + results[res_id]['partner_ids'] = partner_ids + return results + def generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): """Generates an email from the template for given the given model based on records given by res_ids.