[FIX] sms, test_mail_full: make contextual action work for sms templates

While creating contextual action for an sms template, the composition mode
may be decided on the fly, based on number of records and on context the key
`default_composition_mode`, which is set to 'guess'.

It used to work before a recent refactoring[1], because the composition
mode was changed in the default_get, and was being set to appropriate
value instead of 'guess'.

After this refactoring, the composition mode is not being set in the
default_get but is being computed, so the key `default_composition_mode`
tries to set the composition_mode selection field to 'guess', which is not
available in the selection values, resulting into traceback.

This commit fixes the issue by renaming the context key(removing 'default'
prefix) to avoid setting the mode directly and instead let the compute method
decide the composition mode based on context key and number of records.

[1] - https://github.com/odoo/odoo/commit/e02137c48562d824e3e01054e31dae383e5843e2

TaskID - 2286959

closes odoo/odoo#54938

X-original-commit: 2b9ea3d93445e05cb0440aab33f2bf9e066b0fa5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Dharmraj Jhala
2020-07-27 07:27:18 +00:00
committed by Thibault Delavallée
parent dafe96b3da
commit 0e57bfd453
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ class SMSTemplate(models.Model):
'type': 'ir.actions.act_window',
'res_model': 'sms.composer',
# Add default_composition_mode to guess to determine if need to use mass or comment composer
'context': "{'default_template_id' : %d, 'default_composition_mode': 'guess', 'default_res_ids': active_ids, 'default_res_id': active_id}" % (template.id),
'context': "{'default_template_id' : %d, 'sms_composition_mode': 'guess', 'default_res_ids': active_ids, 'default_res_id': active_id}" % (template.id),
'view_mode': 'form',
'view_id': view.id,
'target': 'new',
+2 -2
View File
@@ -74,10 +74,10 @@ class SendSMS(models.TransientModel):
readonly=False, store=True, required=True)
@api.depends('res_ids_count', 'active_domain_count')
@api.depends_context('default_composition_mode')
@api.depends_context('sms_composition_mode')
def _compute_composition_mode(self):
for composer in self:
if self.env.context.get('default_composition_mode') == 'guess' or not composer.composition_mode:
if self.env.context.get('sms_composition_mode') == 'guess' or not composer.composition_mode:
if composer.res_ids_count > 1 or (composer.use_active_domain and composer.active_domain_count > 1):
composer.composition_mode = 'mass'
else:
@@ -519,7 +519,7 @@ class TestSMSComposerMass(TestMailFullCommon):
# Composer creation with context from a template context action (simulate) - comment (single recipient)
with self.with_user('employee'):
composer = self.env['sms.composer'].with_context(
default_composition_mode='guess',
sms_composition_mode='guess',
default_res_ids=[test_record_2.id],
default_res_id=test_record_2.id,
active_ids=[test_record_2.id],
@@ -541,7 +541,7 @@ class TestSMSComposerMass(TestMailFullCommon):
# Composer creation with context from a template context action (simulate) - mass (multiple recipient)
with self.with_user('employee'):
composer = self.env['sms.composer'].with_context(
default_composition_mode='guess',
sms_composition_mode='guess',
default_res_ids=[test_record_1.id, test_record_2.id],
default_res_id=test_record_1.id,
active_ids=[test_record_1.id, test_record_2.id],