[IMP] hide unnecessary buttons in wizard
[IMP] order wizard lines by name [IMP] deal with modules whose models can't be loaded [IMP] double quotes for docstring [FIX] use exists query instead of huge in list [IMP] hide unnecessary buttons in wizard II [IMP] readability [FIX] cope with purging nonexisting modelspull/2684/head
parent
e5e76d0e94
commit
c1406ebed2
|
@ -82,8 +82,8 @@ class CleanupPurgeWizardData(orm.TransientModel):
|
|||
SELECT id FROM ir_model_data
|
||||
WHERE model = %%s
|
||||
AND res_id IS NOT NULL
|
||||
AND res_id NOT IN (
|
||||
SELECT id FROM %s)
|
||||
AND NOT EXISTS (
|
||||
SELECT id FROM %s WHERE id=ir_model_data.res_id)
|
||||
""" % self.pool[model]._table, (model,))
|
||||
data_ids += [data_row[0] for data_row in cr.fetchall()]
|
||||
data_ids += data_pool.search(
|
||||
|
|
|
@ -34,6 +34,26 @@ class IrModel(orm.Model):
|
|||
return True
|
||||
return super(IrModel, self)._drop_table(cr, uid, ids, context=context)
|
||||
|
||||
def _inherited_models(self, cr, uid, ids, field_name, arg, context=None):
|
||||
"""this function crashes for undefined models"""
|
||||
result = dict((i, []) for i in ids)
|
||||
existing_model_ids = [
|
||||
this.id for this in self.browse(cr, uid, ids, context=context)
|
||||
if self.pool.get(this.model)
|
||||
]
|
||||
super_result = super(IrModel, self)._inherited_models(
|
||||
cr, uid, existing_model_ids, field_name, arg, context=context)
|
||||
result.update(super_result)
|
||||
return result
|
||||
|
||||
def _register_hook(self, cr):
|
||||
# patch the function field instead of overwriting it
|
||||
if self._columns['inherited_model_ids']._fnct !=\
|
||||
self._inherited_models.__func__:
|
||||
self._columns['inherited_model_ids']._fnct =\
|
||||
self._inherited_models.__func__
|
||||
return super(IrModel, self)._register_hook(cr)
|
||||
|
||||
|
||||
class CleanupPurgeLineModel(orm.TransientModel):
|
||||
_inherit = 'cleanup.purge.line'
|
||||
|
|
|
@ -23,6 +23,44 @@ from openerp import pooler
|
|||
from openerp.osv import orm, fields
|
||||
from openerp.modules.module import get_module_path
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
|
||||
|
||||
|
||||
class IrModelConstraint(orm.Model):
|
||||
_inherit = 'ir.model.constraint'
|
||||
|
||||
def _module_data_uninstall(self, cr, uid, ids, context=None):
|
||||
"""this function crashes for constraints on undefined models"""
|
||||
for this in self.browse(cr, uid, ids, context=context):
|
||||
if not self.pool.get(this.model.model):
|
||||
ids.remove(this.id)
|
||||
this.unlink()
|
||||
return super(IrModelConstraint, self)._module_data_uninstall(
|
||||
cr, uid, ids, context=context)
|
||||
|
||||
|
||||
class IrModelData(orm.Model):
|
||||
_inherit = 'ir.model.data'
|
||||
|
||||
def _module_data_uninstall(self, cr, uid, modules_to_remove, context=None):
|
||||
"""this function crashes for xmlids on undefined models or fields
|
||||
referring to undefined models"""
|
||||
if context is None:
|
||||
context = {}
|
||||
ids = self.search(cr, uid, [('module', 'in', modules_to_remove)])
|
||||
for this in self.browse(cr, uid, ids, context=context):
|
||||
if this.model == 'ir.model.fields':
|
||||
ctx = context.copy()
|
||||
ctx[MODULE_UNINSTALL_FLAG] = True
|
||||
field = self.pool[this.model].browse(
|
||||
cr, uid, this.res_id, context=ctx)
|
||||
if not self.pool.get(field.model):
|
||||
this.unlink()
|
||||
continue
|
||||
if not self.pool.get(this.model):
|
||||
this.unlink()
|
||||
return super(IrModelData, self)._module_data_uninstall(
|
||||
cr, uid, modules_to_remove, context=context)
|
||||
|
||||
|
||||
class CleanupPurgeLineModule(orm.TransientModel):
|
||||
|
|
|
@ -26,6 +26,7 @@ from openerp.osv import orm, fields
|
|||
class CleanupPurgeLine(orm.AbstractModel):
|
||||
""" Abstract base class for the purge wizard lines """
|
||||
_name = 'cleanup.purge.line'
|
||||
_order = 'name'
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=256, readonly=True),
|
||||
'purged': fields.boolean('Purged', readonly=True),
|
||||
|
|
|
@ -25,12 +25,24 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purge_columns" model="ir.actions.act_window">
|
||||
<record id="action_purge_columns" model="ir.actions.server">
|
||||
<field name="name">Purge columns</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">cleanup.purge.wizard.column</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_column" />
|
||||
<field name="code">
|
||||
wizard_id = self.create(cr, uid, {}, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'cleanup.purge.wizard.column',
|
||||
'res_id': wizard_id,
|
||||
'flags': {
|
||||
'action_buttons': False,
|
||||
'sidebar': False,
|
||||
},
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
|
@ -25,12 +25,24 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purge_data" model="ir.actions.act_window">
|
||||
<record id="action_purge_data" model="ir.actions.server">
|
||||
<field name="name">Purge data entries that refer to missing resources</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">cleanup.purge.wizard.data</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_data" />
|
||||
<field name="code">
|
||||
wizard_id = self.create(cr, uid, {}, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'cleanup.purge.wizard.data',
|
||||
'res_id': wizard_id,
|
||||
'flags': {
|
||||
'action_buttons': False,
|
||||
'sidebar': False,
|
||||
},
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
|
@ -24,12 +24,24 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purge_models" model="ir.actions.act_window">
|
||||
<record id="action_purge_models" model="ir.actions.server">
|
||||
<field name="name">Purge models</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">cleanup.purge.wizard.model</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_model" />
|
||||
<field name="code">
|
||||
wizard_id = self.create(cr, uid, {}, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'cleanup.purge.wizard.model',
|
||||
'res_id': wizard_id,
|
||||
'flags': {
|
||||
'action_buttons': False,
|
||||
'sidebar': False,
|
||||
},
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
|
@ -24,12 +24,24 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purge_modules" model="ir.actions.act_window">
|
||||
<record id="action_purge_modules" model="ir.actions.server">
|
||||
<field name="name">Purge modules</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">cleanup.purge.wizard.module</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_module" />
|
||||
<field name="code">
|
||||
wizard_id = self.create(cr, uid, {}, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'cleanup.purge.wizard.module',
|
||||
'res_id': wizard_id,
|
||||
'flags': {
|
||||
'action_buttons': False,
|
||||
'sidebar': False,
|
||||
},
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
|
@ -24,12 +24,24 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_purge_tables" model="ir.actions.act_window">
|
||||
<record id="action_purge_tables" model="ir.actions.server">
|
||||
<field name="name">Purge tables</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">cleanup.purge.wizard.table</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_wizard_table" />
|
||||
<field name="code">
|
||||
wizard_id = self.create(cr, uid, {}, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'cleanup.purge.wizard.table',
|
||||
'res_id': wizard_id,
|
||||
'flags': {
|
||||
'action_buttons': False,
|
||||
'sidebar': False,
|
||||
},
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue