diff --git a/database_cleanup/README.rst b/database_cleanup/README.rst
index 2cf3865369b..51642ff57ee 100644
--- a/database_cleanup/README.rst
+++ b/database_cleanup/README.rst
@@ -17,13 +17,13 @@ Database cleanup
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
- :target: https://github.com/OCA/server-tools/tree/17.0/database_cleanup
+ :target: https://github.com/OCA/server-tools/tree/18.0/database_cleanup
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-database_cleanup
+ :target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-database_cleanup
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -65,7 +65,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -100,6 +100,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/server-tools `_ project on GitHub.
+This module is part of the `OCA/server-tools `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/database_cleanup/__manifest__.py b/database_cleanup/__manifest__.py
index f93701daba8..22094c652ae 100644
--- a/database_cleanup/__manifest__.py
+++ b/database_cleanup/__manifest__.py
@@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Database cleanup",
- "version": "17.0.1.2.1",
+ "version": "18.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"depends": ["base"],
@@ -19,7 +19,6 @@
"views/purge_tables.xml",
"views/purge_data.xml",
"views/create_indexes.xml",
- "views/purge_properties.xml",
"views/menu.xml",
"security/ir.model.access.csv",
],
diff --git a/database_cleanup/models/__init__.py b/database_cleanup/models/__init__.py
index a7685efdb47..4052f59006a 100644
--- a/database_cleanup/models/__init__.py
+++ b/database_cleanup/models/__init__.py
@@ -7,4 +7,3 @@
from . import purge_data
from . import purge_menus
from . import create_indexes
-from . import purge_properties
diff --git a/database_cleanup/models/purge_properties.py b/database_cleanup/models/purge_properties.py
deleted file mode 100644
index 3ae76f67ceb..00000000000
--- a/database_cleanup/models/purge_properties.py
+++ /dev/null
@@ -1,153 +0,0 @@
-# Copyright 2017 Therp BV
-# Copyright 2021 Camptocamp
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-# pylint: disable=consider-merging-classes-inherited
-from odoo import api, fields, models
-
-REASON_DUPLICATE = "REASON_DUPLICATE"
-REASON_DEFAULT = "REASON_DEFAULT"
-REASON_DEFAULT_FALSE = "REASON_DEFAULT_FALSE"
-REASON_UNKNOWN_MODEL = "REASON_UNKNOWN_MODEL"
-
-
-class CleanupPurgeLineProperty(models.TransientModel):
- _inherit = "cleanup.purge.line"
- _name = "cleanup.purge.line.property"
- _description = "Cleanup Purge Line Property"
-
- wizard_id = fields.Many2one(
- "cleanup.purge.wizard.property", "Purge Wizard", readonly=True
- )
- property_id = fields.Many2one("ir.property")
- reason = fields.Selection(
- [
- (REASON_DUPLICATE, "Duplicated property"),
- (REASON_DEFAULT, "Same value as default"),
- (REASON_DEFAULT_FALSE, "Empty default property"),
- (REASON_UNKNOWN_MODEL, "Unknown model"),
- ]
- )
-
- def purge(self):
- """Delete properties"""
- self.write({"purged": True})
- return self.mapped("property_id").unlink()
-
-
-class CleanupPurgeWizardProperty(models.TransientModel):
- _inherit = "cleanup.purge.wizard"
- _name = "cleanup.purge.wizard.property"
- _description = "Purge properties"
-
- @api.model
- def find(self):
- """
- Search property records which are duplicated or the same as the default
- """
- result = []
- default_properties = self.env["ir.property"].search(
- [
- ("res_id", "=", False),
- ]
- )
- handled_field_ids = []
- for prop in default_properties:
- value = None
- try:
- value = prop.get_by_record()
- except KeyError:
- result.append(
- {
- "name": f"{prop.name}@{prop.res_id}: {value}",
- "property_id": prop.id,
- "reason": REASON_UNKNOWN_MODEL,
- }
- )
- continue
- if not value:
- result.append(
- {
- "name": f"{prop.name}@{prop.res_id}: {value}",
- "property_id": prop.id,
- "reason": REASON_DEFAULT_FALSE,
- }
- )
- continue
- if prop.fields_id.id in handled_field_ids:
- continue
- domain = [
- ("id", "!=", prop.id),
- ("fields_id", "=", prop.fields_id.id),
- # =? explicitly tests for None or False, not falsyness
- ("value_float", "=?", prop.value_float or False),
- ("value_integer", "=?", prop.value_integer or False),
- ("value_text", "=?", prop.value_text or False),
- ("value_binary", "=?", prop.value_binary or False),
- ("value_reference", "=?", prop.value_reference or False),
- ("value_datetime", "=?", prop.value_datetime or False),
- ]
- if prop.company_id:
- domain.append(("company_id", "=", prop.company_id.id))
- else:
- domain.extend(
- [
- "|",
- ("company_id", "=", False),
- (
- "company_id",
- "in",
- self.env["res.company"]
- .search(
- [
- (
- "id",
- "not in",
- default_properties.filtered(
- lambda x,
- prop_fields_id=prop.fields_id: x.company_id
- and x.fields_id == prop_fields_id
- ).ids,
- )
- ]
- )
- .ids,
- ),
- ]
- )
-
- for redundant_property in self.env["ir.property"].search(domain):
- result.append(
- {
- "name": "{}@{}: {}".format(
- prop.name, redundant_property.res_id, prop.get_by_record()
- ),
- "property_id": redundant_property.id,
- "reason": REASON_DEFAULT,
- }
- )
- handled_field_ids.append(prop.fields_id.id)
- self.env.cr.execute(
- """
- with grouped_properties(ids, cnt) as (
- select array_agg(id), count(*)
- from ir_property group by res_id, company_id, fields_id
- )
- select ids from grouped_properties where cnt > 1
- """
- )
- for (ids,) in self.env.cr.fetchall():
- # odoo uses the first property found by search
- for prop in self.env["ir.property"].search([("id", "in", ids)])[1:]:
- result.append(
- {
- "name": f"{prop.name}@{prop.res_id}: {prop.get_by_record()}",
- "property_id": prop.id,
- "reason": REASON_DUPLICATE,
- }
- )
-
- return result
-
- purge_line_ids = fields.One2many(
- "cleanup.purge.line.property", "wizard_id", "Properties to purge"
- )
diff --git a/database_cleanup/models/purge_wizard.py b/database_cleanup/models/purge_wizard.py
index 456ee524a94..e14c2d16fe4 100644
--- a/database_cleanup/models/purge_wizard.py
+++ b/database_cleanup/models/purge_wizard.py
@@ -72,7 +72,7 @@ def select_lines(self):
return {
"type": "ir.actions.act_window",
"name": _("Select lines to purge"),
- "views": [(False, "tree"), (False, "form")],
+ "views": [(False, "list"), (False, "form")],
"res_model": self._fields["purge_line_ids"].comodel_name,
"domain": [("wizard_id", "in", self.ids)],
}
diff --git a/database_cleanup/readme/CREDIT.md b/database_cleanup/readme/CREDIT.md
new file mode 100644
index 00000000000..83b3ec91f7d
--- /dev/null
+++ b/database_cleanup/readme/CREDIT.md
@@ -0,0 +1 @@
+The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
diff --git a/database_cleanup/security/ir.model.access.csv b/database_cleanup/security/ir.model.access.csv
index c70c420e9d3..1d93bc221f1 100644
--- a/database_cleanup/security/ir.model.access.csv
+++ b/database_cleanup/security/ir.model.access.csv
@@ -15,5 +15,3 @@ access_cleanup_purge_line_data,access_cleanup_purge_line_data,model_cleanup_purg
access_cleanup_purge_wizard_data,access_cleanup_purge_wizard_data,model_cleanup_purge_wizard_data,base.group_user,1,1,1,1
access_cleanup_purge_line_menu,access_cleanup_purge_line_menu,model_cleanup_purge_line_menu,base.group_user,1,1,1,1
access_cleanup_purge_wizard_menu,access_cleanup_purge_wizard_menu,model_cleanup_purge_wizard_menu,base.group_user,1,1,1,1
-access_cleanup_purge_line_property,access_cleanup_purge_line_property,model_cleanup_purge_line_property,base.group_user,1,1,1,1
-access_cleanup_purge_wizard_property,access_cleanup_purge_wizard_property,model_cleanup_purge_wizard_property,base.group_user,1,1,1,1
diff --git a/database_cleanup/static/description/index.html b/database_cleanup/static/description/index.html
index d1edeebc3f9..44172501be3 100644
--- a/database_cleanup/static/description/index.html
+++ b/database_cleanup/static/description/index.html
@@ -369,7 +369,7 @@ Database cleanup
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0cfcda2589a9f11270616e22be3e3560c3360bb96421bba926a9dfd30735398d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
Clean your Odoo database from remnants of modules, models, columns and
tables left by uninstalled modules (prior to 7.0) or a homebrew database
upgrade to a new major version of Odoo.
@@ -407,7 +407,7 @@
Bugs are tracked on GitHub Issues .
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback .
+feedback .
Do not contact contributors directly about support or help with technical issues.
@@ -439,7 +439,7 @@
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/server-tools project on GitHub.
+
This module is part of the OCA/server-tools project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute .
diff --git a/database_cleanup/tests/__init__.py b/database_cleanup/tests/__init__.py
index 221c556007e..f8fd046e4e5 100644
--- a/database_cleanup/tests/__init__.py
+++ b/database_cleanup/tests/__init__.py
@@ -10,5 +10,4 @@
from . import test_purge_menus
from . import test_purge_models
from . import test_purge_modules
-from . import test_purge_properties
from . import test_purge_tables
diff --git a/database_cleanup/tests/common.py b/database_cleanup/tests/common.py
index 2223ed4d903..6ab78a32482 100644
--- a/database_cleanup/tests/common.py
+++ b/database_cleanup/tests/common.py
@@ -15,7 +15,7 @@ def environment():
"""Return an environment with a new cursor for the current database; the
cursor is committed and closed after the context block.
"""
- registry = odoo.registry(common.get_db_name())
+ registry = odoo.modules.registry.Registry(common.get_db_name())
with registry.cursor() as cr:
yield odoo.api.Environment(cr, ADMIN_USER_ID, {})
diff --git a/database_cleanup/tests/test_purge_fields.py b/database_cleanup/tests/test_purge_fields.py
index 774c990d92e..efb33716938 100644
--- a/database_cleanup/tests/test_purge_fields.py
+++ b/database_cleanup/tests/test_purge_fields.py
@@ -10,8 +10,9 @@
# Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install")
class TestCleanupPurgeFields(Common):
- def setUp(self):
- super().setUp()
+ @classmethod
+ def setUpClass(self):
+ super().setUpClass()
with environment() as env:
# create a nonexistent model
self.model_name = "x_database.cleanup.test.field.model"
@@ -54,3 +55,11 @@ def test_empty_field(self):
]
)
)
+
+ @classmethod
+ def tearDownClass(self):
+ super().tearDownClass()
+ with environment() as env:
+ model = env["ir.model"].search([("model", "=", self.model_name)])
+ if model:
+ model.unlink()
diff --git a/database_cleanup/tests/test_purge_modules.py b/database_cleanup/tests/test_purge_modules.py
index 46a659ffbc4..2b05b1972fe 100644
--- a/database_cleanup/tests/test_purge_modules.py
+++ b/database_cleanup/tests/test_purge_modules.py
@@ -9,13 +9,15 @@
# Use post_install to get all models loaded more info: odoo/odoo#13458
@tagged("post_install", "-at_install")
class TestCleanupPurgeLineModule(Common):
- def setUp(self):
- super().setUp()
+ @classmethod
+ def setUpClass(self):
+ super().setUpClass()
+ self.model_name = "database_cleanup_test"
with environment() as env:
# create a nonexistent module
self.module = env["ir.module.module"].create(
{
- "name": "database_cleanup_test",
+ "name": self.model_name,
"state": "to upgrade",
}
)
@@ -26,4 +28,13 @@ def test_remove_to_upgrade_module(self):
module_names = wizard.purge_line_ids.filtered(
lambda x: not x.purged
).mapped("name")
- self.assertTrue("database_cleanup_test" in module_names)
+ self.assertTrue(self.model_name in module_names)
+
+ @classmethod
+ def tearDownClass(self):
+ super().tearDownClass()
+ with environment() as env:
+ module = env["ir.module.module"].search([("name", "=", self.model_name)])
+ if module:
+ module.state = "uninstalled"
+ module.unlink()
diff --git a/database_cleanup/tests/test_purge_properties.py b/database_cleanup/tests/test_purge_properties.py
deleted file mode 100644
index 2377ad5c8f0..00000000000
--- a/database_cleanup/tests/test_purge_properties.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright 2021 Camptocamp SA
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-
-from odoo.tests.common import tagged
-
-from .common import Common, environment
-
-
-# Use post_install to get all models loaded more info: odoo/odoo#13458
-@tagged("post_install", "-at_install")
-class TestCleanupPurgeLineProperty(Common):
- def setUp(self):
- super().setUp()
- with environment() as env:
- # Create one property for tests
- self.partner_name_field_id = env["ir.model.fields"].search(
- [("name", "=", "name"), ("model_id.model", "=", "res.partner")], limit=1
- )
-
- def test_property_to_not_removed(self):
- with environment() as env:
- self.property = env["ir.property"].create(
- {
- "fields_id": self.partner_name_field_id.id,
- "type": "char",
- "value_text": "My default partner name",
- "res_id": False,
- }
- )
- wizard = env["cleanup.purge.wizard.property"].create({})
- wizard.purge_all()
- self.assertTrue(self.property.exists())
-
- def test_property_no_value(self):
- with environment() as env:
- self.property = env["ir.property"].create(
- {
- "fields_id": self.partner_name_field_id.id,
- "type": "char",
- "value_text": False,
- "res_id": False,
- }
- )
- wizard = env["cleanup.purge.wizard.property"].create({})
- wizard.purge_all()
- self.assertFalse(self.property.exists())
diff --git a/database_cleanup/views/menu.xml b/database_cleanup/views/menu.xml
index 353288c7156..9618986c738 100644
--- a/database_cleanup/views/menu.xml
+++ b/database_cleanup/views/menu.xml
@@ -63,11 +63,4 @@
-
-
diff --git a/database_cleanup/views/purge_properties.xml b/database_cleanup/views/purge_properties.xml
deleted file mode 100644
index a21f34dcbd9..00000000000
--- a/database_cleanup/views/purge_properties.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
- cleanup.purge.wizard.property
-
- primary
-
-
-
-
-
-
- Purge properties
- ir.actions.server
- code
-
- action = env.get('cleanup.purge.wizard.property').get_wizard_action()
-
-
-
- cleanup.purge.line.property
-
- primary
-
-
-
-
-
-
-
-
- Purge
- ir.actions.server
- code
-
- records.purge()
-
-
-
diff --git a/database_cleanup/views/purge_wizard.xml b/database_cleanup/views/purge_wizard.xml
index ad977f1c911..22c09e8d076 100644
--- a/database_cleanup/views/purge_wizard.xml
+++ b/database_cleanup/views/purge_wizard.xml
@@ -39,7 +39,7 @@
cleanup.purge.line
-
+
-
+