From: Christophe Simonis Date: Tue, 14 Oct 2014 12:36:45 +0000 (+0200) Subject: [MERGE] forward port of branch 7.0 up to 75d3ea6 X-Git-Tag: InsPy_8.0_01~4^2~9^2 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=db759948ffdda5f73eaa989a6b14f291b9a8f9b8;p=odoo%2Fodoo.git [MERGE] forward port of branch 7.0 up to 75d3ea6 --- db759948ffdda5f73eaa989a6b14f291b9a8f9b8 diff --cc addons/email_template/email_template.py index d8b0f61,c5e24b0..ed19efd --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@@ -425,67 -309,57 +425,68 @@@ class email_template(osv.osv) """ if context is None: context = {} + if fields is None: + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to'] + report_xml_pool = self.pool.get('ir.actions.report.xml') - template = self.get_email_template(cr, uid, template_id, res_id, context) - values = {} - for field in ['subject', 'body_html', 'email_from', - 'email_to', 'email_recipients', 'email_cc', 'reply_to']: - values[field] = self.render_template(cr, uid, getattr(template, field), - template.model, res_id, context=context) \ - or False - if template.user_signature: - signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature - if signature: - values['body_html'] = tools.append_content_to_html(values['body_html'], signature) - - if values['body_html']: - values['body'] = tools.html_sanitize(values['body_html']) - - values.update(mail_server_id=template.mail_server_id.id or False, - auto_delete=template.auto_delete, - model=template.model, - res_id=res_id or False) - - attachments = [] - # Add report in attachments - if template.report_template: - report_name = self.render_template(cr, uid, template.report_name, template.model, res_id, context=context) - report_service = 'report.' + report_xml_pool.browse(cr, uid, template.report_template.id, context).report_name - # Ensure report is rendered using template's language - ctx = context.copy() - if template.lang: - ctx['lang'] = self.render_template(cr, uid, template.lang, template.model, res_id, context) - service = netsvc.LocalService(report_service) - (result, format) = service.create(cr, uid, [res_id], {'model': template.model}, ctx) + res_ids_to_templates = self.get_email_template_batch(cr, uid, template_id, res_ids, context) + + # templates: res_id -> template; template -> res_ids + templates_to_res_ids = {} + for res_id, template in res_ids_to_templates.iteritems(): + templates_to_res_ids.setdefault(template, []).append(res_id) + + results = dict() + for template, template_res_ids in templates_to_res_ids.iteritems(): + # generate fields value for all res_ids linked to the current template + for field in fields: + generated_field_values = self.render_template_batch( + cr, uid, getattr(template, field), template.model, template_res_ids, + post_process=(field == 'body_html'), + context=context) + for res_id, field_value in generated_field_values.iteritems(): + results.setdefault(res_id, dict())[field] = field_value + # update values for all res_ids + for res_id in template_res_ids: + values = results[res_id] + if 'body_html' in fields and template.user_signature: + signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature - values['body_html'] = tools.append_content_to_html(values['body_html'], signature) ++ if signature: ++ values['body_html'] = tools.append_content_to_html(values['body_html'], signature) + if values.get('body_html'): + values['body'] = tools.html_sanitize(values['body_html']) + values.update( + mail_server_id=template.mail_server_id.id or False, + auto_delete=template.auto_delete, + model=template.model, + res_id=res_id or False, + attachment_ids=[attach.id for attach in template.attachment_ids], + ) + + # Add report in attachments: generate once for all template_res_ids + if template.report_template: + for res_id in template_res_ids: + attachments = [] + report_name = self.render_template(cr, uid, template.report_name, template.model, res_id, context=context) + report_service = report_xml_pool.browse(cr, uid, template.report_template.id, context).report_name + # Ensure report is rendered using template's language + ctx = context.copy() + if template.lang: + ctx['lang'] = self.render_template_batch(cr, uid, template.lang, template.model, [res_id], context)[res_id] # take 0 ? + result, format = openerp.report.render_report(cr, uid, [res_id], report_service, {'model': template.model}, ctx) # TODO in trunk, change return format to binary to match message_post expected format - result = base64.b64encode(result) - if not report_name: - report_name = report_service - ext = "." + format - if not report_name.endswith(ext): - report_name += ext - attachments.append((report_name, result)) - - attachment_ids = [] - # Add template attachments - for attach in template.attachment_ids: - attachment_ids.append(attach.id) - - values['attachments'] = attachments - values['attachment_ids'] = attachment_ids - return values - - def send_mail(self, cr, uid, template_id, res_id, force_send=False, context=None): + result = base64.b64encode(result) + if not report_name: + report_name = 'report.' + report_service + ext = "." + format + if not report_name.endswith(ext): + report_name += ext + attachments.append((report_name, result)) + results[res_id]['attachments'] = attachments + + return results + + def send_mail(self, cr, uid, template_id, res_id, force_send=False, raise_exception=False, context=None): """Generates a new mail message for the given template and record, and schedules it for delivery through the ``mail`` module's scheduler. diff --cc addons/web/static/src/js/view_form.js index e93375c,6a3fad2..d0951b6 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@@ -4449,12 -4258,17 +4454,11 @@@ instance.web.form.FieldMany2ManyTags = indexed[el[0]] = el; }); data = _.map(values, function(el) { return indexed[el]; }); - if (! self.get("effective_readonly")) { - self.tags.containerElement().children().remove(); - self.$('textarea').css("padding-left", "3px"); - self.tags.addTags(_.map(data, function(el) {return {name: el[1], id:el[0]};})); - } else { - self.$el.html(QWeb.render("FieldMany2ManyTag", {elements: data})); - } - }; + self.render_tag(data); + } if (! values || values.length > 0) { - this._display_orderer.add(self.get_render_data(values)).done(handle_names); - } - else{ - return this._display_orderer.add(dataset.name_get(values)).done(handle_names); ++ return this._display_orderer.add(self.get_render_data(values)).done(handle_names); + } else { handle_names([]); } },