From e86b8758c1b0d90256b10eccb902b4952828d859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <30716308+remi-filament@users.noreply.github.com> Date: Tue, 21 May 2024 18:47:01 +0200 Subject: [PATCH] [MIG] remove_odoo_enterprise: Migration to 17.0 --- remove_odoo_enterprise/__manifest__.py | 2 +- remove_odoo_enterprise/models/__init__.py | 1 - remove_odoo_enterprise/models/base.py | 8 ++++--- .../models/ir_module_module.py | 13 ---------- .../models/res_config_settings.py | 24 +++++++++++++------ .../tests/test_remove_odoo_enterprise.py | 12 ++++------ .../views/res_config_settings_views.xml | 2 +- 7 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 remove_odoo_enterprise/models/ir_module_module.py diff --git a/remove_odoo_enterprise/__manifest__.py b/remove_odoo_enterprise/__manifest__.py index 3a2a19a4..fc30b89f 100644 --- a/remove_odoo_enterprise/__manifest__.py +++ b/remove_odoo_enterprise/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Remove Odoo Enterprise", "summary": "Remove enterprise modules and setting items", - "version": "16.0.2.0.1", + "version": "17.0.1.0.0", "category": "Maintenance", "author": "Eska, Onestein, Odoo Community Association (OCA)", "website": "https://github.com/OCA/server-brand", diff --git a/remove_odoo_enterprise/models/__init__.py b/remove_odoo_enterprise/models/__init__.py index acd20c92..a257f605 100644 --- a/remove_odoo_enterprise/models/__init__.py +++ b/remove_odoo_enterprise/models/__init__.py @@ -4,4 +4,3 @@ from . import base from . import res_config_settings -from . import ir_module_module diff --git a/remove_odoo_enterprise/models/base.py b/remove_odoo_enterprise/models/base.py index 158a4736..d683d561 100644 --- a/remove_odoo_enterprise/models/base.py +++ b/remove_odoo_enterprise/models/base.py @@ -9,8 +9,10 @@ class Base(models.AbstractModel): _inherit = "base" @api.model - def search(self, domain, offset=0, limit=None, order=None, count=False): - res = super().search(domain, offset, limit, order, count) - if not count and self._name == "payment.provider": + def search_fetch(self, domain, field_names, offset=0, limit=None, order=None): + res = super().search_fetch(domain, field_names, offset, limit, order) + if self._name == "ir.module.module": + res = res.filtered(lambda a: not a.to_buy) + elif self._name == "payment.provider": res = res.filtered(lambda a: not a.module_to_buy) return res diff --git a/remove_odoo_enterprise/models/ir_module_module.py b/remove_odoo_enterprise/models/ir_module_module.py deleted file mode 100644 index 462b9d6b..00000000 --- a/remove_odoo_enterprise/models/ir_module_module.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2019-2020 Onestein () -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import api, models - - -class IrModuleModule(models.Model): - _inherit = "ir.module.module" - - @api.model - def search(self, domain, offset=0, limit=None, order=None, count=False): - domain += [("to_buy", "=", False)] - return super().search(domain, offset, limit, order, count) diff --git a/remove_odoo_enterprise/models/res_config_settings.py b/remove_odoo_enterprise/models/res_config_settings.py index a461ea40..9030c5b1 100644 --- a/remove_odoo_enterprise/models/res_config_settings.py +++ b/remove_odoo_enterprise/models/res_config_settings.py @@ -21,16 +21,26 @@ def get_views(self, views, options=None): doc = etree.XML(ret_val["views"]["form"]["arch"]) - query = "//div[div[field[@widget='upgrade_boolean']]]" + query = "//setting[field[@widget='upgrade_boolean']]" for item in doc.xpath(query): item.attrib["class"] = "d-none" - for container in doc.xpath("//div[contains(@class, 'o_settings_container')]"): - if len(container.xpath("div[not(contains(@class, 'd-none'))]")) == 0: - prev_el = container.getprevious() - if len(prev_el) and prev_el.tag == "h2": - prev_el.attrib["class"] = "d-none" - container.attrib["class"] = "d-none" + for block in doc.xpath("//block"): + if ( + len( + block.xpath( + """setting[ + not(contains(@class, 'd-none')) + and not(@invisible='1')] + """ + ) + ) + == 0 + ): + # Removing title and tip so that no empty h2 or h3 are displayed + block.attrib.pop("title", None) + block.attrib.pop("tip", None) + block.attrib["class"] = "d-none" ret_val["views"]["form"]["arch"] = etree.tostring(doc) return ret_val diff --git a/remove_odoo_enterprise/tests/test_remove_odoo_enterprise.py b/remove_odoo_enterprise/tests/test_remove_odoo_enterprise.py index 9a0f417f..68f9b6e7 100644 --- a/remove_odoo_enterprise/tests/test_remove_odoo_enterprise.py +++ b/remove_odoo_enterprise/tests/test_remove_odoo_enterprise.py @@ -3,7 +3,6 @@ # Copyright 2023 Le Filament (https://le-filament.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import json from lxml import etree @@ -16,7 +15,7 @@ def test_res_config_settings(self): view = conf.get_views([[False, "form"]])["views"]["form"] doc = etree.XML(view["arch"]) - query = "//div[div[field[@widget='upgrade_boolean']]]" + query = "//setting[field[@widget='upgrade_boolean']]" for item in doc.xpath(query): self.assertEqual(item.attrib["class"], "d-none") @@ -35,10 +34,9 @@ def test_appstore_invisible(self): view = conf.get_views([[False, "form"]])["views"]["form"] doc = etree.XML(view["arch"]) - query = "//div[@id='appstore']" + query = "//setting[@id='appstore']" for item in doc.xpath(query): - invisible_attrib = json.loads(item.attrib["modifiers"]) - self.assertTrue(invisible_attrib["invisible"]) + self.assertTrue(item.attrib["invisible"]) def test_appstore_visible(self): """Disabling the view makes the appstore widget visible again""" @@ -50,6 +48,6 @@ def test_appstore_visible(self): view = conf.get_views([[False, "form"]])["views"]["form"] doc = etree.XML(view["arch"]) - query = "//div[@id='appstore']" + query = "//setting[@id='appstore']" for item in doc.xpath(query): - self.assertNotIn("modifiers", item.attrib) + self.assertNotIn("invisible", item.attrib) diff --git a/remove_odoo_enterprise/views/res_config_settings_views.xml b/remove_odoo_enterprise/views/res_config_settings_views.xml index bc94909e..28397828 100644 --- a/remove_odoo_enterprise/views/res_config_settings_views.xml +++ b/remove_odoo_enterprise/views/res_config_settings_views.xml @@ -4,7 +4,7 @@ res.config.settings - + 1