Files
odoo_source/addons/sms/wizard/sms_composer_views.xml
T
lase@odoo.com 1767efd9be [FIX] sms: compute the body of the SMS template
Steps to reproduce:

- Go to Settings > Technical > Phone > SMS > SMS Templates
- Create a new SMS template that applies to contacts with any content
  and add context action to save the template (this will allow you to
  use this template from the contact form view).
- Go to Contacts, select any, click on the gear icon and send an SMS
  using your new SMS template.

-> Issue : the Body of the SMS template is not displayed.

Cause of the issue:

The send SMS action generates an `sms.composer wizzard that triggers a
call of the `onchange` method to compute the values of the form view of
the record from scratch.
The body of the message is computed during the snapshot1 of the onchange
of the `sms.composer`
https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/addons/web/models/models.py#L1076
by the `_compute_body` method:
https://github.com/odoo/odoo/blob/72c1a4f96a1219d98ce9b90ee54fd7297b9ab999/addons/sms/wizard/sms_composer.py#L167
To be processed correctly, this computation requires a `template_id`
(field of the sms.composer model). This `template_id` information is
present in the `self._context` of the onchange as a
'default_template_id'. However, since the template_id is not present in
the form view of the sms.composer, it is not part of the `fields_spec`
arguments of the onchange and this `default` value is not converted into
a value before the snapshot1 at this step:
https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/addons/web/models/models.py#L931-L938
Prior to Odoo 17.0, this was not a problem as the value was still
used from the context the snapshot1. However, this value is now cleaned
form the context during the snapshot1:
https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/odoo/api.py#L567
https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/odoo/tools/misc.py#L1010-L1014
As a result, there is no template_id during the call of the
`_compute_body` and the body of the message stays empty.

Fix:

In order to compute the body, correctly, we add the template_id as an
invisible field of the `sms.composer` form view so that it becomes part
of the `fields_spec` arguments of the onchange so that its default value
'default_template_id' is converted into a real value:
https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/addons/web/models/models.py#L931-L938
that will be used as an argument of the snapshot1.

opw-3733881

closes odoo/odoo#154549

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2024-03-12 10:34:44 +00:00

78 lines
4.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sms_composer_view_form" model="ir.ui.view">
<field name="name">sms.composer.view.form</field>
<field name="model">sms.composer</field>
<field name="arch" type="xml">
<form string="Send an SMS">
<!-- Single mode information (invalid number) -->
<div class="alert alert-danger text-center" role="alert"
invisible="not res_model_description or not comment_single_recipient or recipient_single_valid">
<p class="my-0">
<strong>Invalid number:</strong>
<span> make sure to set a country on the </span>
<span><field name="res_model_description"/></span>
<span> or to specify the country code.</span>
</p>
</div>
<!-- Mass mode information (res_ids versus active domain) -->
<div class="alert alert-info text-center" role="alert"
invisible="comment_single_recipient or recipient_invalid_count == 0">
<p class="my-0">
<field class="oe_inline fw-bold" name="recipient_invalid_count"/> out of
<field class="oe_inline fw-bold" name="res_ids_count"/> recipients have an invalid phone number and will not receive this text message.
</p>
</div>
<sheet>
<group>
<field name="composition_mode" invisible="1"/>
<field name="comment_single_recipient" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="res_ids" invisible="1"/>
<field name="res_model" invisible="1"/>
<field name="mass_force_send" invisible="1"/>
<field name="recipient_single_valid" invisible="1"/>
<field name="recipient_single_number" invisible="1"/>
<field name="number_field_name" invisible="1"/>
<field name="numbers" invisible="1"/>
<field name="sanitized_numbers" invisible="1"/>
<field name="template_id" invisible="1"/>
<label for="recipient_single_description" string="Recipient"
class="fw-bold"
invisible="not comment_single_recipient"/>
<div invisible="not comment_single_recipient">
<field name="recipient_single_description" class="oe_inline" invisible="not recipient_single_description"/>
<field name="recipient_single_number_itf" class="oe_inline" nolabel="1" onchange_on_keydown="True" placeholder="e.g. +1 415 555 0100"/>
</div>
<field name="body" widget="sms_widget" invisible="not comment_single_recipient or recipient_single_valid"/>
<field name="body" widget="sms_widget" invisible="comment_single_recipient and not recipient_single_valid" default_focus="1"/>
<field name="mass_keep_log" invisible="1"/>
</group>
</sheet>
<footer>
<!-- attrs doesn't work for 'disabled'-->
<button string="Send SMS" type="object" class="oe_highlight" name="action_send_sms" data-hotkey="q"
invisible="composition_mode not in ('comment', 'numbers') or not recipient_single_valid"/>
<button string="Send SMS" type="object" class="oe_highlight" name="action_send_sms" data-hotkey="q"
invisible="composition_mode not in ('comment', 'numbers') or recipient_single_valid" disabled='1'/>
<button string="Put in queue" type="object" class="oe_highlight" name="action_send_sms" data-hotkey="q"
invisible="composition_mode != 'mass'"/>
<button string="Send Now" type="object" name="action_send_sms_mass_now" data-hotkey="w"
invisible="composition_mode != 'mass'"/>
<button string="Close" class="btn btn-secondary" special="cancel" data-hotkey="x"/>
</footer>
</form>
</field>
</record>
<record id="sms_composer_action_form" model="ir.actions.act_window">
<field name="name">Send SMS Text Message</field>
<field name="res_model">sms.composer</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>