Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Email Marketing

Entity: mailing.contact

Compute Method: _compute_statistics

Inputs Method Outputs
  • id
""" Compute the mailing statistics for the mailing contact """
result = self.env["mailing.trace"].sudo()._read_group(
            [('model', '=', 'mailing.contact'), ('res_id', 'in', self.ids)],
            ['res_id', 'trace_status'],
            ['__count'])
result_per_contact = defaultdict(lambda: defaultdict(int))
for res_id, trace_status, count in result:
            result_per_contact[res_id][trace_status] = count
for contact in self:
            line = result_per_contact[contact.id]
            expected = sum(line.values())
            delivered = line['sent'] + line['open'] + line['reply']
            opened = line['open'] + line['reply']
            failed = line['error'] + line['bounce']
            total = (expected - line['cancel']) or 1
            total_no_error = (expected - line['cancel'] - failed) or 1
            contact.mailing_count = delivered
            contact.received_ratio = float_round(100.0 * delivered / total, precision_digits=2)
            contact.opened_ratio = float_round(100.0 * opened / total_no_error, precision_digits=2)
            contact.replied_ratio = float_round(100.0 * line['reply'] / total_no_error, precision_digits=2)

Back to entity