From ab196777c9f110d70a1106bec723394b58889e94 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 17 Jul 2018 08:17:54 +0200 Subject: [PATCH 1/5] [IMP] purge uninstalled unavailable modules in bulk --- database_cleanup/models/purge_modules.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/database_cleanup/models/purge_modules.py b/database_cleanup/models/purge_modules.py index ed8c03a0a..b0a2c297c 100644 --- a/database_cleanup/models/purge_modules.py +++ b/database_cleanup/models/purge_modules.py @@ -63,16 +63,19 @@ class CleanupPurgeWizardModule(models.TransientModel): @api.model def find(self): res = [] + purge_lines = self.env['cleanup.purge.line.module'] for module in self.env['ir.module.module'].search([]): if get_module_path(module.name): continue if module.state == 'uninstalled': - self.env['cleanup.purge.line.module'].create({ + purge_lines += self.env['cleanup.purge.line.module'].create({ 'name': module.name, - }).purge() + }) continue res.append((0, 0, {'name': module.name})) + purge_lines.purge() + if not res: raise UserError(_('No modules found to purge')) return res From 4ea883fe147f53a55f370c6c2d8dd5aac53dce5c Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 11 Feb 2019 13:39:00 +0100 Subject: [PATCH 2/5] [FIX] don't destroy values when there are empty default properties --- database_cleanup/models/purge_properties.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py index 9cd32d3f0..7a77c8943 100644 --- a/database_cleanup/models/purge_properties.py +++ b/database_cleanup/models/purge_properties.py @@ -4,6 +4,7 @@ from odoo import api, models, fields REASON_DUPLICATE = 1 REASON_DEFAULT = 2 +REASON_DEFAULT_FALSE = 3 class CleanupPurgeLineProperty(models.TransientModel): @@ -17,6 +18,7 @@ class CleanupPurgeLineProperty(models.TransientModel): reason = fields.Selection([ (REASON_DUPLICATE, 'Duplicated property'), (REASON_DEFAULT, 'Same value as default'), + (REASON_DEFAULT_FALSE, 'Empty default property'), ]) @api.multi @@ -42,6 +44,15 @@ class CleanupPurgeWizardProperty(models.TransientModel): ]) handled_field_ids = [] for prop in default_properties: + if not prop.get_by_record(): + result.append({ + 'name': '%s@%s: %s' % ( + prop.name, prop.res_id, prop.get_by_record() + ), + 'property_id': prop.id, + 'reason': REASON_DEFAULT_FALSE, + }) + continue if prop.fields_id.id in handled_field_ids: continue domain = [ From 802e88d088ddf24247fcc903f4f8d2cf9b31eb2f Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 11 Feb 2019 13:50:41 +0100 Subject: [PATCH 3/5] [FIX] show the redundant property's res_id, not the default one's --- database_cleanup/models/purge_properties.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py index 7a77c8943..7793c9bc0 100644 --- a/database_cleanup/models/purge_properties.py +++ b/database_cleanup/models/purge_properties.py @@ -87,7 +87,8 @@ class CleanupPurgeWizardProperty(models.TransientModel): for redundant_property in self.env['ir.property'].search(domain): result.append({ 'name': '%s@%s: %s' % ( - prop.name, prop.res_id, prop.get_by_record() + prop.name, redundant_property.res_id, + prop.get_by_record() ), 'property_id': redundant_property.id, 'reason': REASON_DEFAULT, From c4f7999dca17c5cbd8fca54c5f9884a795ff7005 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 14 Feb 2019 13:09:14 +0100 Subject: [PATCH 4/5] [IMP] don't break on properties pointing to unknown models --- database_cleanup/models/purge_properties.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py index 7793c9bc0..9f62762f0 100644 --- a/database_cleanup/models/purge_properties.py +++ b/database_cleanup/models/purge_properties.py @@ -5,6 +5,7 @@ from odoo import api, models, fields REASON_DUPLICATE = 1 REASON_DEFAULT = 2 REASON_DEFAULT_FALSE = 3 +REASON_UNKNOWN_MODEL = 4 class CleanupPurgeLineProperty(models.TransientModel): @@ -44,10 +45,22 @@ class CleanupPurgeWizardProperty(models.TransientModel): ]) handled_field_ids = [] for prop in default_properties: - if not prop.get_by_record(): + value = None + try: + value = prop.get_by_record() + except KeyError: result.append({ 'name': '%s@%s: %s' % ( - prop.name, prop.res_id, prop.get_by_record() + prop.name, prop.res_id, value, + ), + 'property_id': prop.id, + 'reason': REASON_UNKNOWN_MODEL, + }) + continue + if not value: + result.append({ + 'name': '%s@%s: %s' % ( + prop.name, prop.res_id, value, ), 'property_id': prop.id, 'reason': REASON_DEFAULT_FALSE, From 1bcb71dcec4c32be180585ef8d79fc283e9fd218 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 25 Feb 2019 11:35:38 +0100 Subject: [PATCH 5/5] fixup! [IMP] don't break on properties pointing to unknown models --- database_cleanup/models/purge_properties.py | 1 + 1 file changed, 1 insertion(+) diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py index 9f62762f0..61d7dd9f7 100644 --- a/database_cleanup/models/purge_properties.py +++ b/database_cleanup/models/purge_properties.py @@ -20,6 +20,7 @@ class CleanupPurgeLineProperty(models.TransientModel): (REASON_DUPLICATE, 'Duplicated property'), (REASON_DEFAULT, 'Same value as default'), (REASON_DEFAULT_FALSE, 'Empty default property'), + (REASON_UNKNOWN_MODEL, 'Unknown model'), ]) @api.multi