[IMP] mail_tracking: email score performance (#299)
This commit is contained in:
parent
8d9cebdf99
commit
f1259fc0ec
@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Email tracking",
|
"name": "Email tracking",
|
||||||
"summary": "Email tracking system for all mails sent",
|
"summary": "Email tracking system for all mails sent",
|
||||||
"version": "11.0.1.0.0",
|
"version": "11.0.1.1.0",
|
||||||
"category": "Social Network",
|
"category": "Social Network",
|
||||||
"website": "http://github.com/OCA/social",
|
"website": "http://github.com/OCA/social",
|
||||||
"author": "Tecnativa, "
|
"author": "Tecnativa, "
|
||||||
|
@ -103,10 +103,12 @@ class MailTrackingEmail(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def email_score_from_email(self, email):
|
def email_score_from_email(self, email):
|
||||||
if email:
|
if not email:
|
||||||
return self.search([
|
|
||||||
('recipient_address', '=', email.lower())]).email_score()
|
|
||||||
return 0.
|
return 0.
|
||||||
|
data = self.read_group([('recipient_address', '=', email.lower())],
|
||||||
|
['recipient_address', 'state'], ['state'])
|
||||||
|
mapped_data = {state['state']: state['state_count'] for state in data}
|
||||||
|
return self.with_context(mt_states=mapped_data).email_score()
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _email_score_weights(self):
|
def _email_score_weights(self):
|
||||||
@ -124,7 +126,7 @@ class MailTrackingEmail(models.Model):
|
|||||||
|
|
||||||
def email_score(self):
|
def email_score(self):
|
||||||
"""Default email score algorimth. Ready to be inherited
|
"""Default email score algorimth. Ready to be inherited
|
||||||
|
It can receive a recordset or mapped states dictionary via context.
|
||||||
Must return a value beetwen 0.0 and 100.0
|
Must return a value beetwen 0.0 and 100.0
|
||||||
- Bad reputation: Value between 0 and 50.0
|
- Bad reputation: Value between 0 and 50.0
|
||||||
- Unknown reputation: Value 50.0
|
- Unknown reputation: Value 50.0
|
||||||
@ -132,6 +134,11 @@ class MailTrackingEmail(models.Model):
|
|||||||
"""
|
"""
|
||||||
weights = self._email_score_weights()
|
weights = self._email_score_weights()
|
||||||
score = 50.0
|
score = 50.0
|
||||||
|
states = self.env.context.get('mt_states', False)
|
||||||
|
if states:
|
||||||
|
for state in states.keys():
|
||||||
|
score += weights.get(state, 0.0) * states[state]
|
||||||
|
else:
|
||||||
for tracking in self:
|
for tracking in self:
|
||||||
score += weights.get(tracking.state, 0.0)
|
score += weights.get(tracking.state, 0.0)
|
||||||
if score > 100.0:
|
if score > 100.0:
|
||||||
|
@ -303,6 +303,15 @@ class TestMailTracking(TransactionCase):
|
|||||||
self.assertEqual('bounced', tracking.state)
|
self.assertEqual('bounced', tracking.state)
|
||||||
self.assertEqual(0.0, self.recipient.email_score)
|
self.assertEqual(0.0, self.recipient.email_score)
|
||||||
|
|
||||||
|
def test_recordset_email_score(self):
|
||||||
|
"""For backwords compatibility sake"""
|
||||||
|
trackings = self.env['mail.tracking.email']
|
||||||
|
for i in range(11):
|
||||||
|
mail, tracking = self.mail_send(self.recipient.email)
|
||||||
|
tracking.event_create('click', {})
|
||||||
|
trackings |= tracking
|
||||||
|
self.assertEqual(100.0, trackings.email_score())
|
||||||
|
|
||||||
def test_db(self):
|
def test_db(self):
|
||||||
db = self.env.cr.dbname
|
db = self.env.cr.dbname
|
||||||
controller = MailTrackingController()
|
controller = MailTrackingController()
|
||||||
|
Loading…
Reference in New Issue
Block a user