From 8178669795e987c9b3df7eec7712f2f6cd1fba47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 8 Apr 2014 14:40:53 +0200 Subject: [PATCH] [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 --- addons/mail/mail_mail.py | 4 ++-- addons/mass_mailing/models/email_template.py | 2 ++ addons/mass_mailing/models/mass_mailing.py | 20 ++++++++++++------- addons/mass_mailing/views/email_template.xml | 3 +++ addons/mass_mailing/views/mass_mailing.xml | 16 +++++++-------- addons/mass_mailing/wizard/test_mailing.py | 1 + addons/portal_sale/portal_sale.py | 2 +- addons/purchase/purchase.py | 2 +- addons/website_mail/models/email_template.py | 2 +- .../views/email_template_view.xml | 2 +- 10 files changed, 33 insertions(+), 21 deletions(-) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 64efb181045..12903d02236 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -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 diff --git a/addons/mass_mailing/models/email_template.py b/addons/mass_mailing/models/email_template.py index db5782c3234..0403c857528 100644 --- a/addons/mass_mailing/models/email_template.py +++ b/addons/mass_mailing/models/email_template.py @@ -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'] diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py index 375f2e1162d..f7c6a1d5127 100644 --- a/addons/mass_mailing/models/mass_mailing.py +++ b/addons/mass_mailing/models/mass_mailing.py @@ -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 diff --git a/addons/mass_mailing/views/email_template.xml b/addons/mass_mailing/views/email_template.xml index cb1a6b2d514..438852609bb 100644 --- a/addons/mass_mailing/views/email_template.xml +++ b/addons/mass_mailing/views/email_template.xml @@ -36,6 +36,9 @@