Browse Source

[FIX] mass_mailing_partner: Several things:

* Exclude opt_out.

  Now opted-out records will not be counted in the "Mailing lists" smart button
  in the partner form.

* Avoid duplicate error.

  By indicating the exact `partner_id` and ensuring no contacts associated to it are found, you avoid possible duplication errors when several partners share the same name or email.
pull/277/head
Jairo Llopis 8 years ago
committed by Pedro M. Baeza
parent
commit
f25249c911
  1. 3
      mass_mailing_partner/README.rst
  2. 2
      mass_mailing_partner/__openerp__.py
  3. 15
      mass_mailing_partner/models/res_partner.py
  4. 4
      mass_mailing_partner/views/res_partner_view.xml
  5. 9
      mass_mailing_partner/wizard/partner_mail_list_wizard.py

3
mass_mailing_partner/README.rst

@ -79,9 +79,10 @@ Contributors
------------ ------------
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> * Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Rafael Blasco <rafabn@antiun.com>
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Antonio Espinosa <antonioea@antiun.com> * Antonio Espinosa <antonioea@antiun.com>
* Javier Iniesta <javieria@antiun.com> * Javier Iniesta <javieria@antiun.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
Maintainer Maintainer
---------- ----------

2
mass_mailing_partner/__openerp__.py

@ -7,7 +7,7 @@
{ {
"name": "Link partners with mass-mailing", "name": "Link partners with mass-mailing",
"version": "8.0.2.0.0",
"version": "8.0.2.1.0",
"author": "Tecnativa, " "author": "Tecnativa, "
"Antiun Ingeniería S.L., " "Antiun Ingeniería S.L., "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, " "Serv. Tecnol. Avanzados - Pedro M. Baeza, "

15
mass_mailing_partner/models/res_partner.py

@ -12,8 +12,10 @@ from openerp.exceptions import ValidationError
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
mass_mailing_contacts = fields.One2many(
mass_mailing_contact_ids = fields.One2many(
string="Mailing lists", string="Mailing lists",
oldname="mass_mailing_contacts",
domain=[('opt_out', '=', False)],
comodel_name='mail.mass_mailing.contact', inverse_name='partner_id') comodel_name='mail.mass_mailing.contact', inverse_name='partner_id')
mass_mailing_contacts_count = fields.Integer( mass_mailing_contacts_count = fields.Integer(
string='Mailing list number', string='Mailing list number',
@ -28,15 +30,16 @@ class ResPartner(models.Model):
@api.one @api.one
@api.constrains('email') @api.constrains('email')
def _check_email_mass_mailing_contacts(self): 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( raise ValidationError(
_("This partner '%s' is subscribed to one or more " _("This partner '%s' is subscribed to one or more "
"mailing lists. Email must be assigned." % self.name)) "mailing lists. Email must be assigned." % self.name))
@api.one @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): 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.one
@api.depends('mass_mailing_stats') @api.depends('mass_mailing_stats')
@ -52,5 +55,7 @@ class ResPartner(models.Model):
mm_vals['name'] = vals['name'] mm_vals['name'] = vals['name']
if vals.get('email'): if vals.get('email'):
mm_vals['name'] = vals['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 return res

4
mass_mailing_partner/views/res_partner_view.xml

@ -44,8 +44,8 @@
<field name="priority">20</field> <field name="priority">20</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="category_id" position="after"> <field name="category_id" position="after">
<field name="mass_mailing_contacts" string="Mailing List"
filter_domain="[('mass_mailing_contacts.list_id','ilike', self)]"/>
<field name="mass_mailing_contact_ids" string="Mailing List"
filter_domain="[('mass_mailing_contact_ids.list_id','ilike', self)]"/>
</field> </field>
</field> </field>
</record> </record>

9
mass_mailing_partner/wizard/partner_mail_list_wizard.py

@ -24,12 +24,17 @@ class PartnerMailListWizard(models.TransientModel):
for partner in self.partner_ids: for partner in self.partner_ids:
if not partner.email: if not partner.email:
raise UserError(_("Partner '%s' has no email.") % partner.name) raise UserError(_("Partner '%s' has no email.") % partner.name)
criteria = [('email', '=', partner.email),
('list_id', '=', self.mail_list_id.id)]
criteria = [
'|',
('email', '=', partner.email),
('partner_id', '=', partner.id),
('list_id', '=', self.mail_list_id.id),
]
contact_test = contact_obj.search(criteria) contact_test = contact_obj.search(criteria)
if contact_test: if contact_test:
continue continue
contact_vals = { contact_vals = {
'partner_id': partner.id,
'email': partner.email, 'email': partner.email,
'name': partner.name, 'name': partner.name,
'list_id': self.mail_list_id.id 'list_id': self.mail_list_id.id

Loading…
Cancel
Save