|
|
@ -20,21 +20,22 @@ class PartnerMailListWizard(models.TransientModel): |
|
|
|
@api.multi |
|
|
|
def add_to_mail_list(self): |
|
|
|
contact_obj = self.env['mail.mass_mailing.contact'] |
|
|
|
for partner in self.partner_ids: |
|
|
|
partners = self.partner_ids |
|
|
|
|
|
|
|
add_list = partners.filtered(lambda r: r.mass_mailing_contact_ids) |
|
|
|
if add_list: |
|
|
|
add_list.mass_mailing_contact_ids[0].list_ids |= self.mail_list_id |
|
|
|
|
|
|
|
to_create = partners - add_list |
|
|
|
for partner in to_create: |
|
|
|
if not partner.email: |
|
|
|
raise UserError(_("Partner '%s' has no email.") % partner.name) |
|
|
|
contact = contact_obj.search([('partner_id', '=', partner.id)]) |
|
|
|
if self.mail_list_id not in contact.mapped('list_ids'): |
|
|
|
contact_vals = { |
|
|
|
'partner_id': partner.id, |
|
|
|
'list_ids': [[6, 0, [self.mail_list_id.id]]] |
|
|
|
} |
|
|
|
if partner.title: |
|
|
|
contact_vals['title_id'] = partner.title.id |
|
|
|
if partner.company_id: |
|
|
|
contact_vals['company_name'] = partner.company_id.name |
|
|
|
if partner.country_id: |
|
|
|
contact_vals['country_id'] = partner.country_id.id |
|
|
|
if partner.category_id: |
|
|
|
contact_vals['tag_ids'] = partner.category_id.ids |
|
|
|
contact_obj.create(contact_vals) |
|
|
|
contact_vals = { |
|
|
|
'partner_id': partner.id, |
|
|
|
'list_ids': [[6, 0, [self.mail_list_id.id]]], |
|
|
|
'title_id': partner.title or False, |
|
|
|
'company_name': partner.company_id.name or False, |
|
|
|
'country_id': partner.country_id or False, |
|
|
|
'tag_ids': partner.category_id or False, |
|
|
|
} |
|
|
|
contact_obj.create(contact_vals) |