From cbdabc0acdb5fb0be54fe9eba33674aa5a4445a7 Mon Sep 17 00:00:00 2001 From: mreficent Date: Mon, 16 Mar 2020 20:06:23 +0100 Subject: [PATCH] [FIX] database_cleanup: only uninstall installed modules Due to https://github.com/odoo/odoo/commit/0ca82f2a75b7c2559fd77eed4b65bf6e7bc46576 --- .../{__openerp__.py => __manifest__.py} | 0 database_cleanup/models/purge_modules.py | 13 +++++++++++-- database_cleanup/tests/test_database_cleanup.py | 7 +++---- 3 files changed, 14 insertions(+), 6 deletions(-) rename database_cleanup/{__openerp__.py => __manifest__.py} (100%) diff --git a/database_cleanup/__openerp__.py b/database_cleanup/__manifest__.py similarity index 100% rename from database_cleanup/__openerp__.py rename to database_cleanup/__manifest__.py diff --git a/database_cleanup/models/purge_modules.py b/database_cleanup/models/purge_modules.py index 0cb799d22..c099e390d 100644 --- a/database_cleanup/models/purge_modules.py +++ b/database_cleanup/models/purge_modules.py @@ -48,10 +48,19 @@ class CleanupPurgeLineModule(models.TransientModel): return True self.logger.info('Purging modules %s', ', '.join(module_names)) modules.filtered( - lambda x: x.state not in ('uninstallable', 'uninstalled') + lambda x: x.state == 'to install' + ).write({'state': 'uninstalled'}) + modules.filtered( + lambda x: x.state in ('to upgrade', 'to remove') + ).write({'state': 'installed'}) + modules.filtered( + lambda x: x.state == 'installed' and x.name != 'base' ).button_immediate_uninstall() modules.refresh() - modules.unlink() + modules.filtered( + lambda x: x.state not in ( + 'installed', 'to upgrade', 'to remove', 'to install') + ).unlink() return self.write({'purged': True}) diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index 705b844f0..b05c804ea 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -3,12 +3,11 @@ from psycopg2 import ProgrammingError from odoo.modules.registry import Registry from odoo.tools import config, mute_logger -from odoo.tests.common import TransactionCase, at_install, post_install +from odoo.tests.common import TransactionCase, tagged -# Use post_install to get all models loaded more info: odoo/odoo#13458 -@at_install(False) -@post_install(True) +# Use post_install to get all models loaded, more info: odoo/odoo#13458 +@tagged('post_install', '-at_install') class TestDatabaseCleanup(TransactionCase): def setUp(self): super(TestDatabaseCleanup, self).setUp()