[FIX] mass_mailing_partner: compute fields performance (#271)
- In DB which use large amounts of records and intesive use of mass_mailings, not optimized compute records lead to a drastical decrease of performance
This commit is contained in:
parent
eaa4cad627
commit
a11a597edd
@ -1,13 +1,12 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
# Copyright 2015-2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||||
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Link partners with mass-mailing",
|
"name": "Link partners with mass-mailing",
|
||||||
"version": "10.0.1.0.2",
|
"version": "10.0.1.0.3",
|
||||||
"author": "Tecnativa, "
|
"author": "Tecnativa, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"website": "https://www.tecnativa.com",
|
"website": "https://www.tecnativa.com",
|
||||||
|
@ -36,17 +36,29 @@ class ResPartner(models.Model):
|
|||||||
_("This partner '%s' is subscribed to one or more "
|
_("This partner '%s' is subscribed to one or more "
|
||||||
"mailing lists. Email must be assigned.") % partner.name)
|
"mailing lists. Email must be assigned.") % partner.name)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
@api.depends('mass_mailing_contact_ids',
|
@api.depends('mass_mailing_contact_ids',
|
||||||
'mass_mailing_contact_ids.opt_out')
|
'mass_mailing_contact_ids.opt_out')
|
||||||
def _compute_mass_mailing_contacts_count(self):
|
def _compute_mass_mailing_contacts_count(self):
|
||||||
for reg in self:
|
contact_data = self.env['mail.mass_mailing.contact'].read_group(
|
||||||
reg.mass_mailing_contacts_count = len(
|
[('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id'])
|
||||||
reg.mass_mailing_contact_ids)
|
mapped_data = dict(
|
||||||
|
[(contact['partner_id'][0], contact['partner_id_count'])
|
||||||
|
for contact in contact_data])
|
||||||
|
for partner in self:
|
||||||
|
partner.mass_mailing_contacts_count = mapped_data.get(partner.id,
|
||||||
|
0)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
@api.depends('mass_mailing_stats')
|
@api.depends('mass_mailing_stats')
|
||||||
def _compute_mass_mailing_stats_count(self):
|
def _compute_mass_mailing_stats_count(self):
|
||||||
for reg in self:
|
contact_data = self.env['mail.mail.statistics'].read_group(
|
||||||
reg.mass_mailing_stats_count = len(reg.mass_mailing_stats)
|
[('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id'])
|
||||||
|
mapped_data = dict(
|
||||||
|
[(contact['partner_id'][0], contact['partner_id_count'])
|
||||||
|
for contact in contact_data])
|
||||||
|
for partner in self:
|
||||||
|
partner.mass_mailing_stats_count = mapped_data.get(partner.id, 0)
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
res = super(ResPartner, self).write(vals)
|
res = super(ResPartner, self).write(vals)
|
||||||
|
Loading…
Reference in New Issue
Block a user