From 0e57bfd45392fc2107e58aca8cd767c0c5c2c12e Mon Sep 17 00:00:00 2001 From: Dharmraj Jhala Date: Wed, 1 Jul 2020 11:13:00 +0000 Subject: [PATCH] [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) --- addons/sms/models/sms_template.py | 2 +- addons/sms/wizard/sms_composer.py | 4 ++-- addons/test_mail_full/tests/test_sms_composer.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py index f3e777f77c4..be402f02a37 100644 --- a/addons/sms/models/sms_template.py +++ b/addons/sms/models/sms_template.py @@ -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', diff --git a/addons/sms/wizard/sms_composer.py b/addons/sms/wizard/sms_composer.py index 7467d99a21a..044ce248ce1 100644 --- a/addons/sms/wizard/sms_composer.py +++ b/addons/sms/wizard/sms_composer.py @@ -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: diff --git a/addons/test_mail_full/tests/test_sms_composer.py b/addons/test_mail_full/tests/test_sms_composer.py index cee5e969c1a..8a36d0ce2e5 100644 --- a/addons/test_mail_full/tests/test_sms_composer.py +++ b/addons/test_mail_full/tests/test_sms_composer.py @@ -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],