Browse Source
[8.0][IMP][mass_mailing_partner] Link mail statistics to partner (#104)
[8.0][IMP][mass_mailing_partner] Link mail statistics to partner (#104)
[IMP] mass_mailing_partner: Link mail statistics to partnerpull/113/head
Antonio Espinosa
8 years ago
committed by
archetipo
22 changed files with 284 additions and 42 deletions
-
15mass_mailing_partner/README.rst
-
22mass_mailing_partner/__init__.py
-
14mass_mailing_partner/__openerp__.py
-
37mass_mailing_partner/hooks.py
-
7mass_mailing_partner/models/__init__.py
-
37mass_mailing_partner/models/mail_mail_statistics.py
-
5mass_mailing_partner/models/mail_mass_mailing.py
-
8mass_mailing_partner/models/mail_mass_mailing_contact.py
-
25mass_mailing_partner/models/res_partner.py
-
6mass_mailing_partner/tests/__init__.py
-
5mass_mailing_partner/tests/base.py
-
28mass_mailing_partner/tests/test_mail_mail_statistics.py
-
20mass_mailing_partner/tests/test_mail_mass_mailing_contact.py
-
5mass_mailing_partner/tests/test_partner_mail_list_wizard.py
-
6mass_mailing_partner/tests/test_res_partner.py
-
46mass_mailing_partner/views/mail_mail_statistics_view.xml
-
7mass_mailing_partner/views/mail_mass_mailing_contact_view.xml
-
4mass_mailing_partner/views/mail_mass_mailing_view.xml
-
15mass_mailing_partner/views/res_partner_view.xml
-
5mass_mailing_partner/wizard/__init__.py
-
5mass_mailing_partner/wizard/partner_mail_list_wizard.py
-
4mass_mailing_partner/wizard/partner_mail_list_wizard.xml
@ -1,20 +1,10 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# See README.rst file on addon root folder for license details |
|
||||
|
# © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# © 2015 Antonio Espinosa <antonioea@antiun.com> |
||||
|
# © 2015 Javier Iniesta <javieria@antiun.com> |
||||
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import models |
from . import models |
||||
from . import wizard |
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}) |
|
||||
|
from .hooks import post_init_hook |
@ -0,0 +1,37 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# © 2015 Antonio Espinosa <antonioea@antiun.com> |
||||
|
# © 2015 Javier Iniesta <javieria@antiun.com> |
||||
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import logging |
||||
|
from openerp import api, SUPERUSER_ID |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
def post_init_hook(cr, registry): |
||||
|
with api.Environment.manage(): |
||||
|
env = api.Environment(cr, SUPERUSER_ID, {}) |
||||
|
# ACTION 1: Match existing contacts |
||||
|
contact_model = env['mail.mass_mailing.contact'] |
||||
|
partner_model = env['res.partner'] |
||||
|
contacts = contact_model.search([('email', '!=', False)]) |
||||
|
_logger.info('Trying to match %d contacts to partner by email', |
||||
|
len(contacts)) |
||||
|
for contact in contacts: |
||||
|
partners = partner_model.search([ |
||||
|
('email', '=ilike', contact.email) |
||||
|
], limit=1) |
||||
|
if partners: |
||||
|
contact.write({'partner_id': partners.id}) |
||||
|
# ACTION 2: Match existing statistics |
||||
|
stat_model = env['mail.mail.statistics'] |
||||
|
stats = stat_model.search([ |
||||
|
('model', '!=', False), |
||||
|
('res_id', '!=', False), |
||||
|
]) |
||||
|
_logger.info('Trying to link %d mass mailing statistics to partner', |
||||
|
len(stats)) |
||||
|
stats.partner_link() |
@ -1,6 +1,11 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# See README.rst file on addon root folder for license details |
|
||||
|
# © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# © 2015 Antonio Espinosa <antonioea@antiun.com> |
||||
|
# © 2015 Javier Iniesta <javieria@antiun.com> |
||||
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import mail_mass_mailing_contact |
from . import mail_mass_mailing_contact |
||||
from . import res_partner |
from . import res_partner |
||||
from . import mail_mass_mailing |
from . import mail_mass_mailing |
||||
|
from . import mail_mail_statistics |
@ -0,0 +1,37 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp import models, fields, api |
||||
|
|
||||
|
|
||||
|
class MailMailStatistics(models.Model): |
||||
|
_inherit = "mail.mail.statistics" |
||||
|
|
||||
|
partner_id = fields.Many2one( |
||||
|
string="Partner", comodel_name='res.partner', readonly=True) |
||||
|
|
||||
|
@api.model |
||||
|
def partner_id_from_obj(self, model, res_id): |
||||
|
partner_id = False |
||||
|
obj = self.env[model].browse(res_id) |
||||
|
if obj.exists(): |
||||
|
if model == 'res.partner': |
||||
|
partner_id = res_id |
||||
|
elif 'partner_id' in obj._fields: |
||||
|
partner_id = obj.partner_id.id |
||||
|
return partner_id |
||||
|
|
||||
|
@api.multi |
||||
|
def partner_link(self): |
||||
|
for stat in self.filtered(lambda r: r.model and r.res_id): |
||||
|
partner_id = self.partner_id_from_obj(stat.model, stat.res_id) |
||||
|
if partner_id != stat.partner_id.id: |
||||
|
stat.partner_id = partner_id |
||||
|
return True |
||||
|
|
||||
|
@api.model |
||||
|
def create(self, vals): |
||||
|
stat = super(MailMailStatistics, self).create(vals) |
||||
|
stat.partner_link() |
||||
|
return stat |
@ -1,5 +1,9 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# See README.rst file on addon root folder for license details |
|
||||
|
# © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# © 2015 Antonio Espinosa <antonioea@antiun.com> |
||||
|
# © 2015 Javier Iniesta <javieria@antiun.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import test_mail_mass_mailing_contact, test_res_partner |
from . import test_mail_mass_mailing_contact, test_res_partner |
||||
|
from . import test_mail_mail_statistics |
||||
from . import test_partner_mail_list_wizard |
from . import test_partner_mail_list_wizard |
@ -0,0 +1,28 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from . import base |
||||
|
|
||||
|
|
||||
|
class MailMailStatisticsCase(base.BaseCase): |
||||
|
|
||||
|
def test_link_partner(self): |
||||
|
partner = self.create_partner( |
||||
|
{'name': 'Test partner'}) |
||||
|
stat = self.env['mail.mail.statistics'].create({ |
||||
|
'model': 'res.partner', |
||||
|
'res_id': partner.id, |
||||
|
}) |
||||
|
self.assertEqual(partner.id, stat.partner_id.id) |
||||
|
|
||||
|
def test_link_mail_contact(self): |
||||
|
partner = self.create_partner( |
||||
|
{'name': 'Test partner', 'email': 'test@domain.com'}) |
||||
|
contact = self.create_mailing_contact( |
||||
|
{'partner_id': partner.id, 'list_id': self.mailing_list.id}) |
||||
|
stat = self.env['mail.mail.statistics'].create({ |
||||
|
'model': 'mail.mass_mailing.contact', |
||||
|
'res_id': contact.id, |
||||
|
}) |
||||
|
self.assertEqual(partner.id, stat.partner_id.id) |
@ -0,0 +1,46 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record model="ir.ui.view" id="view_mail_mail_statistics_form"> |
||||
|
<field name="name">Add partner field</field> |
||||
|
<field name="model">mail.mail.statistics</field> |
||||
|
<field name="inherit_id" ref="mass_mailing.view_mail_mail_statistics_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="res_id" position="after"> |
||||
|
<field name="partner_id"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.ui.view" id="view_mail_mail_statistics_tree"> |
||||
|
<field name="name">Add partner column</field> |
||||
|
<field name="model">mail.mail.statistics</field> |
||||
|
<field name="inherit_id" ref="mass_mailing.view_mail_mail_statistics_tree"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="sent" position="before"> |
||||
|
<field name="partner_id"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.ui.view" id="view_mail_mail_statistics_search"> |
||||
|
<field name="name">Add partner search field and group by</field> |
||||
|
<field name="model">mail.mail.statistics</field> |
||||
|
<field name="inherit_id" ref="mass_mailing.view_mail_mail_statistics_search"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="mass_mailing_id" position="after"> |
||||
|
<field name="partner_id"/> |
||||
|
</field> |
||||
|
<filter name="group_reply_date" position="after"> |
||||
|
<filter string="Partner" |
||||
|
name="group_partner" |
||||
|
context="{'group_by': 'partner_id'}"/> |
||||
|
</filter> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -1,4 +1,7 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# See README.rst file on addon root folder for license details |
|
||||
|
# © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
# © 2015 Antonio Espinosa <antonioea@antiun.com> |
||||
|
# © 2015 Javier Iniesta <javieria@antiun.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import partner_mail_list_wizard |
from . import partner_mail_list_wizard |
Write
Preview
Loading…
Cancel
Save
Reference in new issue