[FIX] mass_mailing: send at least one a/b test if possible
When there is not enough recipients for the A/B testing percentage, we pick a minimum of one recipients (if there is at least one) to avoid sending a/b test to no one. task-2713198 closes odoo/odoo#107488 X-original-commit: e1fa7b10250efc790452f02490ab84d2183698ff Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
committed by
Aurélien Warnon
parent
6bfe126313
commit
348265db3d
@@ -261,8 +261,8 @@ class MassMailing(models.Model):
|
||||
def _compute_total(self):
|
||||
for mass_mailing in self:
|
||||
total = self.env[mass_mailing.mailing_model_real].search_count(mass_mailing._parse_mailing_domain())
|
||||
if mass_mailing.ab_testing_pc < 100:
|
||||
total = int(total / 100.0 * mass_mailing.ab_testing_pc)
|
||||
if total and mass_mailing.ab_testing_pc < 100:
|
||||
total = max(int(total / 100.0 * mass_mailing.ab_testing_pc), 1)
|
||||
mass_mailing.total = total
|
||||
|
||||
def _compute_clicks_ratio(self):
|
||||
@@ -990,7 +990,9 @@ class MassMailing(models.Model):
|
||||
# randomly choose a fragment
|
||||
if self.ab_testing_enabled and self.ab_testing_pc < 100:
|
||||
contact_nbr = self.env[self.mailing_model_real].search_count(mailing_domain)
|
||||
topick = int(contact_nbr / 100.0 * self.ab_testing_pc)
|
||||
topick = 0
|
||||
if contact_nbr:
|
||||
topick = max(int(contact_nbr / 100.0 * self.ab_testing_pc), 1)
|
||||
if self.campaign_id and self.ab_testing_enabled:
|
||||
already_mailed = self.campaign_id._get_mailing_recipients()[self.campaign_id.id]
|
||||
else:
|
||||
|
||||
@@ -173,3 +173,22 @@ class TestMailingABTesting(MassMailCommon):
|
||||
self.ab_testing_mailing_ids.invalidate_recordset()
|
||||
winner_mailing = self.ab_testing_campaign.mailing_mail_ids.filtered(lambda mailing: mailing.ab_testing_pc == 100)
|
||||
self.assertEqual(winner_mailing.subject, 'A/B Testing V2')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
@users('user_marketing')
|
||||
def test_mailing_ab_testing_minimum_participants(self):
|
||||
""" Test that it should send minimum one mail(if possible) when ab_testing_pc is too small compared to the amount of targeted records."""
|
||||
mailing_list = self._create_mailing_list_of_x_contacts(10)
|
||||
ab_testing = self.env['mailing.mailing'].create({
|
||||
'subject': 'A/B Testing SMS V1',
|
||||
'contact_list_ids': mailing_list.ids,
|
||||
'ab_testing_enabled': True,
|
||||
'ab_testing_pc': 2,
|
||||
'ab_testing_schedule_datetime': datetime.now(),
|
||||
'mailing_type': 'mail',
|
||||
'campaign_id': self.ab_testing_campaign.id,
|
||||
})
|
||||
with self.mock_mail_gateway():
|
||||
ab_testing.action_send_mail()
|
||||
self.assertEqual(ab_testing.state, 'done')
|
||||
self.assertEqual(len(self._mails), 1)
|
||||
|
||||
Reference in New Issue
Block a user