[FIX] mail, mass_mailing

- mail: now trigger postprocess_sent_message in every case, being sent or not, as the state
is propagated in the method; udpated all addons accordingly;
- email_template: fixed URL to edit it in website + form view;
- mass_mailing: barchart now send jsonified value;
- mass_mailing: tweaking the form view with all options

bzr revid: tde@openerp.com-20140408124053-o9tb14k6v47s5mjd
This commit is contained in:
Thibault Delavallée 2014-04-08 14:40:53 +02:00
parent cbfc26fe77
commit 8178669795
10 changed files with 33 additions and 21 deletions

View File

@ -288,11 +288,11 @@ class mail_mail(osv.Model):
# /!\ can't use mail.state here, as mail.refresh() will cause an error
# see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1
if mail_sent:
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=mail_sent)
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=mail_sent)
except Exception as e:
_logger.exception('failed sending mail.mail %s', mail.id)
mail.write({'state': 'exception'})
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=False)
if raise_exception:
if isinstance(e, AssertionError):
# get the args of the original error, wrap into a value and throw a MailDeliveryException

View File

@ -32,5 +32,7 @@ class EmailTemplate(osv.Model):
class email_template_preview(osv.TransientModel):
""" Reinitialize email template preview model to have access to all email.template
new fields. """
_name = "email_template.preview"
_inherit = ['email.template', 'email_template.preview']

View File

@ -22,6 +22,10 @@
from datetime import datetime
from dateutil import relativedelta
import random
try:
import simplejson as json
except ImportError:
import json
import urllib
import urlparse
@ -230,20 +234,18 @@ class MassMailingCampaign(osv.Model):
"""Model of mass mailing campaigns. """
_name = "mail.mass_mailing.campaign"
_description = 'Mass Mailing Campaign'
# number of embedded mailings in kanban view
_kanban_mailing_nbr = 4
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
""" Compute statistics of the mass mailing campaign """
Statistics = self.pool['mail.mail.statistics']
results = dict.fromkeys(ids, False)
for cid in ids:
stat_ids = Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid)], context=context),
stat_ids = Statistics.search(cr, uid, [('mass_mailing_campaign_id', '=', cid)], context=context)
stats = Statistics.browse(cr, uid, stat_ids, context=context)
results[cid] = {
'total': len(stats),
'failed': len([s for s in stats if not s.scheduled is False and s.sent is False and not s.exception is False]),
'scheduled': len([s for s in stats if not s.scheduled is False and s.sent is False]),
'scheduled': len([s for s in stats if not s.scheduled is False and s.sent is False and s.exception is False]),
'sent': len([s for s in stats if not s.sent is False]),
'opened': len([s for s in stats if not s.opened is False]),
'replied': len([s for s in stats if not s.replied is False]),
@ -416,9 +418,9 @@ class MassMailing(osv.Model):
date_begin_str = date_begin.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
date_end_str = date_end.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
domain = [('mass_mailing_id', '=', id), ('opened', '>=', date_begin_str), ('opened', '<=', date_end_str)]
res[id]['opened_dayly'] = self.__get_bar_values(cr, uid, id, obj, domain, ['opened'], 'opened_count', 'opened:day', context=context)
res[id]['opened_dayly'] = json.dumps(self.__get_bar_values(cr, uid, id, obj, domain, ['opened'], 'opened_count', 'opened:day', context=context))
domain = [('mass_mailing_id', '=', id), ('replied', '>=', date_begin_str), ('replied', '<=', date_end_str)]
res[id]['replied_dayly'] = self.__get_bar_values(cr, uid, id, obj, domain, ['replied'], 'replied_count', 'replied:day', context=context)
res[id]['replied_dayly'] = json.dumps(self.__get_bar_values(cr, uid, id, obj, domain, ['replied'], 'replied_count', 'replied:day', context=context))
return res
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
@ -431,7 +433,7 @@ class MassMailing(osv.Model):
results[mid] = {
'total': len(stats),
'failed': len([s for s in stats if not s.scheduled is False and s.sent is False and not s.exception is False]),
'scheduled': len([s for s in stats if not s.scheduled is False and s.sent is False]),
'scheduled': len([s for s in stats if not s.scheduled is False and s.sent is False and s.exception is False]),
'sent': len([s for s in stats if not s.sent is False]),
'opened': len([s for s in stats if not s.opened is False]),
'replied': len([s for s in stats if not s.replied is False]),
@ -699,6 +701,9 @@ class MassMailing(osv.Model):
values['body_html'] = False
return {'value': values}
def on_change_contact_ab_pc(self, cr, uid, ids, contact_ab_pc, contact_nbr, context=None):
return {'value': {'contact_ab_nbr': contact_nbr * contact_ab_pc / 100.0}}
def action_duplicate(self, cr, uid, ids, context=None):
copy_id = None
for mid in ids:
@ -837,6 +842,7 @@ class MassMailing(osv.Model):
composer_values['reply_to'] = mailing.reply_to
composer_id = self.pool['mail.compose.message'].create(cr, uid, composer_values, context=comp_ctx)
self.pool['mail.compose.message'].send_mail(cr, uid, [composer_id], context=comp_ctx)
self.write(cr, uid, [mailing.id], {'date': fields.datetime.now(), 'state': 'done'}, context=context)
return True

View File

@ -36,6 +36,9 @@
<button name="%(email_template.wizard_email_template_preview)d" string="Preview"
type="action" target="new"
context="{'template_id':active_id}"/>
<br />
<field name="website_link" widget='html' radonly='1'
style='margin: 0px; padding: 0px;'/>
</div>
</group>
</group>

View File

@ -228,7 +228,6 @@
<field name="name"/>
</group>
<group>
<field name="total" invisible="1"/>
<div class="oe_right oe_button_box" name="buttons">
<div>
<button name="action_see_recipients" type="object"
@ -301,14 +300,13 @@
<span style="margin-left: 8px; margin-right: 8px">or</span>
<button string='Create a New List' class="oe_link" type='object' name='action_new_list'/><br />
<!-- <label for="contact_nbr" string="Total" style="display: inline-block; min-width: 90px;"/> -->
<!-- <field name="contact_nbr" nolabel="1" class="oe_inline" readonly="True"/> recipients -->
<!-- <button name="action_see_recipients" type="object" string="See Recipients" class="oe_inline oe_link" style='margin-left: 8px;'/><br /> -->
<div groups="mass_mailing.group_mass_mailing_campaign" style="display: inline;">
<field name="ab_testing" invisible="1"/>
<label for="contact_ab_pc" string="AB Testing"/>
<field name="contact_ab_pc" class="oe_inline"/>%, <field name="contact_ab_nbr" class="oe_inline"/> contacts to mail
<label for="contact_ab_pc" string="AB Testing" style="display: inline-block; min-width: 90px;"/>
Email <field name="contact_ab_pc" class="oe_inline"
on_change="on_change_contact_ab_pc(contact_ab_pc, contact_nbr, context)"/>
<strong>%</strong> of recipients
(<field name="contact_ab_nbr" class="oe_inline"/> recipients)
<div attrs="{'invisible': [('ab_testing', '=', False)]}" style="display: inline;">
<span>(</span>
<field name="contact_ab_done" class="oe_inline"
@ -318,7 +316,8 @@
</div>
</div>
<field name="date" readonly="True" groups="mass_mailing.group_mass_mailing_campaign"/>
<field name="date" readonly="True" groups="mass_mailing.group_mass_mailing_campaign"
attrs="{'invisible': [('state', '!=', 'done')]}"/>
<field name="mass_mailing_campaign_id" groups="mass_mailing.group_mass_mailing_campaign"/>
<label for="body_html" string="Email"/>
<div>
@ -665,6 +664,7 @@
<group>
<field name="mail_mail_id"/>
<field name="message_id"/>
<field name="exception"/>
<field name="sent"/>
<field name="opened"/>
<field name="replied"/>

View File

@ -39,4 +39,5 @@ class TestMassMailing(osv.TransientModel):
}
mail_ids.append(Mail.create(cr, uid, mail_values, context=context))
Mail.send(cr, uid, mail_ids, context=context)
self.pool['mail.mass_mailing'].write(cr, uid, [mailing.id], {'state': 'test'}, context=context)
return True

View File

@ -127,7 +127,7 @@ class mail_mail(osv.osv):
_inherit = 'mail.mail'
def _postprocess_sent_message(self, cr, uid, mail, context=None, mail_sent=True):
if mail.model == 'sale.order':
if mail_sent and mail.model == 'sale.order':
so_obj = self.pool.get('sale.order')
order = so_obj.browse(cr, uid, mail.res_id, context=context)
partner = order.partner_id

View File

@ -1249,7 +1249,7 @@ class mail_mail(osv.Model):
_inherit = 'mail.mail'
def _postprocess_sent_message(self, cr, uid, mail, context=None, mail_sent=True):
if mail.model == 'purchase.order':
if mail_sent and mail.model == 'purchase.order':
self.pool.get('purchase.order').signal_send_rfq(cr, uid, [mail.res_id])
return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context, mail_sent=mail_sent)

View File

@ -27,7 +27,7 @@ class EmailTemplate(osv.Model):
_inherit = 'email.template'
def _get_website_link(self, cr, uid, ids, name, args, context=None):
return dict((id, _('<a href="website_mail/email_designer/%s">Open with visual editor</a>') % id) for id in ids)
return dict((id, _('<a href="website_mail/email_designer?model=email.template&res_id=%d">Open with visual editor</a>') % id) for id in ids)
_columns = {
'website_link': fields.function(

View File

@ -6,7 +6,7 @@
<field name="model">email.template</field>
<field name="inherit_id" ref="email_template.email_template_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='model']" position="before">
<xpath expr="//h1" position="after">
<br />
<field name="website_link" widget='html' radonly='1'
style='margin: 0px; padding: 0px;'/>