From 6d5765eaf2a915f3464a36d4d7d9195f259ab3f8 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 12 Sep 2016 08:43:32 +0200 Subject: [PATCH] Exclude opt_out. (#110) [FIX][mass_mailing_partner] Exclude opt_out. Now opted-out records will not be counted in the "Mailing lists" smart button in the partner form. --- mass_mailing_partner/README.rst | 3 ++- mass_mailing_partner/__openerp__.py | 2 +- mass_mailing_partner/models/res_partner.py | 15 ++++++++++----- mass_mailing_partner/views/res_partner_view.xml | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mass_mailing_partner/README.rst b/mass_mailing_partner/README.rst index 0af7934d..a95f5175 100644 --- a/mass_mailing_partner/README.rst +++ b/mass_mailing_partner/README.rst @@ -79,9 +79,10 @@ Contributors ------------ * Pedro M. Baeza -* Rafael Blasco +* Rafael Blasco * Antonio Espinosa * Javier Iniesta +* Jairo Llopis Maintainer ---------- diff --git a/mass_mailing_partner/__openerp__.py b/mass_mailing_partner/__openerp__.py index bb49d895..b0dea3a4 100644 --- a/mass_mailing_partner/__openerp__.py +++ b/mass_mailing_partner/__openerp__.py @@ -7,7 +7,7 @@ { "name": "Link partners with mass-mailing", - "version": "8.0.2.0.0", + "version": "8.0.2.1.0", "author": "Tecnativa, " "Antiun IngenierĂ­a S.L., " "Serv. Tecnol. Avanzados - Pedro M. Baeza, " diff --git a/mass_mailing_partner/models/res_partner.py b/mass_mailing_partner/models/res_partner.py index d53b4728..708a0560 100644 --- a/mass_mailing_partner/models/res_partner.py +++ b/mass_mailing_partner/models/res_partner.py @@ -12,8 +12,10 @@ from openerp.exceptions import ValidationError class ResPartner(models.Model): _inherit = 'res.partner' - mass_mailing_contacts = fields.One2many( + mass_mailing_contact_ids = fields.One2many( string="Mailing lists", + oldname="mass_mailing_contacts", + domain=[('opt_out', '=', False)], comodel_name='mail.mass_mailing.contact', inverse_name='partner_id') mass_mailing_contacts_count = fields.Integer( string='Mailing list number', @@ -28,15 +30,16 @@ class ResPartner(models.Model): @api.one @api.constrains('email') def _check_email_mass_mailing_contacts(self): - if self.mass_mailing_contacts and not self.email: + if self.mass_mailing_contact_ids and not self.email: raise ValidationError( _("This partner '%s' is subscribed to one or more " "mailing lists. Email must be assigned." % self.name)) @api.one - @api.depends('mass_mailing_contacts') + @api.depends('mass_mailing_contact_ids', + 'mass_mailing_contact_ids.opt_out') def _compute_mass_mailing_contacts_count(self): - self.mass_mailing_contacts_count = len(self.mass_mailing_contacts) + self.mass_mailing_contacts_count = len(self.mass_mailing_contact_ids) @api.one @api.depends('mass_mailing_stats') @@ -52,5 +55,7 @@ class ResPartner(models.Model): mm_vals['name'] = vals['name'] if vals.get('email'): mm_vals['name'] = vals['email'] - self.mapped('mass_mailing_contacts').write(mm_vals) + self.env["mail.mass_mailing.contact"].search([ + ("partner_id", "in", self.ids), + ]).write(mm_vals) return res diff --git a/mass_mailing_partner/views/res_partner_view.xml b/mass_mailing_partner/views/res_partner_view.xml index 3e8d5712..81a552b1 100644 --- a/mass_mailing_partner/views/res_partner_view.xml +++ b/mass_mailing_partner/views/res_partner_view.xml @@ -44,8 +44,8 @@ 20 - +