[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>