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