Browse Source

mass_mailing_partner

pull/277/head
Javier Iniesta 9 years ago
committed by Pedro M. Baeza
parent
commit
627b238a5a
  1. 88
      mass_mailing_partner/README.rst
  2. 20
      mass_mailing_partner/__init__.py
  3. 23
      mass_mailing_partner/__openerp__.py
  4. 140
      mass_mailing_partner/i18n/es.po
  5. 140
      mass_mailing_partner/i18n/mass_mailing_partner.pot
  6. 6
      mass_mailing_partner/models/__init__.py
  7. 13
      mass_mailing_partner/models/mail_mass_mailing.py
  8. 78
      mass_mailing_partner/models/mail_mass_mailing_contact.py
  9. 41
      mass_mailing_partner/models/res_partner.py
  10. BIN
      mass_mailing_partner/static/description/icon.png
  11. 5
      mass_mailing_partner/tests/__init__.py
  12. 35
      mass_mailing_partner/tests/base.py
  13. 35
      mass_mailing_partner/tests/test_mail_mass_mailing_contact.py
  14. 24
      mass_mailing_partner/tests/test_partner_mail_list_wizard.py
  15. 25
      mass_mailing_partner/tests/test_res_partner.py
  16. 39
      mass_mailing_partner/views/mail_mass_mailing_contact_view.xml
  17. 22
      mass_mailing_partner/views/mail_mass_mailing_view.xml
  18. 39
      mass_mailing_partner/views/res_partner_view.xml
  19. 4
      mass_mailing_partner/wizard/__init__.py
  20. 34
      mass_mailing_partner/wizard/partner_mail_list_wizard.py
  21. 32
      mass_mailing_partner/wizard/partner_mail_list_wizard.xml

88
mass_mailing_partner/README.rst

@ -0,0 +1,88 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===============================
Link partners with mass-mailing
===============================
This module links mass-mailing contacts with partners.
Features
--------
* When creating or saving a mass-mailing contact, partners are matched through
email, linking matched partner, or creating a new one if no match and the
maling list partner mandatory field is checked.
* Mailing contacts smart button in partner form.
Configuration
=============
At first install, all existing mass mailing contacts are matched against
partners.
Usage
=====
In partner view, there is a new action called "Add to mailing list". This
action open a pop-up to select a mailing list. Selected partners will be added
as mailing list contacts.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/111/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/crm/issues/new?body=module:%20mass_mailing_partner%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
License
=======
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/agpl-3.0-standalone.html>.
Credits
=======
Contributors
------------
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Rafael Blasco <rafabn@antiun.com>
* Antonio Espinosa <antonioea@antiun.com>
* Javier Iniesta <javieria@antiun.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

20
mass_mailing_partner/__init__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import models
from . import wizard
from openerp import api, SUPERUSER_ID
def _match_existing_contacts(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
contact_model = env['mail.mass_mailing.contact']
partner_model = env['res.partner']
contacts = contact_model.search([('email', '!=', False)])
for contact in contacts:
if contact.email:
partners = partner_model.search([('email', '=ilike',
contact.email)])
if partners:
contact.write({'partner_id': partners[0].id})

23
mass_mailing_partner/__openerp__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
{
"name": "Link partners with mass-mailing",
"version": "8.0.1.0.0",
"author": "Antiun Ingeniería S.L., "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Marketing",
"depends": [
'mass_mailing',
],
"post_init_hook": "_match_existing_contacts",
'data': [
'views/mail_mass_mailing_contact_view.xml',
'views/mail_mass_mailing_view.xml',
'views/res_partner_view.xml',
'wizard/partner_mail_list_wizard.xml'
],
"installable": True,
}

140
mass_mailing_partner/i18n/es.po

@ -0,0 +1,140 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mass_mailing_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-11-03 14:42+0000\n"
"PO-Revision-Date: 2015-11-03 14:42+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Add contacts to mailing list"
msgstr "Añadir contactos a la lista de correo"
#. module: mass_mailing_partner
#: model:ir.actions.act_window,name:mass_mailing_partner.action_partner_mail_list
msgid "Add to mailing list"
msgstr "Añadir a lista de correo"
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Cancel"
msgstr "Cancelar"
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_partner_mail_list_wizard
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Create contact mailing list"
msgstr "Crear lista de correo de contactos"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,create_uid:0
msgid "Created by"
msgstr "Creado por"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,create_date:0
msgid "Created on"
msgstr "Creado en"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,id:0
msgid "ID"
msgstr "ID"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,write_uid:0
msgid "Last Updated by"
msgstr "Última actualización por"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,write_date:0
msgid "Last Updated on"
msgstr "Última actualización en"
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_mail_mass_mailing_list
#: field:partner.mail.list.wizard,mail_list_id:0
#: view:res.partner:mass_mailing_partner.view_res_partner_filter
msgid "Mailing List"
msgstr "Lista de correo"
#. module: mass_mailing_partner
#: field:res.partner,mass_mailing_contacts_count:0
msgid "Mailing list number"
msgstr "Nº Listas de correo"
#. module: mass_mailing_partner
#: view:res.partner:mass_mailing_partner.view_partner_form
msgid "Mailing lists"
msgstr "Listas de correo"
#. module: mass_mailing_partner
#: field:mail.mass_mailing.list,partner_mandatory:0
msgid "Mandatory Partner"
msgstr "Empresa obligatoria"
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_mail_mass_mailing_contact
msgid "Mass Mailing Contact"
msgstr "Contacto de lista de correo"
#. module: mass_mailing_partner
#: field:res.partner,mass_mailing_contacts:0
msgid "Mass mailing contacts"
msgstr "Contactos de lista de correo"
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_res_partner
#: view:mail.mass_mailing.contact:mass_mailing_partner.view_mail_mass_mailing_contact_search
#: field:mail.mass_mailing.contact,partner_id:0
msgid "Partner"
msgstr "Empresa"
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/wizard/partner_mail_list_wizard.py:24
#, python-format
msgid "Partner '%s' has no email."
msgstr "La empresa '%s' no tiene email."
#. module: mass_mailing_partner
#: field:mail.mass_mailing.list,partner_category:0
msgid "Partner Tag"
msgstr "Etiqueta de empresa"
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/models/mail_mass_mailing_contact.py:15
#: sql_constraint:mail.mass_mailing.contact:0
#, python-format
msgid "Partner already exists in this mailing list."
msgstr "La empresa ya existe en esta lista de correo"
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,partner_ids:0
msgid "Partner ids"
msgstr "IDS de empresas"
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/models/res_partner.py:23
#, python-format
msgid "This partner '%s' is subscribed to one or more mailing lists. Email must be assigned."
msgstr "Esta empresa '%s' está suscrita a una o más listas de correo. El email debe estar asignado."
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "or"
msgstr "o"
#. module: mass_mailing_partner
#: view:mail.mass_mailing.contact:mass_mailing_partner.view_mail_mass_mailing_contact_tree
msgid "{'readonly': [('partner_id', '!=', False)]}"
msgstr ""

140
mass_mailing_partner/i18n/mass_mailing_partner.pot

@ -0,0 +1,140 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mass_mailing_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-11-03 14:42+0000\n"
"PO-Revision-Date: 2015-11-03 14:42+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Add contacts to mailing list"
msgstr ""
#. module: mass_mailing_partner
#: model:ir.actions.act_window,name:mass_mailing_partner.action_partner_mail_list
msgid "Add to mailing list"
msgstr ""
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Cancel"
msgstr ""
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_partner_mail_list_wizard
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "Create contact mailing list"
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,create_uid:0
msgid "Created by"
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,create_date:0
msgid "Created on"
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,id:0
msgid "ID"
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_mail_mass_mailing_list
#: field:partner.mail.list.wizard,mail_list_id:0
#: view:res.partner:mass_mailing_partner.view_res_partner_filter
msgid "Mailing List"
msgstr ""
#. module: mass_mailing_partner
#: field:res.partner,mass_mailing_contacts_count:0
msgid "Mailing list number"
msgstr ""
#. module: mass_mailing_partner
#: view:res.partner:mass_mailing_partner.view_partner_form
msgid "Mailing lists"
msgstr ""
#. module: mass_mailing_partner
#: field:mail.mass_mailing.list,partner_mandatory:0
msgid "Mandatory Partner"
msgstr ""
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_mail_mass_mailing_contact
msgid "Mass Mailing Contact"
msgstr ""
#. module: mass_mailing_partner
#: field:res.partner,mass_mailing_contacts:0
msgid "Mass mailing contacts"
msgstr ""
#. module: mass_mailing_partner
#: model:ir.model,name:mass_mailing_partner.model_res_partner
#: view:mail.mass_mailing.contact:mass_mailing_partner.view_mail_mass_mailing_contact_search
#: field:mail.mass_mailing.contact,partner_id:0
msgid "Partner"
msgstr ""
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/wizard/partner_mail_list_wizard.py:24
#, python-format
msgid "Partner '%s' has no email."
msgstr ""
#. module: mass_mailing_partner
#: field:mail.mass_mailing.list,partner_category:0
msgid "Partner Tag"
msgstr ""
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/models/mail_mass_mailing_contact.py:15
#: sql_constraint:mail.mass_mailing.contact:0
#, python-format
msgid "Partner already exists in this mailing list."
msgstr ""
#. module: mass_mailing_partner
#: field:partner.mail.list.wizard,partner_ids:0
msgid "Partner ids"
msgstr ""
#. module: mass_mailing_partner
#: code:addons/mass_mailing_partner/models/res_partner.py:23
#, python-format
msgid "This partner '%s' is subscribed to one or more mailing lists. Email must be assigned."
msgstr ""
#. module: mass_mailing_partner
#: view:partner.mail.list.wizard:mass_mailing_partner.partner_mail_list_wizard_form
msgid "or"
msgstr ""
#. module: mass_mailing_partner
#: view:mail.mass_mailing.contact:mass_mailing_partner.view_mail_mass_mailing_contact_tree
msgid "{'readonly': [('partner_id', '!=', False)]}"
msgstr ""

6
mass_mailing_partner/models/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import mail_mass_mailing_contact
from . import res_partner
from . import mail_mass_mailing

13
mass_mailing_partner/models/mail_mass_mailing.py

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from openerp import models, fields
class MailMassMailingList(models.Model):
_inherit = 'mail.mass_mailing.list'
partner_mandatory = fields.Boolean(string="Mandatory Partner",
default=False)
partner_category = fields.Many2one(comodel_name='res.partner.category',
string="Partner Tag")

78
mass_mailing_partner/models/mail_mass_mailing_contact.py

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from openerp import models, fields, api, _
class MailMassMailingContact(models.Model):
_inherit = 'mail.mass_mailing.contact'
partner_id = fields.Many2one(comodel_name='res.partner', string="Partner",
domain=[('email', '!=', False)])
_sql_constraints = [
('partner_list_uniq', 'unique(partner_id, list_id)',
_('Partner already exists in this mailing list.'))
]
@api.one
@api.onchange('partner_id')
def _onchange_partner(self):
if self.partner_id:
self.name = self.partner_id.name
self.email = self.partner_id.email
@api.model
@api.returns('self', lambda x: x.id)
def create(self, vals):
if not vals.get('partner_id'):
vals = self._set_partner(vals)
vals = self._set_name_email(vals)
return super(MailMassMailingContact, self).create(vals)
@api.one
def write(self, vals):
if vals.get('partner_id', None) is False:
# If removing partner, search again by email
vals = self._set_partner(vals)
vals = self._set_name_email(vals)
return super(MailMassMailingContact, self).write(vals)
def _prepare_partner(self, vals, mailing_list):
vals = {
'name': vals.get('name') or vals.get('email'),
'email': vals.get('email', False),
}
if mailing_list.partner_category:
vals['category_id'] = [(4, mailing_list.partner_category.id, 0)]
return vals
def _set_partner(self, vals):
email = vals.get('email', self.email)
if not email:
return vals
m_mailing = self.env['mail.mass_mailing.list']
m_partner = self.env['res.partner']
list_id = vals.get('list_id', self.list_id.id)
mailing_list = m_mailing.browse(list_id)
# Look for a partner with that email
email = email.strip()
partners = m_partner.search([('email', '=ilike', email)], limit=1)
if partners:
# Partner found
vals['partner_id'] = partners[0].id
elif mailing_list.partner_mandatory:
# Create partner
partner = m_partner.sudo().create(
self._prepare_partner(vals, mailing_list))
vals['partner_id'] = partner.id
return vals
def _set_name_email(self, vals):
partner_id = vals.get('partner_id', self.partner_id.id)
if not partner_id:
return vals
partner = self.env['res.partner'].browse(partner_id)
vals['email'] = partner.email
vals['name'] = partner.name
return vals

41
mass_mailing_partner/models/res_partner.py

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = 'res.partner'
mass_mailing_contacts = fields.One2many(
comodel_name='mail.mass_mailing.contact', inverse_name='partner_id')
mass_mailing_contacts_count = fields.Integer(
string='Mailing list number', compute='_count_mass_mailing_contacts',
store=True)
@api.one
@api.constrains('email')
def _check_email_mass_mailing_contacts(self):
if self.mass_mailing_contacts 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')
def _count_mass_mailing_contacts(self):
self.mass_mailing_contacts_count = len(self.mass_mailing_contacts)
@api.multi
def write(self, vals):
res = super(ResPartner, self).write(vals)
if vals.get('name') or vals.get('email'):
mm_vals = {}
if vals.get('name'):
mm_vals['name'] = vals['name']
if vals.get('email'):
mm_vals['name'] = vals['email']
self.mapped('mass_mailing_contacts').write(mm_vals)
return res

BIN
mass_mailing_partner/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 15 KiB

5
mass_mailing_partner/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import test_mail_mass_mailing_contact, test_res_partner
from . import test_partner_mail_list_wizard

35
mass_mailing_partner/tests/base.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from openerp.tests.common import TransactionCase
class BaseCase(TransactionCase):
def setUp(self):
super(BaseCase, self).setUp()
m_partner_category = self.env['res.partner.category']
m_mailing_list = self.env['mail.mass_mailing.list']
self.company_id = self.env.ref('base.main_company')
self.company = self.env['res.company'].browse(self.company_id)
self.partner = self.create_partner({'name': 'Partner test',
'email': 'partner@test.com'})
partner_category = m_partner_category.create({'name': 'Category Test'})
self.mailing_list = m_mailing_list.create({'name': 'List test'})
self.mailing_list2 = m_mailing_list.create(
{'name': 'List test 2', 'partner_mandatory': True,
'partner_category': partner_category.id})
def create_partner(self, vals):
m_partner = self.env['res.partner']
return m_partner.create(vals)
def create_mailing_contact(self, vals):
m_mailing_contact = self.env['mail.mass_mailing.contact']
return m_mailing_contact.create(vals)
def check_mailing_contact_partner(self, mailing_contact):
if mailing_contact.partner_id:
self.assertEqual(mailing_contact.partner_id.email,
mailing_contact.email)
self.assertEqual(mailing_contact.partner_id.name,
mailing_contact.name)

35
mass_mailing_partner/tests/test_mail_mass_mailing_contact.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import base
from .. import _match_existing_contacts
from psycopg2 import IntegrityError
class MailMassMailingContactCase(base.BaseCase):
def test_match_existing_contacts(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
_match_existing_contacts(self.cr, self.registry)
self.assertEqual(contact.partner_id.id, self.partner.id)
def test_create_mass_mailing_contact(self):
contact = self.create_mailing_contact(
{'email': 'partner2@test.com', 'name': 'Partner test 2',
'list_id': self.mailing_list2.id})
self.check_mailing_contact_partner(contact)
with self.assertRaises(IntegrityError):
self.create_mailing_contact({'email': 'partner2@test.com',
'list_id': self.mailing_list2.id})
def test_write_mass_mailing_contact(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
contact.write({'partner_id': False})
self.check_mailing_contact_partner(contact)
contact2 = self.create_mailing_contact(
{'email': 'partner2@test.com', 'name': 'Partner test 2',
'list_id': self.mailing_list.id})
contact.write({'partner_id': False})
self.assertFalse(contact2.partner_id)

24
mass_mailing_partner/tests/test_partner_mail_list_wizard.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import base
from openerp.exceptions import Warning as UserError
class PartnerMailListWizardCase(base.BaseCase):
def test_add_to_mail_list(self):
wizard = self.env['partner.mail.list.wizard'].create(
{'mail_list_id': self.mailing_list.id})
wizard.partner_ids = [self.partner.id]
wizard.add_to_mail_list()
contact = self.env['mail.mass_mailing.contact'].search([
('partner_id', '=', self.partner.id),
('list_id', '=', self.mailing_list.id)])
self.check_mailing_contact_partner(contact)
# This line does not create a new contact
wizard.add_to_mail_list()
partner = self.env['res.partner'].create({'name': 'No email partner'})
wizard.partner_ids = [partner.id]
with self.assertRaises(UserError):
wizard.add_to_mail_list()

25
mass_mailing_partner/tests/test_res_partner.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import base
from openerp.exceptions import ValidationError
class ResPartnerCase(base.BaseCase):
def test_count_mass_mailing_contacts(self):
self.create_mailing_contact({'email': 'partner@test.com',
'list_id': self.mailing_list.id})
self.create_mailing_contact({'email': 'partner@test.com',
'list_id': self.mailing_list2.id})
self.partner._count_mass_mailing_contacts()
self.assertEqual(self.partner.mass_mailing_contacts_count, 2)
def test_write_res_partner(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
self.partner.write({'name': 'Changed', 'email': 'partner@changed.com'})
self.assertEqual(contact.name, self.partner.name)
self.assertEqual(contact.email, self.partner.email)
with self.assertRaises(ValidationError):
self.partner.write({'email': False})

39
mass_mailing_partner/views/mail_mass_mailing_contact_view.xml

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_mail_mass_mailing_contact_tree">
<field name="name">mail.mass_mailing.contact.tree.partner</field>
<field name="model">mail.mass_mailing.contact</field>
<field name="inherit_id" ref="mass_mailing.view_mail_mass_mailing_contact_tree"/>
<field name="arch" type="xml">
<field name="email" position="after">
<field name="partner_id"/>
</field>
<field name="email" position="attributes">
<attribute name="attrs">{'readonly': [('partner_id', '!=', False)]}</attribute>
</field>
<field name="name" position="attributes">
<attribute name="attrs">{'readonly': [('partner_id', '!=', False)]}</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_mail_mass_mailing_contact_search">
<field name="name">mail.mass_mailing.contact.search.partner</field>
<field name="model">mail.mass_mailing.contact</field>
<field name="inherit_id" ref="mass_mailing.view_mail_mass_mailing_contact_search"/>
<field name="arch" type="xml">
<field name="email" position="after">
<field name="partner_id"/>
</field>
<filter name="group_create_date" position="after">
<filter string="Partner"
name="group_partner"
context="{'group_by': 'partner_id'}"/>
</filter>
</field>
</record>
</data>
</openerp>

22
mass_mailing_partner/views/mail_mass_mailing_view.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_mail_mass_mailing_list_form">
<field name="name">mail.mass_mailing.list.form</field>
<field name="model">mail.mass_mailing.list</field>
<field name="inherit_id" ref="mass_mailing.view_mail_mass_mailing_list_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@class='oe_title']" position="after">
<group>
<group>
<field name="partner_mandatory"/>
<field name="partner_category"/>
</group>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

39
mass_mailing_partner/views/res_partner_view.xml

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_partner_form">
<field name="name">Partner Form with mailing contacts</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<div class="oe_right oe_button_box" position="inside">
<button name="%(mass_mailing.action_view_mass_mailing_contacts)d"
context="{'search_default_partner_id': active_id,
'default_partner_id': active_id}"
type="action"
class="oe_stat_button oe_inline"
icon="fa-envelope-o">
<field name="mass_mailing_contacts_count"
widget="statinfo"
string="Mailing lists"/>
</button>
</div>
</field>
</record>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">Partner Search with mailing contacts</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<field name="category_id" position="after">
<field name="mass_mailing_contacts" string="Mailing List"
filter_domain="[('mass_mailing_contacts.list_id','ilike', self)]"/>
</field>
</field>
</record>
</data>
</openerp>

4
mass_mailing_partner/wizard/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from . import partner_mail_list_wizard

34
mass_mailing_partner/wizard/partner_mail_list_wizard.py

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# See README.rst file on addon root folder for license details
from openerp import models, api, fields, _
from openerp.exceptions import Warning as UserError
class PartnerMailListWizard(models.TransientModel):
_name = "partner.mail.list.wizard"
_description = "Create contact mailing list"
mail_list_id = fields.Many2one(comodel_name="mail.mass_mailing.list",
string="Mailing List")
partner_ids = fields.Many2many(
comodel_name="res.partner", relation="mail_list_wizard_partner",
default=lambda self: self.env.context.get("active_ids"))
@api.multi
def add_to_mail_list(self):
contact_obj = self.env['mail.mass_mailing.contact']
for partner in self.partner_ids:
if not partner.email:
raise UserError(_("Partner '%s' has no email.") % partner.name)
criteria = [('email', '=', partner.email),
('list_id', '=', self.mail_list_id.id)]
contact_test = contact_obj.search(criteria)
if contact_test:
continue
contact_vals = {
'email': partner.email,
'name': partner.name,
'list_id': self.mail_list_id.id
}
contact_obj.create(contact_vals)

32
mass_mailing_partner/wizard/partner_mail_list_wizard.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<act_window name="Add to mailing list"
res_model="partner.mail.list.wizard"
src_model="res.partner"
view_mode="form"
target="new"
key2="client_action_multi"
id="action_partner_mail_list"/>
<record model="ir.ui.view" id="partner_mail_list_wizard_form">
<field name="name">partner.mail.list.form</field>
<field name="model">partner.mail.list.wizard</field>
<field name="arch" type="xml">
<form string="Create contact mailing list">
<group>
<field name="mail_list_id"/>
</group>
<footer>
<button string="Add contacts to mailing list" name="add_to_mail_list"
type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save