diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py index f106c21139f..d09dd26a703 100644 --- a/addons/sms/models/sms_template.py +++ b/addons/sms/models/sms_template.py @@ -103,3 +103,7 @@ class SMSTemplate(models.Model): def _render_template(self, template_txt, model, res_ids): """ Render the jinja template """ return self.env['mail.template']._render_template(template_txt, model, res_ids) + + def unlink(self): + self.sudo().mapped('sidebar_action_id').unlink() + return super(SMSTemplate, self).unlink() diff --git a/addons/test_mail_full/tests/test_sms_template.py b/addons/test_mail_full/tests/test_sms_template.py index fb8c1353fb1..a39edf8545f 100644 --- a/addons/test_mail_full/tests/test_sms_template.py +++ b/addons/test_mail_full/tests/test_sms_template.py @@ -68,3 +68,23 @@ class TestSmsTemplate(test_mail_full_common.TestSMSCommon, test_mail_full_common self.assertEqual(rids, test_record_2.ids) else: self.assertTrue(False, 'Should not return lang %s' % lang) + + def test_sms_template_create_and_unlink_sidebar_action(self): + ActWindow = self.env['ir.actions.act_window'] + self.sms_template.action_create_sidebar_action() + action_id = self.sms_template.sidebar_action_id.id + + self.assertNotEqual(action_id, False) + self.assertEqual(ActWindow.search_count([('id', '=', action_id)]), 1) + + self.sms_template.action_unlink_sidebar_action() + self.assertEqual(ActWindow.search_count([('id', '=', action_id)]), 0) + + def test_sms_template_unlink_with_action(self): + ActWindow = self.env['ir.actions.act_window'] + self.sms_template.action_create_sidebar_action() + action_id = self.sms_template.sidebar_action_id.id + + self.sms_template.unlink() + self.assertEqual(ActWindow.search_count([('id', '=', action_id)]), 0) +