From 9574b71a87271fb776174318164058e554944f1d Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 3 Oct 2017 17:26:19 +0200 Subject: [PATCH] [ADD] [database_cleanup] migrate to 11.0 --- database_cleanup/__manifest__.py | 2 +- database_cleanup/identifier_adapter.py | 4 +++- database_cleanup/models/__init__.py | 1 - database_cleanup/models/ir_model_fields.py | 17 ----------------- database_cleanup/models/purge_columns.py | 2 +- database_cleanup/models/purge_tables.py | 3 +-- database_cleanup/tests/test_database_cleanup.py | 10 +++++----- database_cleanup/views/create_indexes.xml | 11 ++--------- database_cleanup/views/purge_columns.xml | 13 ++----------- database_cleanup/views/purge_data.xml | 13 ++----------- database_cleanup/views/purge_menus.xml | 13 ++----------- database_cleanup/views/purge_models.xml | 13 ++----------- database_cleanup/views/purge_modules.xml | 13 ++----------- database_cleanup/views/purge_properties.xml | 12 ++---------- database_cleanup/views/purge_tables.xml | 13 ++----------- 15 files changed, 27 insertions(+), 113 deletions(-) delete mode 100644 database_cleanup/models/ir_model_fields.py diff --git a/database_cleanup/__manifest__.py b/database_cleanup/__manifest__.py index f3cc47001..192483da0 100644 --- a/database_cleanup/__manifest__.py +++ b/database_cleanup/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Database cleanup', - 'version': '10.0.1.0.0', + 'version': '11.0.1.0.0', 'author': "Therp BV,Odoo Community Association (OCA)", 'depends': ['base'], 'license': 'AGPL-3', diff --git a/database_cleanup/identifier_adapter.py b/database_cleanup/identifier_adapter.py index 280fcd920..008044689 100644 --- a/database_cleanup/identifier_adapter.py +++ b/database_cleanup/identifier_adapter.py @@ -20,4 +20,6 @@ class IdentifierAdapter(ISQLQuote): format_string = '"%s"' if not self.quote: format_string = '%s' - return format_string % filter(is_identifier_char, self.identifier) + return format_string % ''.join( + filter(is_identifier_char, self.identifier) + ) diff --git a/database_cleanup/models/__init__.py b/database_cleanup/models/__init__.py index f9de433cf..fcca884ef 100644 --- a/database_cleanup/models/__init__.py +++ b/database_cleanup/models/__init__.py @@ -5,6 +5,5 @@ from . import purge_columns from . import purge_tables from . import purge_data from . import purge_menus -from . import ir_model_fields from . import create_indexes from . import purge_properties diff --git a/database_cleanup/models/ir_model_fields.py b/database_cleanup/models/ir_model_fields.py deleted file mode 100644 index ffb2988ac..000000000 --- a/database_cleanup/models/ir_model_fields.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2014-2016 Therp BV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, models - - -class IrModelFields(models.Model): - _inherit = 'ir.model.fields' - - # In case of purging it means the model does not exist anymore in - # installed module. In this specific case, we need to avoid to check - # if fields can be removed as it would fail. - @api.multi - def _prepare_update(self): - if self.env.context.get('purge'): - self -= self.filtered(lambda x: x.model not in self.env.registry) - return super(IrModelFields, self)._prepare_update() diff --git a/database_cleanup/models/purge_columns.py b/database_cleanup/models/purge_columns.py index be2918913..6050ae2dd 100644 --- a/database_cleanup/models/purge_columns.py +++ b/database_cleanup/models/purge_columns.py @@ -117,7 +117,7 @@ class CleanupPurgeWizardColumn(models.TransientModel): model_pool._table, (model.id, []) )[1].append(model_pool) - for table, model_spec in table2model.iteritems(): + for table, model_spec in table2model.items(): for column in self.get_orphaned_columns(model_spec[1]): res.append((0, 0, { 'name': column, diff --git a/database_cleanup/models/purge_tables.py b/database_cleanup/models/purge_tables.py index 3ed41c81d..808c42490 100644 --- a/database_cleanup/models/purge_tables.py +++ b/database_cleanup/models/purge_tables.py @@ -81,8 +81,7 @@ class CleanupPurgeWizardTable(models.TransientModel): Search for tables that cannot be instantiated. Ignore views for now. """ - # Start out with known tables with no model - known_tables = ['wkf_witm_trans'] + known_tables = [] for model in self.env['ir.model'].search([]): if model.model not in self.env: continue diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index 04fc8e06f..75265ddb9 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from psycopg2 import ProgrammingError from odoo.modules.registry import Registry -from odoo.tools import config +from odoo.tools import config, mute_logger from odoo.tests.common import TransactionCase, at_install, post_install @@ -52,7 +52,8 @@ class TestDatabaseCleanup(TransactionCase): # must be removed by the wizard with self.assertRaises(ProgrammingError): with self.env.registry.cursor() as cr: - cr.execute('select database_cleanup_test from res_partner') + with mute_logger('odoo.sql_db'): + cr.execute('select database_cleanup_test from res_partner') # create a data entry pointing nowhere self.env.cr.execute('select max(id) + 1 from res_users') @@ -77,8 +78,6 @@ class TestDatabaseCleanup(TransactionCase): 'insert into ir_attachment (name, res_model, res_id, type) values ' "('test attachment', 'database.cleanup.test.model', 42, 'binary')") self.env.registry.models.pop('x_database.cleanup.test.model') - self.env.registry._fields_by_model.pop( - 'x_database.cleanup.test.model') purge_models = self.env['cleanup.purge.wizard.model'].create({}) purge_models.purge_all() # must be removed by the wizard @@ -112,7 +111,8 @@ class TestDatabaseCleanup(TransactionCase): purge_tables.purge_all() with self.assertRaises(ProgrammingError): with self.env.registry.cursor() as cr: - cr.execute('select * from database_cleanup_test') + with mute_logger('odoo.sql_db'): + cr.execute('select * from database_cleanup_test') def tearDown(self): super(TestDatabaseCleanup, self).tearDown() diff --git a/database_cleanup/views/create_indexes.xml b/database_cleanup/views/create_indexes.xml index 714db354a..d0aa21485 100644 --- a/database_cleanup/views/create_indexes.xml +++ b/database_cleanup/views/create_indexes.xml @@ -39,14 +39,7 @@ ir.actions.server code - env.get('cleanup.create_indexes.line').purge() - - - - Create indexes - action - client_action_multi - cleanup.create_indexes.line - + records.purge() + diff --git a/database_cleanup/views/purge_columns.xml b/database_cleanup/views/purge_columns.xml index 23eefaaef..e8c40565d 100644 --- a/database_cleanup/views/purge_columns.xml +++ b/database_cleanup/views/purge_columns.xml @@ -37,16 +37,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.column').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.column - + records.purge() + diff --git a/database_cleanup/views/purge_data.xml b/database_cleanup/views/purge_data.xml index c6804a38a..42cd2707b 100644 --- a/database_cleanup/views/purge_data.xml +++ b/database_cleanup/views/purge_data.xml @@ -37,16 +37,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.data').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.data - + records.purge() + diff --git a/database_cleanup/views/purge_menus.xml b/database_cleanup/views/purge_menus.xml index 0757088d4..09e6582fa 100644 --- a/database_cleanup/views/purge_menus.xml +++ b/database_cleanup/views/purge_menus.xml @@ -33,16 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.menu').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.menu - + records.purge() + diff --git a/database_cleanup/views/purge_models.xml b/database_cleanup/views/purge_models.xml index b0dfa7e0d..a72e18977 100644 --- a/database_cleanup/views/purge_models.xml +++ b/database_cleanup/views/purge_models.xml @@ -33,16 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.model').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.model - + records.purge() + diff --git a/database_cleanup/views/purge_modules.xml b/database_cleanup/views/purge_modules.xml index 549563a96..d105c7b75 100644 --- a/database_cleanup/views/purge_modules.xml +++ b/database_cleanup/views/purge_modules.xml @@ -33,16 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.module').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.module - + records.purge() + diff --git a/database_cleanup/views/purge_properties.xml b/database_cleanup/views/purge_properties.xml index f1a472293..ca03cf70a 100644 --- a/database_cleanup/views/purge_properties.xml +++ b/database_cleanup/views/purge_properties.xml @@ -33,15 +33,7 @@ ir.actions.server code - env.get('cleanup.purge.line.property').purge() + records.purge() + - - - Purge - action - client_action_multi - cleanup.purge.line.property - - - diff --git a/database_cleanup/views/purge_tables.xml b/database_cleanup/views/purge_tables.xml index d7d5a849f..d255e77c1 100644 --- a/database_cleanup/views/purge_tables.xml +++ b/database_cleanup/views/purge_tables.xml @@ -33,16 +33,7 @@ ir.actions.server code - - env.get('cleanup.purge.line.table').purge() - - - - - Purge - action - client_action_multi - cleanup.purge.line.table - + records.purge() +