Antonio Espinosa
9 years ago
12 changed files with 341 additions and 33 deletions
-
1mail_tracking/__init__.py
-
6mail_tracking/__openerp__.py
-
71mail_tracking/controllers/main.py
-
24mail_tracking/hooks.py
-
1mail_tracking/models/__init__.py
-
4mail_tracking/models/ir_mail_server.py
-
107mail_tracking/models/mail_tracking_email.py
-
40mail_tracking/models/res_partner.py
-
71mail_tracking/tests/test_mail_tracking.py
-
11mail_tracking/views/mail_tracking_email_view.xml
-
5mail_tracking/views/mail_tracking_event_view.xml
-
33mail_tracking/views/res_partner_view.xml
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 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, {}) |
|||
# Recalculate all partner tracking_email_ids |
|||
partners = env['res.partner'].search([ |
|||
('email', '!=', False), |
|||
]) |
|||
emails = partners.mapped('email') |
|||
_logger.info( |
|||
"Recalculating 'tracking_email_ids' in 'res.partner' " |
|||
"model for %d email addresses", len(emails)) |
|||
for email in emails: |
|||
env['mail.tracking.email'].tracking_ids_recalculate( |
|||
'res.partner', 'email', 'tracking_email_ids', email) |
@ -0,0 +1,40 @@ |
|||
# -*- 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, api, fields |
|||
|
|||
|
|||
class ResPartner(models.Model): |
|||
_inherit = 'res.partner' |
|||
|
|||
tracking_email_ids = fields.Many2many( |
|||
string="Tracking emails", comodel_name="mail.tracking.email", |
|||
readonly=True) |
|||
tracking_emails_count = fields.Integer( |
|||
string="Tracking emails count", store=True, readonly=True, |
|||
compute="_compute_tracking_emails_count") |
|||
email_score = fields.Float( |
|||
string="Email score", |
|||
compute="_compute_email_score", store=True, readonly=True) |
|||
|
|||
@api.one |
|||
@api.depends('tracking_email_ids.state') |
|||
def _compute_email_score(self): |
|||
self.email_score = self.tracking_email_ids.email_score() |
|||
|
|||
@api.one |
|||
@api.depends('tracking_email_ids') |
|||
def _compute_tracking_emails_count(self): |
|||
self.tracking_emails_count = self.env['mail.tracking.email'].\ |
|||
search_count([ |
|||
('recipient_address', '=ilike', self.email) |
|||
]) |
|||
|
|||
@api.multi |
|||
def write(self, vals): |
|||
email = vals.get('email') |
|||
if email is not None: |
|||
vals['tracking_email_ids'] = \ |
|||
self.env['mail.tracking.email']._tracking_ids_to_write(email) |
|||
return super(ResPartner, self).write(vals) |
@ -0,0 +1,33 @@ |
|||
<?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_partner_form"> |
|||
<field name="name">Partner Form with tracking emails</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="%(mail_tracking.action_view_mail_tracking_email)d" |
|||
context="{'search_default_recipient': email, |
|||
'default_recipient': email}" |
|||
type="action" |
|||
class="oe_stat_button oe_inline" |
|||
icon="fa-envelope-o" |
|||
attrs="{'invisible': [('email', '=', False)]}"> |
|||
<field name="tracking_emails_count" |
|||
widget="statinfo" |
|||
string="Tracking emails"/> |
|||
</button> |
|||
</div> |
|||
<field name="email" position="after"> |
|||
<field name="email_score" widget="progressbar" |
|||
attrs="{'invisible': [('email', '=', False)]}"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue