Browse Source

[ADD] [database_cleanup] migrate to 11.0

pull/1408/head
Holger Brunn 7 years ago
committed by Pedro M. Baeza
parent
commit
f970118ac1
  1. 2
      database_cleanup/__openerp__.py
  2. 4
      database_cleanup/identifier_adapter.py
  3. 1
      database_cleanup/models/__init__.py
  4. 17
      database_cleanup/models/ir_model_fields.py
  5. 2
      database_cleanup/models/purge_columns.py
  6. 3
      database_cleanup/models/purge_tables.py
  7. 10
      database_cleanup/tests/test_database_cleanup.py
  8. 11
      database_cleanup/views/create_indexes.xml
  9. 13
      database_cleanup/views/purge_columns.xml
  10. 13
      database_cleanup/views/purge_data.xml
  11. 13
      database_cleanup/views/purge_menus.xml
  12. 13
      database_cleanup/views/purge_models.xml
  13. 13
      database_cleanup/views/purge_modules.xml
  14. 12
      database_cleanup/views/purge_properties.xml
  15. 13
      database_cleanup/views/purge_tables.xml

2
database_cleanup/__openerp__.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',

4
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)
)

1
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

17
database_cleanup/models/ir_model_fields.py

@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Therp BV <http://therp.nl>
# 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()

2
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,

3
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

10
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()

11
database_cleanup/views/create_indexes.xml

@ -39,14 +39,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
<field name="code">env.get('cleanup.create_indexes.line').purge()</field>
</record>
<record id="cleanup_create_indexes_line_action_value" model="ir.values">
<field name="name">Create indexes</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.create_indexes.line</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.cleanup_create_indexes_line_action')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
</record>
</odoo>

13
database_cleanup/views/purge_columns.xml

@ -37,16 +37,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
<field name="code">
env.get('cleanup.purge.line.column').purge()
</field>
</record>
<record id="action_purge_column_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.column</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_column_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
</record>
</odoo>

13
database_cleanup/views/purge_data.xml

@ -37,16 +37,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
<field name="code">
env.get('cleanup.purge.line.data').purge()
</field>
</record>
<record id="action_purge_data_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.data</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_data_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
</record>
</odoo>

13
database_cleanup/views/purge_menus.xml

@ -33,16 +33,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
<field name="code">
env.get('cleanup.purge.line.menu').purge()
</field>
</record>
<record id="action_purge_menu_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.menu</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_menu_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
</record>
</odoo>

13
database_cleanup/views/purge_models.xml

@ -33,16 +33,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
<field name="code">
env.get('cleanup.purge.line.model').purge()
</field>
</record>
<record id="action_purge_model_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.model</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_model_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
</record>
</odoo>

13
database_cleanup/views/purge_modules.xml

@ -33,16 +33,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
<field name="code">
env.get('cleanup.purge.line.module').purge()
</field>
</record>
<record id="action_purge_module_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.module</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_module_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
</record>
</odoo>

12
database_cleanup/views/purge_properties.xml

@ -33,15 +33,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
<field name="code">env.get('cleanup.purge.line.property').purge()</field>
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
</record>
<record id="action_purge_property_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.property</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_property_line')" />
</record>
</odoo>

13
database_cleanup/views/purge_tables.xml

@ -33,16 +33,7 @@
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
<field name="code">
env.get('cleanup.purge.line.table').purge()
</field>
</record>
<record id="action_purge_table_line_value" model="ir.values">
<field name="name">Purge</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">cleanup.purge.line.table</field>
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_table_line')" />
<field name="code">records.purge()</field>
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
</record>
</odoo>
Loading…
Cancel
Save