* [8.0][mass_mailing] some fixes

* [FIX] rename wrong mailing_type field and add missing fields when creating a mass mailing from the composer
* [FIX] coerce tooltip to an unicode string to avoid a json crash when locale produces a non unicode string for strftime(%B)
* [FIX] repair wrong sql statement computing statistics
This commit is contained in:
Olivier LAURENT 2014-08-21 11:07:00 +02:00
parent bb30c858b3
commit ac9954d210
2 changed files with 12 additions and 6 deletions

View File

@ -9,6 +9,7 @@ from openerp import tools
from openerp.exceptions import Warning
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _
from openerp.tools import ustr
from openerp.osv import osv, fields
@ -271,7 +272,7 @@ class MassMailing(osv.Model):
"""
date_begin = date_begin.date()
section_result = [{'value': 0,
'tooltip': (date_begin + relativedelta.relativedelta(days=i)).strftime('%d %B %Y'),
'tooltip': ustr((date_begin + relativedelta.relativedelta(days=i)).strftime('%d %B %Y')),
} for i in range(0, self._period_number)]
group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context)
field_col_info = obj._all_columns.get(groupby_field.split(':')[0])
@ -302,7 +303,7 @@ class MassMailing(osv.Model):
return res
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
""" Compute statistics of the mass mailing campaign """
""" Compute statistics of the mass mailing """
results = {}
cr.execute("""
SELECT
@ -311,9 +312,9 @@ class MassMailing(osv.Model):
COUNT(CASE WHEN s.sent is not null THEN 1 ELSE null END) AS sent,
COUNT(CASE WHEN s.scheduled is not null AND s.sent is null AND s.exception is null THEN 1 ELSE null END) AS scheduled,
COUNT(CASE WHEN s.scheduled is not null AND s.sent is null AND s.exception is not null THEN 1 ELSE null END) AS failed,
COUNT(CASE WHEN s.id is not null AND s.bounced is null THEN 1 ELSE null END) AS delivered,
COUNT(CASE WHEN s.sent is not null AND s.bounced is null THEN 1 ELSE null END) AS delivered,
COUNT(CASE WHEN s.opened is not null THEN 1 ELSE null END) AS opened,
COUNT(CASE WHEN s.replied is not null THEN 1 ELSE null END) AS replied ,
COUNT(CASE WHEN s.replied is not null THEN 1 ELSE null END) AS replied,
COUNT(CASE WHEN s.bounced is not null THEN 1 ELSE null END) AS bounced
FROM
mail_mail_statistics s
@ -328,7 +329,6 @@ class MassMailing(osv.Model):
for row in cr.dictfetchall():
results[row.pop('mailing_id')] = row
total = row['total'] or 1
row['delivered'] = row['sent'] - row['bounced']
row['received_ratio'] = 100.0 * row['delivered'] / total
row['opened_ratio'] = 100.0 * row['opened'] / total
row['replied_ratio'] = 100.0 * row['replied'] / total

View File

@ -32,13 +32,19 @@ class MailComposeMessage(osv.TransientModel):
wizard.model in [item[0] for item in self.pool['mail.mass_mailing']._get_mailing_model(cr, uid, context=context)]:
mass_mailing = wizard.mass_mailing_id
if not mass_mailing:
reply_to_mode = wizard.no_auto_thread and 'email' or 'thread'
reply_to = wizard.no_auto_thread and wizard.reply_to or False
mass_mailing_id = self.pool['mail.mass_mailing'].create(
cr, uid, {
'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id and wizard.mass_mailing_campaign_id.id or False,
'name': wizard.mass_mailing_name,
'template_id': wizard.template_id and wizard.template_id.id or False,
'state': 'done',
'mailing_type': wizard.model,
'reply_to_mode': reply_to_mode,
'reply_to': reply_to,
'sent_date': fields.datetime.now(),
'body_html': wizard.body,
'mailing_model': wizard.model,
'mailing_domain': wizard.active_domain,
}, context=context)
mass_mailing = self.pool['mail.mass_mailing'].browse(cr, uid, mass_mailing_id, context=context)