@ -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_id s = 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_id s 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_id s )
@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