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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ class CleanupPurgeLine(models.AbstractModel):
def purge(self):
raise NotImplementedError
@api.model
@api.model_create_multi
def create(self, values):
# 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:
@ -77,10 +77,11 @@ class PurgeWizard(models.AbstractModel):
"domain": [("wizard_id", "in", self.ids)],
}
def name_get(self):
return [(this.id, self._description) for this in self]
def _compute_display_name(self):
for this in self:
this.display_name = self._description
@api.model
@api.model_create_multi
def create(self, values):
# 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:

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">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

View File

@ -13,7 +13,7 @@ class TestCreateIndexesLine(Common):
super().setUp()
with environment() as env:
# 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):
with environment() as env:
@ -21,6 +21,6 @@ class TestCreateIndexesLine(Common):
wizard.purge_all()
env.cr.execute(
"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)

View File

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