[FIX] sms: fix context action not deleted when unlink template

Issue

    - Install Calendar
    - Technical > SMS templates > Calendar reminder > Add context action
    - Calendar > Tree view > meeting > action is there
    - Delete SMS template and/or uninstall calendar_sms

    Template deleted but action still there with a traceback
    when you click on it.

Cause

    The action is never deleted.

Solution

    Delete the action when the template is deleted.

OPW-2161653

Closes #42328

closes odoo/odoo#43984

X-original-commit: eb95f06f19c60babc775de57813a293ffc35c581
Signed-off-by: Jason Van Malder (jvm) <jvm@odoo.com>
This commit is contained in:
Jason Van Malder
2020-01-27 09:06:19 +00:00
parent f9e5f58b7d
commit ee8a30a19b
2 changed files with 24 additions and 0 deletions
+4
View File
@@ -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()
@@ -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)