[MIG] database_cleanup: Migration to 17.0

pull/2804/head
augusto-weiss 2024-01-10 16:14:57 -03:00
parent d60ef91034
commit fbb5dc1fe7
8 changed files with 18 additions and 21 deletions

View File

@ -3,7 +3,7 @@
# 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).
{ {
"name": "Database cleanup", "name": "Database cleanup",
"version": "16.0.1.0.0", "version": "17.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",
"depends": ["base"], "depends": ["base"],

View File

@ -19,7 +19,7 @@ class CreateIndexesLine(models.TransientModel):
def purge(self): def purge(self):
for field in self.mapped("field_id"): for field in self.mapped("field_id"):
model = self.env[field.model] model = self.env[field.model]
name = f"{model._table}_{field.name}_index" name = f"{model._table}__{field.name}_index"
self.env.cr.execute( self.env.cr.execute(
"create index %s ON %s (%s)", "create index %s ON %s (%s)",
( (
@ -56,7 +56,7 @@ class CreateIndexesWizard(models.TransientModel):
if field.model not in self.env.registry: if field.model not in self.env.registry:
continue continue
model = self.env[field.model] model = self.env[field.model]
name = f"{model._table}_{field.name}_index" name = f"{model._table}__{field.name}_index"
self.env.cr.execute( self.env.cr.execute(
"select indexname from pg_indexes " "select indexname from pg_indexes "
"where indexname=%s and tablename=%s", "where indexname=%s and tablename=%s",

View File

@ -78,8 +78,7 @@ class CleanupPurgeWizardData(models.TransientModel):
0, 0,
{ {
"data_id": data.id, "data_id": data.id,
"name": "%s.%s, object of type %s" "name": f"{data.module}.{data.name}, object of type {data.model}",
% (data.module, data.name, data.model),
}, },
) )
) )

View File

@ -103,8 +103,9 @@ class CleanupPurgeWizardProperty(models.TransientModel):
"id", "id",
"not in", "not in",
default_properties.filtered( default_properties.filtered(
lambda x: x.company_id lambda x,
and x.fields_id == prop.fields_id prop_fields_id=prop.fields_id: x.company_id
and x.fields_id == prop_fields_id
).ids, ).ids,
) )
] ]

View File

@ -25,7 +25,7 @@ class CleanupPurgeLine(models.AbstractModel):
def purge(self): def purge(self):
raise NotImplementedError raise NotImplementedError
@api.model @api.model_create_multi
def create(self, values): def create(self, values):
# make sure the user trying this is actually supposed to do it # make sure the user trying this is actually supposed to do it
if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id: if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id:
@ -77,10 +77,11 @@ class PurgeWizard(models.AbstractModel):
"domain": [("wizard_id", "in", self.ids)], "domain": [("wizard_id", "in", self.ids)],
} }
def name_get(self): def _compute_display_name(self):
return [(this.id, self._description) for this in self] for this in self:
this.display_name = self._description
@api.model @api.model_create_multi
def create(self, values): def create(self, values):
# make sure the user trying this is actually supposed to do it # make sure the user trying this is actually supposed to do it
if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id: if self.env.ref("base.group_erp_manager") not in self.env.user.groups_id:

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>

View File

@ -13,7 +13,7 @@ class TestCreateIndexesLine(Common):
super().setUp() super().setUp()
with environment() as env: with environment() as env:
# delete some index and check if our module recreated it # delete some index and check if our module recreated it
env.cr.execute("drop index res_partner_name_index") env.cr.execute("drop index res_partner__name_index")
def test_deleted_index(self): def test_deleted_index(self):
with environment() as env: with environment() as env:
@ -21,6 +21,6 @@ class TestCreateIndexesLine(Common):
wizard.purge_all() wizard.purge_all()
env.cr.execute( env.cr.execute(
"select indexname from pg_indexes where " "select indexname from pg_indexes where "
"indexname='res_partner_name_index' and tablename='res_partner' " "indexname='res_partner__name_index' and tablename='res_partner' "
) )
self.assertEqual(env.cr.rowcount, 1) self.assertEqual(env.cr.rowcount, 1)

View File

@ -13,13 +13,10 @@
/> />
<button type="object" name="select_lines" string="Select lines" /> <button type="object" name="select_lines" string="Select lines" />
</header> </header>
<div attrs="{'invisible': [('purge_line_ids', '!=', [])]}"> <div invisible="purge_line_ids">
Nothing found to clean up. Nothing found to clean up.
</div> </div>
<field <field name="purge_line_ids" invisible="not purge_line_ids">
name="purge_line_ids"
attrs="{'invisible': [('purge_line_ids', '=', [])]}"
>
<form> <form>
<group> <group>
<field name="name" /> <field name="name" />
@ -31,7 +28,7 @@
name="purge" name="purge"
class="oe_highlight" class="oe_highlight"
string="Purge" string="Purge"
attrs="{'invisible': [('purged', '=', True)]}" invisible="purged"
/> />
</footer> </footer>
</form> </form>
@ -50,7 +47,7 @@
name="purge" name="purge"
icon="fa-times-circle text-danger" icon="fa-times-circle text-danger"
string="Purge this model" string="Purge this model"
attrs="{'invisible': [('purged', '=', True)]}" invisible="purged"
/> />
</tree> </tree>
</field> </field>