diff --git a/database_cleanup/models/purge_models.py b/database_cleanup/models/purge_models.py index b2c40b93d..c2796c09a 100644 --- a/database_cleanup/models/purge_models.py +++ b/database_cleanup/models/purge_models.py @@ -73,6 +73,13 @@ class CleanupPurgeLineModel(models.TransientModel): self.env['ir.model.constraint'].search([ ('model', '=', line.name), ]).unlink() + cronjobs = self.env['ir.cron'].with_context( + active_test=False + ).search([ + ('model_id.model', '=', line.name), + ]) + if cronjobs: + cronjobs.unlink() relations = self.env['ir.model.fields'].search([ ('relation', '=', row[1]), ]).with_context(**context_flags) diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index d1d1c795c..e2f1a6deb 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -73,6 +73,11 @@ class TestDatabaseCleanup(TransactionCase): 'name': 'Database cleanup test model', 'model': 'x_database.cleanup.test.model', }) + # and a cronjob for it + cronjob = self.env['ir.cron'].create({ + 'name': 'testcronjob', + 'model_id': self.models.id, + }) self.env.cr.execute( 'insert into ir_attachment (name, res_model, res_id, type) values ' "('test attachment', 'database.cleanup.test.model', 42, 'binary')") @@ -83,6 +88,7 @@ class TestDatabaseCleanup(TransactionCase): self.assertFalse(self.env['ir.model'].search([ ('model', '=', 'x_database.cleanup.test.model'), ])) + self.assertFalse(cronjob.exists()) # create an orphaned table self.env.cr.execute('create table database_cleanup_test (test int)')