Browse Source

[MIG] mail_tracking: Migrated to 10.0

pull/108/head
Damien Bouvy 8 years ago
parent
commit
94bb11557b
No known key found for this signature in database GPG Key ID: 1D0AB759B4B928E3
  1. 2
      mail_tracking/README.rst
  2. 4
      mail_tracking/__manifest__.py
  3. 2
      mail_tracking/controllers/main.py
  4. 12
      mail_tracking/data/tracking_data.xml
  5. 2
      mail_tracking/models/ir_mail_server.py
  6. 5
      mail_tracking/models/mail_mail.py
  7. 3
      mail_tracking/models/mail_message.py
  8. 17
      mail_tracking/models/mail_tracking_email.py
  9. 5
      mail_tracking/models/mail_tracking_event.py
  10. 10
      mail_tracking/models/res_partner.py
  11. 3
      mail_tracking/static/src/js/mail_tracking.js
  12. 14
      mail_tracking/tests/test_mail_tracking.py
  13. 6
      mail_tracking/views/assets.xml

2
mail_tracking/README.rst

@ -63,7 +63,7 @@ These are all available status icons:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/9.0
:target: https://runbot.odoo-community.org/runbot/205/10.0
If you want to see all tracking emails and events you can go to If you want to see all tracking emails and events you can go to

4
mail_tracking/__manifest__.py

@ -5,14 +5,14 @@
{ {
"name": "Email tracking", "name": "Email tracking",
"summary": "Email tracking system for all mails sent", "summary": "Email tracking system for all mails sent",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Social Network", "category": "Social Network",
"website": "http://www.tecnativa.com", "website": "http://www.tecnativa.com",
"author": "Tecnativa, " "author": "Tecnativa, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
'installable': False,
'installable': True,
"depends": [ "depends": [
"decimal_precision", "decimal_precision",
"mail", "mail",

2
mail_tracking/controllers/main.py

@ -4,7 +4,7 @@
import werkzeug import werkzeug
from psycopg2 import OperationalError from psycopg2 import OperationalError
from openerp import api, http, registry, SUPERUSER_ID
from odoo import api, http, registry, SUPERUSER_ID
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)

12
mail_tracking/data/tracking_data.xml

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> <!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<record forcecreate="True" id="decimal_tracking_timestamp" model="decimal.precision">
<odoo>
<record forcecreate="True" id="decimal_tracking_timestamp" model="decimal.precision">
<field name="name">MailTracking Timestamp</field> <field name="name">MailTracking Timestamp</field>
<field name="digits">6</field> <field name="digits">6</field>
</record>
</data>
</openerp>
</record>
</odoo>

2
mail_tracking/models/ir_mail_server.py

@ -4,7 +4,7 @@
import re import re
import threading import threading
from openerp import models, api, tools
from odoo import models, api, tools
class IrMailServer(models.Model): class IrMailServer(models.Model):

5
mail_tracking/models/mail_mail.py

@ -6,7 +6,7 @@ import time
from datetime import datetime from datetime import datetime
from email.utils import COMMASPACE from email.utils import COMMASPACE
from openerp import models, api, fields
from odoo import models, fields
class MailMail(models.Model): class MailMail(models.Model):
@ -18,7 +18,7 @@ class MailMail(models.Model):
email_to_list = email.get('email_to', []) email_to_list = email.get('email_to', [])
email_to = COMMASPACE.join(email_to_list) email_to = COMMASPACE.join(email_to_list)
return { return {
'name': email.get('subject', False),
'name': self.subject,
'timestamp': '%.6f' % ts, 'timestamp': '%.6f' % ts,
'time': fields.Datetime.to_string(dt), 'time': fields.Datetime.to_string(dt),
'mail_id': self.id, 'mail_id': self.id,
@ -28,7 +28,6 @@ class MailMail(models.Model):
'sender': self.email_from, 'sender': self.email_from,
} }
@api.multi
def send_get_email_dict(self, partner=None): def send_get_email_dict(self, partner=None):
email = super(MailMail, self).send_get_email_dict(partner=partner) email = super(MailMail, self).send_get_email_dict(partner=partner)
vals = self._tracking_email_prepare(partner, email) vals = self._tracking_email_prepare(partner, email)

3
mail_tracking/models/mail_message.py

@ -2,7 +2,7 @@
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api
from odoo import models, api
class MailMessage(models.Model): class MailMessage(models.Model):
@ -31,7 +31,6 @@ class MailMessage(models.Model):
status = tracking_status_map.get(tracking_email_status, 'unknown') status = tracking_status_map.get(tracking_email_status, 'unknown')
return status return status
@api.multi
def tracking_status(self): def tracking_status(self):
res = {} res = {}
for message in self: for message in self:

17
mail_tracking/models/mail_tracking_email.py

@ -8,8 +8,8 @@ import time
import re import re
from datetime import datetime from datetime import datetime
from openerp import models, api, fields, tools
import openerp.addons.decimal_precision as dp
from odoo import models, api, fields, tools
import odoo.addons.decimal_precision as dp
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -26,7 +26,7 @@ class MailTrackingEmail(models.Model):
name = fields.Char(string="Subject", readonly=True, index=True) name = fields.Char(string="Subject", readonly=True, index=True)
display_name = fields.Char( display_name = fields.Char(
string="Display name", readonly=True, store=True, string="Display name", readonly=True, store=True,
compute="_compute_display_name")
compute="_compute_tracking_display_name")
timestamp = fields.Float( timestamp = fields.Float(
string='UTC timestamp', readonly=True, string='UTC timestamp', readonly=True,
digits=dp.get_precision('MailTracking Timestamp')) digits=dp.get_precision('MailTracking Timestamp'))
@ -120,7 +120,6 @@ class MailTrackingEmail(models.Model):
else: else:
return [(5, False, False)] return [(5, False, False)]
@api.multi
def _email_score_tracking_filter(self): def _email_score_tracking_filter(self):
"""Default email score filter for tracking emails""" """Default email score filter for tracking emails"""
# Consider only last 10 tracking emails # Consider only last 10 tracking emails
@ -133,7 +132,6 @@ class MailTrackingEmail(models.Model):
]) ])
return trackings.email_score() return trackings.email_score()
@api.multi
def email_score(self): def email_score(self):
"""Default email score algorimth""" """Default email score algorimth"""
score = 50.0 score = 50.0
@ -153,7 +151,6 @@ class MailTrackingEmail(models.Model):
score = 100.0 score = 100.0
return score return score
@api.multi
@api.depends('recipient') @api.depends('recipient')
def _compute_recipient_address(self): def _compute_recipient_address(self):
for email in self: for email in self:
@ -163,16 +160,14 @@ class MailTrackingEmail(models.Model):
else: else:
email.recipient_address = email.recipient email.recipient_address = email.recipient
@api.multi
@api.depends('name', 'recipient') @api.depends('name', 'recipient')
def _compute_display_name(self):
def _compute_tracking_display_name(self):
for email in self: for email in self:
parts = [email.name or ''] parts = [email.name or '']
if email.recipient: if email.recipient:
parts.append(email.recipient) parts.append(email.recipient)
email.display_name = ' - '.join(parts) email.display_name = ' - '.join(parts)
@api.multi
@api.depends('time') @api.depends('time')
def _compute_date(self): def _compute_date(self):
for email in self: for email in self:
@ -202,7 +197,6 @@ class MailTrackingEmail(models.Model):
'tracking_email_id': self.id, 'tracking_email_id': self.id,
}) })
@api.multi
def smtp_error(self, mail_server, smtp_server, exception): def smtp_error(self, mail_server, smtp_server, exception):
self.sudo().write({ self.sudo().write({
'error_smtp_server': tools.ustr(smtp_server), 'error_smtp_server': tools.ustr(smtp_server),
@ -212,7 +206,6 @@ class MailTrackingEmail(models.Model):
}) })
return True return True
@api.multi
def tracking_img_add(self, email): def tracking_img_add(self, email):
self.ensure_one() self.ensure_one()
tracking_url = self._get_mail_tracking_img() tracking_url = self._get_mail_tracking_img()
@ -240,7 +233,6 @@ class MailTrackingEmail(models.Model):
}) })
return True return True
@api.multi
def _tracking_sent_prepare(self, mail_server, smtp_server, message, def _tracking_sent_prepare(self, mail_server, smtp_server, message,
message_id): message_id):
self.ensure_one() self.ensure_one()
@ -286,7 +278,6 @@ class MailTrackingEmail(models.Model):
concurrent_event_ids = m_event.search(domain) concurrent_event_ids = m_event.search(domain)
return concurrent_event_ids return concurrent_event_ids
@api.multi
def event_create(self, event_type, metadata): def event_create(self, event_type, metadata):
event_ids = self.env['mail.tracking.event'] event_ids = self.env['mail.tracking.event']
for tracking_email in self: for tracking_email in self:

5
mail_tracking/models/mail_tracking_event.py

@ -5,8 +5,8 @@
import time import time
from datetime import datetime from datetime import datetime
from openerp import models, api, fields
import openerp.addons.decimal_precision as dp
from odoo import models, api, fields
import odoo.addons.decimal_precision as dp
class MailTrackingEvent(models.Model): class MailTrackingEvent(models.Model):
@ -51,7 +51,6 @@ class MailTrackingEvent(models.Model):
error_description = fields.Char(string='Error description', readonly=True) error_description = fields.Char(string='Error description', readonly=True)
error_details = fields.Text(string='Error details', readonly=True) error_details = fields.Text(string='Error details', readonly=True)
@api.multi
@api.depends('time') @api.depends('time')
def _compute_date(self): def _compute_date(self):
for email in self: for email in self:

10
mail_tracking/models/res_partner.py

@ -2,7 +2,7 @@
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api, fields
from odoo import models, api, fields
class ResPartner(models.Model): class ResPartner(models.Model):
@ -17,7 +17,6 @@ class ResPartner(models.Model):
email_score = fields.Float( email_score = fields.Float(
string="Email score", readonly=True, default=50.0) string="Email score", readonly=True, default=50.0)
@api.multi
def email_score_calculate(self): def email_score_calculate(self):
# This is not a compute method because is causing a inter-block # This is not a compute method because is causing a inter-block
# in mail_tracking_email PostgreSQL table # in mail_tracking_email PostgreSQL table
@ -28,15 +27,14 @@ class ResPartner(models.Model):
for partner in self: for partner in self:
partner.email_score = partner.tracking_email_ids.email_score() partner.email_score = partner.tracking_email_ids.email_score()
@api.one
@api.depends('tracking_email_ids') @api.depends('tracking_email_ids')
def _compute_tracking_emails_count(self): def _compute_tracking_emails_count(self):
self.tracking_emails_count = self.env['mail.tracking.email'].\
for partner in self:
partner.tracking_emails_count = self.env['mail.tracking.email'].\
search_count([ search_count([
('recipient_address', '=ilike', self.email)
('recipient_address', '=ilike', partner.email)
]) ])
@api.multi
def write(self, vals): def write(self, vals):
email = vals.get('email') email = vals.get('email')
if email is not None: if email is not None:

3
mail_tracking/static/src/js/mail_tracking.js

@ -4,7 +4,6 @@
odoo.define('mail_tracking.partner_tracking', function(require){ odoo.define('mail_tracking.partner_tracking', function(require){
"use strict"; "use strict";
var $ = require('$');
var core = require('web.core'); var core = require('web.core');
var session = require('web.session'); var session = require('web.session');
var Model = require('web.Model'); var Model = require('web.Model');
@ -26,7 +25,7 @@ chat_manager.make_message = function(data) {
ChatThread.include({ ChatThread.include({
on_tracking_partner_click: function (event) { on_tracking_partner_click: function (event) {
var partner_id = $(event.currentTarget).data('partner');
var partner_id = this.$el.find(event.currentTarget).data('partner');
var state = { var state = {
'model': 'res.partner', 'model': 'res.partner',
'id': partner_id, 'id': partner_id,

14
mail_tracking/tests/test_mail_tracking.py

@ -5,12 +5,12 @@
import mock import mock
import base64 import base64
import time import time
from openerp.tests.common import TransactionCase
from odoo.tests.common import TransactionCase
from ..controllers.main import MailTrackingController, BLANK from ..controllers.main import MailTrackingController, BLANK
mock_request = 'openerp.http.request'
mock_send_email = ('openerp.addons.base.ir.ir_mail_server.'
'ir_mail_server.send_email')
mock_request = 'odoo.http.request'
mock_send_email = ('odoo.addons.base.ir.ir_mail_server.'
'IrMailServer.send_email')
class FakeUserAgent(object): class FakeUserAgent(object):
@ -50,7 +50,7 @@ class TestMailTracking(TransactionCase):
'subject': 'Message test', 'subject': 'Message test',
'author_id': self.sender.id, 'author_id': self.sender.id,
'email_from': self.sender.email, 'email_from': self.sender.email,
'type': 'comment',
'message_type': 'comment',
'model': 'res.partner', 'model': 'res.partner',
'res_id': self.recipient.id, 'res_id': self.recipient.id,
'partner_ids': [(4, self.recipient.id)], 'partner_ids': [(4, self.recipient.id)],
@ -65,9 +65,7 @@ class TestMailTracking(TransactionCase):
self.assertTrue(tracking_email) self.assertTrue(tracking_email)
self.assertEqual(tracking_email.state, 'sent') self.assertEqual(tracking_email.state, 'sent')
# message_dict read by web interface # message_dict read by web interface
message_dict = message.message_read()
# First item in threads is message content
message_dict = message_dict['threads'][0][0]
message_dict = message.message_format()[0]
self.assertTrue(len(message_dict['partner_ids']) > 0) self.assertTrue(len(message_dict['partner_ids']) > 0)
# First partner is recipient # First partner is recipient
partner_id = message_dict['partner_ids'][0][0] partner_id = message_dict['partner_ids'][0][0]

6
mail_tracking/views/assets.xml

@ -2,8 +2,7 @@
<!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> <!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo> <odoo>
<template id="assets_backend"
<template id="assets_backend"
name="mail_tracking assets" name="mail_tracking assets"
inherit_id="web.assets_backend"> inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
@ -12,6 +11,5 @@
<script type="text/javascript" <script type="text/javascript"
src="/mail_tracking/static/src/js/mail_tracking.js"/> src="/mail_tracking/static/src/js/mail_tracking.js"/>
</xpath> </xpath>
</template>
</template>
</odoo> </odoo>
Loading…
Cancel
Save