From 8ae3b158dba4ead28e8f510e7a776a2c98877dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 17 Sep 2013 12:35:55 +0200 Subject: [PATCH] [IMP] cleaning before merging : - added fields on mail.mail.statistics form view to have all data; - added comments; - cleaned get_mail_values override now that statistics are created using o2m command bzr revid: tde@openerp.com-20130917103555-jwhgl8y49g505ugz --- addons/mass_mailing/mail_thread.py | 6 +++++ addons/mass_mailing/mass_mailing.py | 26 ++++++++++++------- addons/mass_mailing/mass_mailing_view.xml | 21 ++++++++++----- .../wizard/mail_compose_message.py | 12 ++++++--- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/addons/mass_mailing/mail_thread.py b/addons/mass_mailing/mail_thread.py index 5c759e71e23..0570596ba12 100644 --- a/addons/mass_mailing/mail_thread.py +++ b/addons/mass_mailing/mail_thread.py @@ -36,6 +36,9 @@ class MailThread(osv.Model): _inherit = ['mail.thread'] def message_route_check_bounce(self, cr, uid, message, context=None): + """ Override to verify that the email_to is the bounce alias. If it is the + case, log the bounce, set the parent and related document as bounced and + return False to end the routing process. """ bounce_alias = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.bounce.alias", context=context) message_id = message.get('Message-Id') email_from = decode_header(message, 'From') @@ -74,6 +77,9 @@ class MailThread(osv.Model): self.write(cr, uid, [obj.id], {'message_bounce': obj.message_bounce + 1}, context=context) def message_route_process(self, cr, uid, message, message_dict, routes, context=None): + """ Override to update the parent mail statistics. The parent is found + by using the References header of the incoming message and looking for + matching message_id in mail.mail.statistics. """ if message.get('References'): message_ids = [x.strip() for x in decode(message['References']).split()] self.pool['mail.mail.statistics'].set_replied(cr, uid, mail_message_ids=message_ids, context=context) diff --git a/addons/mass_mailing/mass_mailing.py b/addons/mass_mailing/mass_mailing.py index 4ef7e260055..49ee106bc69 100644 --- a/addons/mass_mailing/mass_mailing.py +++ b/addons/mass_mailing/mass_mailing.py @@ -32,6 +32,8 @@ class MassMailingCampaign(osv.Model): """ _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 """ @@ -48,10 +50,12 @@ class MassMailingCampaign(osv.Model): return results def _get_mass_mailing_kanban_ids(self, cr, uid, ids, name, arg, context=None): + """ Gather data about mass mailings to display them in kanban view as + nested kanban views is not possible currently. """ results = dict.fromkeys(ids, '') for campaign in self.browse(cr, uid, ids, context=context): mass_mailing_results = [] - for mass_mailing in campaign.mass_mailing_ids: + for mass_mailing in campaign.mass_mailing_ids[:self._kanban_mailing_nbr]: mass_mailing_object = {} for attr in ['name', 'sent', 'delivered', 'opened', 'replied', 'bounced']: mass_mailing_object[attr] = getattr(mass_mailing, attr) @@ -74,7 +78,9 @@ class MassMailingCampaign(osv.Model): 'mass_mailing_kanban_ids': fields.function( _get_mass_mailing_kanban_ids, type='text', string='Mass Mailings (kanban data)', - help='This field has for purpose to gather data about mass mailings to display them in kanban view as nested kanban views is not possible currently', + help='This field has for purpose to gather data about mass mailings ' + 'to display them in kanban view as nested kanban views is not ' + 'possible currently', ), 'statistics_ids': fields.one2many( 'mail.mail.statistics', 'mass_mailing_campaign_id', @@ -139,6 +145,7 @@ class MassMailing(osv.Model): _description = 'Wave of sending emails' # number of periods for tracking mail_mail statistics _period_number = 6 + _order = 'date DESC' def __get_bar_values(self, cr, uid, id, obj, domain, read_fields, value_field, groupby_field, context=None): """ Generic method to generate data for bar chart values using SparklineBarWidget. @@ -167,9 +174,10 @@ class MassMailing(osv.Model): section_result[timedelta.days] = {'value': group.get(value_field, 0), 'tooltip': group.get(groupby_field)} return section_result - def _get_monthly_statistics(self, cr, uid, ids, field_name, arg, context=None): - """ TODO - """ + def _get_daily_statistics(self, cr, uid, ids, field_name, arg, context=None): + """ Get the daily statistics of the mass mailing. This is done by a grouping + on opened and replied fields. Using custom format in context, we obtain + results for the next 6 days following the mass mailing date. """ obj = self.pool['mail.mail.statistics'] res = {} context['datetime_format'] = { @@ -254,14 +262,14 @@ class MassMailing(osv.Model): ), # monthly ratio 'opened_monthly': fields.function( - _get_monthly_statistics, + _get_daily_statistics, string='Opened', - type='char', multi='_get_monthly_statistics', + type='char', multi='_get_daily_statistics', ), 'replied_monthly': fields.function( - _get_monthly_statistics, + _get_daily_statistics, string='Replied', - type='char', multi='_get_monthly_statistics', + type='char', multi='_get_daily_statistics', ), } diff --git a/addons/mass_mailing/mass_mailing_view.xml b/addons/mass_mailing/mass_mailing_view.xml index 680dfe87092..f0c27f42a4a 100644 --- a/addons/mass_mailing/mass_mailing_view.xml +++ b/addons/mass_mailing/mass_mailing_view.xml @@ -328,13 +328,20 @@
- - - - - - - + + + + + + + + + + + + + +
diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index 8e075eb48c6..e5276eb7fd5 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -38,8 +38,9 @@ class MailComposeMessage(osv.TransientModel): } def get_mail_values(self, cr, uid, wizard, res_ids, context=None): - """ Override method that generated the mail content by adding the mass - mailing campaign, when doing pure email mass mailing. """ + """ Override method that generated the mail content by creating the + mail.mail.statistics values in the o2m of mail_mail, when doing pure + email mass mailing. """ res = super(MailComposeMessage, self).get_mail_values(cr, uid, wizard, res_ids, context=context) if wizard.composition_mode == 'mass_mail' and wizard.mass_mailing_campaign_id: # TODO: which kind of mass mailing ? current_date = fields.datetime.now() @@ -51,7 +52,10 @@ class MailComposeMessage(osv.TransientModel): 'domain': wizard.active_domain, 'template_id': wizard.template_id and wizard.template_id.id or False, }, context=context) - context['default_mass_mailing_id'] = mass_mailing_id for res_id in res_ids: - res[res_id]['statistics_ids'] = [(0, 0, {'model': wizard.model, 'res_id': res_id})] + res[res_id]['statistics_ids'] = [(0, 0, { + 'model': wizard.model, + 'res_id': res_id, + 'mass_mailing_id': mass_mailing_id, + })] return res