[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
This commit is contained in:
parent
2bc275457a
commit
8ae3b158db
|
@ -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)
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -328,13 +328,20 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Mail Statistics" version="7.0">
|
||||
<group>
|
||||
<field name="mail_mail_id"/>
|
||||
<field name="message_id"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
<field name="model"/>
|
||||
<field name="res_id"/>
|
||||
<group>
|
||||
<field name="mail_mail_id"/>
|
||||
<field name="message_id"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="mass_mailing_id"/>
|
||||
<field name="mass_mailing_campaign_id"/>
|
||||
<field name="template_id"/>
|
||||
<field name="model"/>
|
||||
<field name="res_id"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue