From c5f8e18b4d4c0a14353b2988cf5a4a6bb21b8a4a Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 11 Feb 2019 13:39:00 +0100 Subject: [PATCH 1/4] [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 7adbf440b..82936d4b5 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 e05997884eca4f6d92a86351ac1d0ab08d0fe6f4 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 11 Feb 2019 13:50:41 +0100 Subject: [PATCH 2/4] [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 82936d4b5..0e362a3eb 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 128cf47212d21a6e9c986e74054696bd54b35583 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 11 Feb 2019 14:02:51 +0100 Subject: [PATCH 3/4] [FIX] actually purge selected lines when purging selections --- database_cleanup/views/create_indexes.xml | 2 +- database_cleanup/views/purge_columns.xml | 4 +--- database_cleanup/views/purge_data.xml | 4 +--- database_cleanup/views/purge_menus.xml | 4 +--- database_cleanup/views/purge_models.xml | 4 +--- database_cleanup/views/purge_modules.xml | 4 +--- database_cleanup/views/purge_properties.xml | 2 +- database_cleanup/views/purge_tables.xml | 4 +--- 8 files changed, 8 insertions(+), 20 deletions(-) diff --git a/database_cleanup/views/create_indexes.xml b/database_cleanup/views/create_indexes.xml index 714db354a..36ef1f3c1 100644 --- a/database_cleanup/views/create_indexes.xml +++ b/database_cleanup/views/create_indexes.xml @@ -39,7 +39,7 @@ ir.actions.server code - env.get('cleanup.create_indexes.line').purge() + records.purge() diff --git a/database_cleanup/views/purge_columns.xml b/database_cleanup/views/purge_columns.xml index 23eefaaef..850e08166 100644 --- a/database_cleanup/views/purge_columns.xml +++ b/database_cleanup/views/purge_columns.xml @@ -37,9 +37,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.column').purge() - + records.purge() diff --git a/database_cleanup/views/purge_data.xml b/database_cleanup/views/purge_data.xml index c6804a38a..99c192c1b 100644 --- a/database_cleanup/views/purge_data.xml +++ b/database_cleanup/views/purge_data.xml @@ -37,9 +37,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.data').purge() - + records.purge() diff --git a/database_cleanup/views/purge_menus.xml b/database_cleanup/views/purge_menus.xml index 0757088d4..e12d811c2 100644 --- a/database_cleanup/views/purge_menus.xml +++ b/database_cleanup/views/purge_menus.xml @@ -33,9 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.menu').purge() - + records.purge() diff --git a/database_cleanup/views/purge_models.xml b/database_cleanup/views/purge_models.xml index b0dfa7e0d..9f3d4aade 100644 --- a/database_cleanup/views/purge_models.xml +++ b/database_cleanup/views/purge_models.xml @@ -33,9 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.model').purge() - + records.purge() diff --git a/database_cleanup/views/purge_modules.xml b/database_cleanup/views/purge_modules.xml index 549563a96..dc8ee7027 100644 --- a/database_cleanup/views/purge_modules.xml +++ b/database_cleanup/views/purge_modules.xml @@ -33,9 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.module').purge() - + records.purge() diff --git a/database_cleanup/views/purge_properties.xml b/database_cleanup/views/purge_properties.xml index f1a472293..16bb988fc 100644 --- a/database_cleanup/views/purge_properties.xml +++ b/database_cleanup/views/purge_properties.xml @@ -33,7 +33,7 @@ ir.actions.server code - env.get('cleanup.purge.line.property').purge() + records.purge() diff --git a/database_cleanup/views/purge_tables.xml b/database_cleanup/views/purge_tables.xml index d7d5a849f..80cff1fee 100644 --- a/database_cleanup/views/purge_tables.xml +++ b/database_cleanup/views/purge_tables.xml @@ -33,9 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.table').purge() - + records.purge() From 0f5c4948cb8f621323158349786ad87025296361 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 14 Feb 2019 13:09:14 +0100 Subject: [PATCH 4/4] [IMP] don't break on properties pointing to unknown models --- database_cleanup/models/purge_properties.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py index 0e362a3eb..3897862cc 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): @@ -19,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 @@ -44,10 +46,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,