from odoo.tests import TransactionCase class TestServerAction(TransactionCase): """Lifecycle of the generated contextual server action.""" def test_unlink_removes_server_action(self): """Deleting a template removes its generated server action, instead of leaving an orphaned action browsing a dead record.""" template = self.env["docuseal.template"].create({ "name": "Contract", "template_id": 123, }) template.action_create_server_action() action = template.server_action_id self.assertTrue(action.exists()) template.unlink() self.assertFalse(action.exists()) def test_create_server_action_is_idempotent(self): """Creating the contextual action twice updates the existing action instead of generating a duplicate.""" template = self.env["docuseal.template"].create({ "name": "Contract", "template_id": 456, }) template.action_create_server_action() first_action = template.server_action_id template.action_create_server_action() self.assertEqual(template.server_action_id, first_action) self.assertEqual( self.env["ir.actions.server"].search_count([ ("name", "=", "Request signature (Contract)"), ]), 1, )