[MIG] adapt code for V16
parent
ec344edf73
commit
603aeb4923
database_cleanup
models
readme
security
|
@ -82,6 +82,7 @@ Contributors
|
|||
* Holger Brunn <hbrunn@therp.nl>
|
||||
* Stéphane Mangin <stephane.mangin@camptocamp.com>
|
||||
* Mark Schuit <mark@gig.solutions>
|
||||
* Andrea Stirpe
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"views/purge_menus.xml",
|
||||
"views/purge_modules.xml",
|
||||
"views/purge_models.xml",
|
||||
'views/purge_fields.xml',
|
||||
"views/purge_fields.xml",
|
||||
"views/purge_columns.xml",
|
||||
"views/purge_tables.xml",
|
||||
"views/purge_data.xml",
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
# Copyright 2014-2016 Therp BV <http://therp.nl>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
# pylint: disable=consider-merging-classes-inherited
|
||||
from odoo import _, api, models, fields
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
|
||||
|
||||
from ..identifier_adapter import IdentifierAdapter
|
||||
|
||||
|
||||
class CleanupPurgeLineField(models.TransientModel):
|
||||
_inherit = 'cleanup.purge.line'
|
||||
_name = 'cleanup.purge.line.field'
|
||||
_description = 'Purge fields'
|
||||
_inherit = "cleanup.purge.line"
|
||||
_name = "cleanup.purge.line.field"
|
||||
_description = "Purge fields"
|
||||
|
||||
wizard_id = fields.Many2one(
|
||||
'cleanup.purge.wizard.field', 'Purge Wizard', readonly=True
|
||||
"cleanup.purge.wizard.field", "Purge Wizard", readonly=True
|
||||
)
|
||||
field_id = fields.Many2one(
|
||||
comodel_name='ir.model.fields',
|
||||
string='Field',
|
||||
comodel_name="ir.model.fields",
|
||||
string="Field",
|
||||
)
|
||||
model_id = fields.Many2one(
|
||||
comodel_name="ir.model",
|
||||
|
@ -31,24 +33,24 @@ class CleanupPurgeLineField(models.TransientModel):
|
|||
store=True,
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def purge(self):
|
||||
"""
|
||||
Unlink fields upon manual confirmation.
|
||||
"""
|
||||
context_flags = {
|
||||
MODULE_UNINSTALL_FLAG: True,
|
||||
'purge': True,
|
||||
"purge": True,
|
||||
}
|
||||
if self:
|
||||
objs = self
|
||||
else:
|
||||
objs = self.env['cleanup.purge.line.action']\
|
||||
.browse(self._context.get('active_ids'))
|
||||
objs = self.env["cleanup.purge.line.action"].browse(
|
||||
self._context.get("active_ids")
|
||||
)
|
||||
to_unlink = objs.filtered(lambda x: not x.purged and x.field_id)
|
||||
self.logger.info('Purging field entries:')
|
||||
self.logger.info("Purging field entries:")
|
||||
for rec in to_unlink:
|
||||
self.logger.info(' - %s.%s', rec.model_name, rec.field_id.name)
|
||||
self.logger.info(" - %s.%s", rec.model_name, rec.field_id.name)
|
||||
field_id = rec.with_context(**context_flags).field_id
|
||||
model = self.env[rec.model_name]
|
||||
table_name = model._table
|
||||
|
@ -71,17 +73,18 @@ class CleanupPurgeLineField(models.TransientModel):
|
|||
# Inheritance such as stock.picking.in from stock.picking
|
||||
# can lead to double attempts at removal
|
||||
self.env.cr.execute(
|
||||
'SELECT count(attname) FROM pg_attribute '
|
||||
'WHERE attrelid = '
|
||||
'( SELECT oid FROM pg_class WHERE relname = %s ) '
|
||||
'AND attname = %s', (table, column)
|
||||
"SELECT count(attname) FROM pg_attribute "
|
||||
"WHERE attrelid = "
|
||||
"( SELECT oid FROM pg_class WHERE relname = %s ) "
|
||||
"AND attname = %s",
|
||||
(table, column),
|
||||
)
|
||||
if not self.env.cr.fetchone()[0]:
|
||||
return
|
||||
self.logger.info('Dropping column %s from table %s', column, table)
|
||||
self.logger.info("Dropping column %s from table %s", column, table)
|
||||
self.env.cr.execute(
|
||||
'ALTER TABLE %s DROP COLUMN %s',
|
||||
(IdentifierAdapter(table), IdentifierAdapter(column))
|
||||
"ALTER TABLE %s DROP COLUMN %s",
|
||||
(IdentifierAdapter(table), IdentifierAdapter(column)),
|
||||
)
|
||||
# we need this commit because the ORM will deadlock if
|
||||
# we still have a pending transaction
|
||||
|
@ -89,9 +92,9 @@ class CleanupPurgeLineField(models.TransientModel):
|
|||
|
||||
|
||||
class CleanupPurgeWizardField(models.TransientModel):
|
||||
_inherit = 'cleanup.purge.wizard'
|
||||
_name = 'cleanup.purge.wizard.field'
|
||||
_description = 'Purge fields'
|
||||
_inherit = "cleanup.purge.wizard"
|
||||
_name = "cleanup.purge.wizard.field"
|
||||
_description = "Purge fields"
|
||||
|
||||
@api.model
|
||||
def find(self):
|
||||
|
@ -100,24 +103,29 @@ class CleanupPurgeWizardField(models.TransientModel):
|
|||
"""
|
||||
res = []
|
||||
ignored_fields = models.MAGIC_COLUMNS + [
|
||||
"display_name", models.BaseModel.CONCURRENCY_CHECK_FIELD
|
||||
"display_name",
|
||||
models.BaseModel.CONCURRENCY_CHECK_FIELD,
|
||||
]
|
||||
domain = [('state', '=', 'base')]
|
||||
for field_id in self.env['ir.model.fields'].search(domain):
|
||||
domain = [("state", "=", "base")]
|
||||
for field_id in self.env["ir.model.fields"].search(domain):
|
||||
if field_id.name in ignored_fields:
|
||||
continue
|
||||
model = self.env[field_id.model_id.model]
|
||||
if field_id.name not in model._fields.keys():
|
||||
res.append(
|
||||
(0, 0, {
|
||||
'name': field_id.name,
|
||||
'field_id': field_id.id,
|
||||
})
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": field_id.name,
|
||||
"field_id": field_id.id,
|
||||
},
|
||||
)
|
||||
)
|
||||
if not res:
|
||||
raise UserError(_('No orphaned fields found'))
|
||||
raise UserError(_("No orphaned fields found"))
|
||||
return res
|
||||
|
||||
purge_line_ids = fields.One2many(
|
||||
'cleanup.purge.line.field', 'wizard_id', 'Fields to purge'
|
||||
"cleanup.purge.line.field", "wizard_id", "Fields to purge"
|
||||
)
|
||||
|
|
|
@ -2,3 +2,5 @@
|
|||
* Holger Brunn <hbrunn@therp.nl>
|
||||
* Stéphane Mangin <stephane.mangin@camptocamp.com>
|
||||
* Mark Schuit <mark@gig.solutions>
|
||||
* `360ERP <https://www.360erp.com>`_:
|
||||
* Andrea Stirpe
|
||||
|
|
|
@ -5,6 +5,8 @@ access_cleanup_purge_line_module,access_cleanup_purge_line_module,model_cleanup_
|
|||
access_cleanup_purge_wizard_module,access_cleanup_purge_wizard_module,model_cleanup_purge_wizard_module,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_line_model,access_cleanup_purge_line_model,model_cleanup_purge_line_model,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_wizard_model,access_cleanup_purge_wizard_model,model_cleanup_purge_wizard_model,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_line_field,access_cleanup_purge_line_field,model_cleanup_purge_line_field,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_wizard_field,access_cleanup_purge_wizard_field,model_cleanup_purge_wizard_field,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_line_column,access_cleanup_purge_line_column,model_cleanup_purge_line_column,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_wizard_column,access_cleanup_purge_wizard_column,model_cleanup_purge_wizard_column,base.group_user,1,1,1,1
|
||||
access_cleanup_purge_line_table,access_cleanup_purge_line_table,model_cleanup_purge_line_table,base.group_user,1,1,1,1
|
||||
|
|
|
|
@ -26,7 +26,7 @@
|
|||
<field name="name">Purge obsolete fields</field>
|
||||
<field name="sequence" eval="25" />
|
||||
<field name="action" ref="action_purge_fields" />
|
||||
<field name="parent_id" ref="menu_database_cleanup"/>
|
||||
<field name="parent_id" ref="menu_database_cleanup" />
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.menu" id="menu_purge_columns">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="purge_fields_view" model="ir.ui.view">
|
||||
<field name="model">cleanup.purge.wizard.field</field>
|
||||
|
@ -13,7 +13,10 @@
|
|||
<field name="name">Purge models</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_field" />
|
||||
<field
|
||||
name="model_id"
|
||||
ref="database_cleanup.model_cleanup_purge_wizard_field"
|
||||
/>
|
||||
<field name="code">
|
||||
action = env.get('cleanup.purge.wizard.field').get_wizard_action()
|
||||
</field>
|
||||
|
@ -38,6 +41,9 @@
|
|||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_field" />
|
||||
<field name="code">records.purge()</field>
|
||||
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_field" />
|
||||
<field
|
||||
name="binding_model_id"
|
||||
ref="database_cleanup.model_cleanup_purge_line_field"
|
||||
/>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue