[FIX] mass_mailing{_sms}: fix A/B testing description

Before this commit
- When we were creating an alternative version in the SMS app for A/B
  testing, we were not able to see different options like select
  winner, compare version, etc in it because of ab_testing_mailings_count
  was counting only records with type equal to mail, in method
  _compute_mailing_mail_count. So, count will never increase
  and those buttons will never be visible.
- We were not able to sent the mail manually in auto mode.
- We were able to see the 'Send winner Now' and 'Send this as Winner'
  buttons even if no a/b test mail were send.

So, with this commit
- We have added the ab_testing_sms_count compute field in utm.campaign
  and ab_testing_sms_count related field in mailing.mailing to deal
  with the above problem.
- The auto mode can now send a winner manually.
- We introduce a new compute field is_ab_test_sent for computing
  whether the any sibling mails of a/b testing are sent or not,
  depending on that we hide / show buttons.

TaskId-2713198

Part-of: odoo/odoo#88997
This commit is contained in:
Pratik Raval
2023-07-17 12:05:48 +02:00
committed by Pratik Raval (PRRA)
parent 06c70b5913
commit ee31690988
5 changed files with 31 additions and 15 deletions
@@ -117,7 +117,7 @@
</p>
<p t-else="">The winner has already been sent. Use <b>Compare Version</b> to get an overview of this A/B testing campaign.</p>
</t>
<t t-elif="mailing.ab_testing_mailings_count >= 2">
<t t-elif="ab_testing_count >= 2">
<p>
A sample of <b><t t-out="mailing.ab_testing_pc"/>% of recipients</b> will receive this version.<br/>
<t t-if="total_ab_testing_pc > 100 and mailing.active">
+10
View File
@@ -203,6 +203,7 @@ class MassMailing(models.Model):
related="campaign_id.ab_testing_winner_selection", readonly=False,
default="opened_ratio",
copy=True)
is_ab_test_sent = fields.Boolean(compute="_compute_is_ab_test_sent")
kpi_mail_required = fields.Boolean('KPI mail required', copy=False)
# statistics data
mailing_trace_ids = fields.One2many('mailing.trace', 'mass_mailing_id', string='Emails Statistics')
@@ -472,6 +473,13 @@ class MassMailing(models.Model):
mailing._get_ab_testing_description_values()
)
@api.depends('campaign_id.mailing_mail_ids.state')
def _compute_is_ab_test_sent(self):
for rec in self:
ab_testing_mailings = rec._get_ab_testing_siblings_mailings()
selected_mailings = ab_testing_mailings.filtered(lambda m: m.state == 'done')
rec.is_ab_test_sent = bool(selected_mailings)
def _get_ab_testing_description_modifying_fields(self):
return ['ab_testing_enabled', 'ab_testing_pc', 'ab_testing_schedule_datetime', 'ab_testing_winner_selection', 'campaign_id']
@@ -853,6 +861,7 @@ class MassMailing(models.Model):
raise ValueError(_("A/B test option has not been enabled"))
final_mailing = self.copy({
'ab_testing_pc': 100,
'name': _(" %(subject)s (final)", subject=self.name) # Add suffix on name to show it's the final mailing
})
self.campaign_id.ab_testing_winner_mailing_id = final_mailing
final_mailing.action_launch()
@@ -868,6 +877,7 @@ class MassMailing(models.Model):
self.ensure_one()
return {
'mailing': self,
'ab_testing_count': self.ab_testing_mailings_count,
'ab_testing_winner_selection_description': self._get_ab_testing_winner_selection()['description'],
'total_ab_testing_pc': sum([
mailing.ab_testing_pc for mailing in self._get_ab_testing_siblings_mailings()
@@ -276,22 +276,21 @@
attrs="{'required': [('ab_testing_enabled', '=', True), ('mailing_type', '=', 'mail')], 'invisible': ['|', ('ab_testing_enabled', '=', False), ('mailing_type', '!=', 'mail')], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="ab_testing_schedule_datetime"
attrs="{'required': [('ab_testing_enabled', '=', True), ('ab_testing_winner_selection', '!=', 'manual')], 'readonly': ['|', ('ab_testing_enabled', '=', False), ('state', '!=', 'draft')], 'invisible': ['|', ('ab_testing_enabled', '=', False), ('ab_testing_winner_selection', '=', 'manual')]}"/>
<field name="is_ab_test_sent" invisible="1"/>
</group>
<div>
<field name="ab_testing_mailings_count" invisible="1"/>
<field name="ab_testing_completed" invisible="1"/>
<field name="ab_testing_description" nolabel="1"/>
<div attrs="{'invisible': ['|', ('ab_testing_mailings_count', '&lt;', 2), ('ab_testing_enabled', '=', False)]}">
<div id="mailing_form_ab_buttons" attrs="{'invisible': ['|', ('ab_testing_mailings_count', '&lt;', 2), ('ab_testing_enabled', '=', False)]}">
<button name="action_compare_versions" type="object" class="btn btn-link d-block">
<i class="fa fa-bar-chart"/> Compare Version
</button>
<button name="action_duplicate" type="object" class="btn btn-link d-block" attrs="{'invisible': [('ab_testing_completed', '=', True)]}">
<i class="fa fa-copy"/> Create an Alternative
</button>
<button name="action_send_winner_mailing" type="object" class="btn btn-link d-block" attrs="{'invisible': [('ab_testing_completed', '=', True)]}">
<i class="fa fa-envelope"/> <span name="ab_test_manual" attrs="{'invisible': [('ab_testing_winner_selection', '!=', 'manual')]}">
Send this version to remaining recipients
</span> <span name="ab_test_auto" attrs="{'invisible': [('ab_testing_winner_selection', '=', 'manual')]}">
<button name="action_send_winner_mailing" type="object" class="btn btn-link d-block" attrs="{'invisible': ['|', ('is_ab_test_sent', '!=', True), '|', ('ab_testing_completed', '=', True), ('ab_testing_winner_selection', '=', 'manual')]}">
<i class="fa fa-envelope"/><span name="ab_test_auto">
Send Winner Now
</span>
</button>
@@ -52,6 +52,7 @@ class Mailing(models.Model):
ab_testing_sms_winner_selection = fields.Selection(
related="campaign_id.ab_testing_sms_winner_selection",
default="clicks_ratio", readonly=False, copy=True)
ab_testing_mailings_sms_count = fields.Integer(related="campaign_id.ab_testing_mailings_sms_count")
@api.depends('mailing_type')
def _compute_medium_id(self):
@@ -337,6 +338,7 @@ class Mailing(models.Model):
values = super()._get_ab_testing_description_values()
if self.mailing_type == 'sms':
values.update({
'ab_testing_count': self.ab_testing_mailings_sms_count,
'ab_testing_winner_selection': self.ab_testing_sms_winner_selection,
})
return values
@@ -159,6 +159,9 @@
('mail_server_available', '=', False)], 'readonly': [('state', 'in', ('sending', 'done'))]}</attribute>
</xpath>
<!-- A/B Testing -->
<xpath expr="//field[@name='ab_testing_mailings_count']" position="after">
<field name="ab_testing_mailings_sms_count" invisible="1"/>
</xpath>
<xpath expr="//field[@name='ab_testing_winner_selection']" position="after">
<label for="ab_testing_sms_winner_selection" string="Winner Selection"
attrs="{'invisible': ['|', ('ab_testing_enabled', '=', False), ('mailing_type', '!=', 'sms')]}"/>
@@ -169,19 +172,21 @@
<field name="ab_testing_schedule_datetime"
attrs="{'required': [('ab_testing_enabled', '=', True), ('ab_testing_winner_selection', '!=', 'manual'), ('ab_testing_sms_winner_selection', '!=', 'manual')], 'readonly': ['|', ('ab_testing_enabled', '=', False), ('state', '!=', 'draft')], 'invisible': ['|', '|', ('ab_testing_enabled', '=', False), ('ab_testing_winner_selection', '=', 'manual'), ('ab_testing_sms_winner_selection', '=', 'manual')]}"/>
</xpath>
<xpath expr="//span[@name='ab_test_manual']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('ab_testing_winner_selection', '!=', 'manual'),
('ab_testing_sms_winner_selection', '!=', 'manual')]}</attribute>
<xpath expr="//div[@id='mailing_form_ab_buttons']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('ab_testing_enabled', '=', False), '&amp;',
('ab_testing_mailings_count', '&lt;', 2),
('ab_testing_mailings_sms_count', '&lt;', 2)]}</attribute>
</xpath>
<xpath expr="//span[@name='ab_test_auto']" position="attributes">
<attribute name="attrs">{'invisible': [('ab_testing_winner_selection', '=', 'manual'),
('ab_testing_sms_winner_selection', '=', 'manual')]}</attribute>
</xpath>
<xpath expr="//button[@name='action_select_as_winner']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('ab_testing_completed', '!=', False), '|',
<xpath expr="//button[@name='action_send_winner_mailing']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('is_ab_test_sent', '!=', True), '|', ('ab_testing_completed', '=', True), '|',
('ab_testing_winner_selection', '=', 'manual'),
('ab_testing_sms_winner_selection', '=', 'manual')]}</attribute>
</xpath>
<xpath expr="//button[@name='action_duplicate'][hasclass('btn-primary')]" position="attributes">
<attribute name="attrs">{'invisible': ['|', '|', ('ab_testing_enabled', '=', False),
('ab_testing_mailings_count', '&gt;=', 2),
('ab_testing_mailings_sms_count', '&gt;=', 2)]}</attribute>
</xpath>
</field>
</record>