From e2660dc4f83e122019554e7cbe1ce36cd4a16e90 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 25 Aug 2023 19:22:03 +0200 Subject: [PATCH 01/11] edi_oca: drop migrations --- .../migrations/14.0.1.19.0/post-migrate.py | 35 ---------------- edi_oca/migrations/14.0.1.19.0/pre-migrate.py | 42 ------------------- edi_oca/migrations/15.0.1.4.0/post-migrate.py | 19 --------- 3 files changed, 96 deletions(-) delete mode 100644 edi_oca/migrations/14.0.1.19.0/post-migrate.py delete mode 100644 edi_oca/migrations/14.0.1.19.0/pre-migrate.py delete mode 100644 edi_oca/migrations/15.0.1.4.0/post-migrate.py diff --git a/edi_oca/migrations/14.0.1.19.0/post-migrate.py b/edi_oca/migrations/14.0.1.19.0/post-migrate.py deleted file mode 100644 index 8c8b6a8b9..000000000 --- a/edi_oca/migrations/14.0.1.19.0/post-migrate.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2023 Camptocamp SA (http://www.camptocamp.com) -# @author Simone Orsi -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - -import logging - -from odoo import SUPERUSER_ID, api, tools - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - if not version: - return - - bkp_table = "exc_type_model_rel_bkp" - if not tools.sql.table_exists(cr, bkp_table): - return - - # Use backup table (created by pre-migrate step) to create type rules - env = api.Environment(cr, SUPERUSER_ID, {}) - query = """ - SELECT * FROM exc_type_model_rel_bkp - """ - cr.execute(query) - res = cr.dictfetchall() - model = env["edi.exchange.type.rule"] - for item in res: - kind = "form_btn" if item.pop("form_btn", False) else "custom" - vals = dict(item, name="Default", kind=kind) - rec = model.create(vals) - rec.type_id.button_wipe_deprecated_rule_fields() - - cr.execute("DROP TABLE exc_type_model_rel_bkp") - _logger.info("edi.exchange.type.rule created") diff --git a/edi_oca/migrations/14.0.1.19.0/pre-migrate.py b/edi_oca/migrations/14.0.1.19.0/pre-migrate.py deleted file mode 100644 index 61419f1d8..000000000 --- a/edi_oca/migrations/14.0.1.19.0/pre-migrate.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2023 Camptocamp SA (http://www.camptocamp.com) -# @author Simone Orsi -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - -import logging - -from odoo import tools - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - if not version: - return - - # Backup old style rules to be used later on post migrate - old_table = "edi_exchange_type_ir_model_rel" - if not tools.sql.table_exists(cr, old_table): - return - bkp_table = "exc_type_model_rel_bkp" - if tools.sql.table_exists(cr, bkp_table): - return - - bkp_query = """ - CREATE TABLE IF NOT EXISTS - exc_type_model_rel_bkp - AS - SELECT - rel.ir_model_id as model_id, - type.id as type_id, - type.enable_domain as enable_domain, - type.enable_snippet as enable_snippet, - type.model_manual_btn as form_btn - FROM - edi_exchange_type type, - edi_exchange_type_ir_model_rel rel - WHERE - rel.edi_exchange_type_id = type.id; - """ - cr.execute(bkp_query) - - _logger.info("edi.exchange.type old style rules backed up") diff --git a/edi_oca/migrations/15.0.1.4.0/post-migrate.py b/edi_oca/migrations/15.0.1.4.0/post-migrate.py deleted file mode 100644 index 2fb55e8bf..000000000 --- a/edi_oca/migrations/15.0.1.4.0/post-migrate.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2022 Camptocamp SA (http://www.camptocamp.com) -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - -import logging - -from odoo import SUPERUSER_ID, api - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - if not version: - return - - env = api.Environment(cr, SUPERUSER_ID, {}) - # For backward compat, enable buttons on all exc types that had a model conf. - domain = [("model_ids", "!=", False), ("model_manual_btn", "=", False)] - env["edi.exchange.type"].search(domain).write({"model_manual_btn": True}) - _logger.info("Activate model manual button on existing `edi.exchange.type`") From e2013bcd7f4e667a82d85be97262c36035e689ce Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 25 Aug 2023 19:23:33 +0200 Subject: [PATCH 02/11] edi_oca: drop deprecated code --- edi_oca/models/edi_exchange_type.py | 134 ------------------ edi_oca/tests/__init__.py | 1 - edi_oca/tests/test_consumer_mixin.py | 2 +- .../test_exchange_type_deprecated_fields.py | 43 ------ edi_oca/views/edi_exchange_type_views.xml | 33 ----- 5 files changed, 1 insertion(+), 212 deletions(-) delete mode 100644 edi_oca/tests/test_exchange_type_deprecated_fields.py diff --git a/edi_oca/models/edi_exchange_type.py b/edi_oca/models/edi_exchange_type.py index db09a7419..aeaef7ed5 100644 --- a/edi_oca/models/edi_exchange_type.py +++ b/edi_oca/models/edi_exchange_type.py @@ -116,28 +116,6 @@ class EDIExchangeType(models.Model): inverse_name="type_id", help="Rules to handle exchanges and UI automatically", ) - # Deprecated fields for rules - begin - # These fields have been deprecated in - # https://github.com/OCA/edi/pull/797 - # but are kept for backward compat. - # If you can stop using them now. - # Anyway, annoying warning messages will be logged. - # See inverse methods. - # NOTE: old configurations are migrated automatically on upgrade - # Yet, if you have data files they might be broken - # if we delete these fields. - model_ids = fields.Many2many( - "ir.model", inverse="_inverse_deprecated_rules_model_ids" - ) - enable_domain = fields.Char(inverse="_inverse_deprecated_rules_enable_domain") - enable_snippet = fields.Char(inverse="_inverse_deprecated_rules_enable_snippet") - model_manual_btn = fields.Boolean( - inverse="_inverse_deprecated_rules_model_manual_btn" - ) - deprecated_rule_fields_still_used = fields.Boolean( - compute="_compute_deprecated_rule_fields_still_used" - ) - # Deprecated fields for rules - end quick_exec = fields.Boolean( string="Quick execution", help="When active, records of this type will be processed immediately " @@ -248,115 +226,3 @@ def is_partner_enabled(self, partner): if exc_type.partner_ids: return partner.id in exc_type.partner_ids.ids return True - - # API to support deprecated model rules fields - begin - def _inverse_deprecated_rules_warning(self): - _fields = ", ".join( - ["model_ids", "enable_domain", "enable_snippet", "model_manual_btn"] - ) - _logger.warning( - "The fields %s are deprecated, " - "please stop using them in favor of edi.exchange.type.rule", - _fields, - ) - - def _inverse_deprecated_rules_model_ids(self): - if self.env.context.get("deprecated_rule_fields_bypass_inverse"): - return - self._inverse_deprecated_rules_warning() - for rec in self: - for model in rec.model_ids: - rule = rec._get_rule_by_model(model) - if not rule: - _logger.warning( - "New rule for %s created from deprecated `model_ids`", - model.model, - ) - rec.rule_ids += rec._inverse_deprecated_rules_create(model) - rules_to_delete = rec.rule_ids.browse() - for rule in rec.rule_ids: - if rule.model_id not in rec.model_ids: - _logger.warning( - "Rule for %s deleted from deprecated `model_ids`", - rule.model_id.model, - ) - rules_to_delete |= rule - rules_to_delete.unlink() - - def _inverse_deprecated_rules_enable_domain(self): - if self.env.context.get("deprecated_rule_fields_bypass_inverse"): - return - self._inverse_deprecated_rules_warning() - for rec in self: - for model in rec.model_ids: - rule = rec._get_rule_by_model(model) - if rule: - _logger.warning( - "Rule for %s domain updated from deprecated `enable_domain`", - model.model, - ) - rule.enable_domain = rec.enable_domain - - def _inverse_deprecated_rules_enable_snippet(self): - if self.env.context.get("deprecated_rule_fields_bypass_inverse"): - return - self._inverse_deprecated_rules_warning() - for rec in self: - for model in rec.model_ids: - rule = rec._get_rule_by_model(model) - if rule: - _logger.warning( - "Rule for %s snippet updated from deprecated `enable_snippet`", - model.model, - ) - rule.enable_snippet = rec.enable_snippet - - def _inverse_deprecated_rules_model_manual_btn(self): - if self.env.context.get("deprecated_rule_fields_bypass_inverse"): - return - self._inverse_deprecated_rules_warning() - for rec in self: - for model in rec.model_ids: - rule = rec._get_rule_by_model(model) - if rule: - _logger.warning( - "Rule for %s btn updated from deprecated `model_manual_btn`", - model.model, - ) - rule.kind = "form_btn" if self.model_manual_btn else "custom" - - def _get_rule_by_model(self, model): - return self.rule_ids.filtered(lambda x: x.model_id == model) - - def _inverse_deprecated_rules_create(self, model): - kind = "form_btn" if self.model_manual_btn else "custom" - vals = { - "type_id": self.id, - "model_id": model.id, - "kind": kind, - "name": "Default", - "enable_snippet": self.enable_snippet, - "enable_domain": self.enable_domain, - } - return self.rule_ids.create(vals) - - @api.depends("model_ids", "enable_domain", "enable_snippet", "model_manual_btn") - def _compute_deprecated_rule_fields_still_used(self): - for rec in self: - rec.deprecated_rule_fields_still_used = ( - rec._deprecated_rule_fields_still_used() - ) - - def _deprecated_rule_fields_still_used(self): - for fname in ("model_ids", "enable_snippet", "enable_domain"): - if self[fname]: - return True - - def button_wipe_deprecated_rule_fields(self): - _fields = ["model_ids", "enable_domain", "enable_snippet", "model_manual_btn"] - deprecated_vals = {}.fromkeys(_fields, None) - self.with_context(deprecated_rule_fields_bypass_inverse=True).write( - deprecated_vals - ) - - # API to support deprecated model rules fields - end diff --git a/edi_oca/tests/__init__.py b/edi_oca/tests/__init__.py index 30692700a..3f4193ce0 100644 --- a/edi_oca/tests/__init__.py +++ b/edi_oca/tests/__init__.py @@ -12,4 +12,3 @@ from . import test_edi_backend_cron from . import test_security from . import test_quick_exec -from . import test_exchange_type_deprecated_fields diff --git a/edi_oca/tests/test_consumer_mixin.py b/edi_oca/tests/test_consumer_mixin.py index ee81d4b7a..099134d4f 100644 --- a/edi_oca/tests/test_consumer_mixin.py +++ b/edi_oca/tests/test_consumer_mixin.py @@ -136,7 +136,7 @@ def make_config_data(**kw): make_config_data(), ) # enable it - self.exchange_type_out.model_manual_btn = True + self.exchange_type_out.rule_ids[0].kind = "form_btn" self.consumer_record.invalidate_cache(["edi_has_form_config", "edi_config"]) self.assertEqual( self.consumer_record.edi_config[str(rule.id)], diff --git a/edi_oca/tests/test_exchange_type_deprecated_fields.py b/edi_oca/tests/test_exchange_type_deprecated_fields.py deleted file mode 100644 index dee571bd9..000000000 --- a/edi_oca/tests/test_exchange_type_deprecated_fields.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). -# @author: Simone Orsi -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - - -from .common import EDIBackendCommonTestCase - - -class EDIExchangeTypeDeprecatedFieldsTestCase(EDIBackendCommonTestCase): - def test_inverse(self): - typ = self.exchange_type_out - self.assertFalse(typ.rule_ids) - self.assertFalse(typ.deprecated_rule_fields_still_used) - typ.model_ids += self.env["ir.model"]._get("res.partner") - self.assertTrue(typ.deprecated_rule_fields_still_used) - self.assertEqual(typ.rule_ids.mapped("model_id.model"), ["res.partner"]) - typ.model_ids += self.env["ir.model"]._get("res.groups") - self.assertEqual( - typ.rule_ids.mapped("model_id.model"), ["res.partner", "res.groups"] - ) - typ.enable_domain = "[(1, '=', 1)]" - self.assertRecordValues( - typ.rule_ids, [{"enable_domain": typ.enable_domain, "kind": "custom"}] * 2 - ) - typ.model_manual_btn = True - self.assertRecordValues( - typ.rule_ids, [{"enable_domain": typ.enable_domain, "kind": "form_btn"}] * 2 - ) - typ.model_ids -= self.env["ir.model"]._get("res.groups") - self.assertEqual(typ.rule_ids.mapped("model_id.model"), ["res.partner"]) - typ.model_ids = False - self.assertFalse(typ.rule_ids) - - def test_btn(self): - typ = self.exchange_type_out - typ.model_ids += self.env["ir.model"]._get("res.partner") - typ.enable_domain = "[(1, '=', 1)]" - typ.button_wipe_deprecated_rule_fields() - self.assertFalse(typ.model_ids) - self.assertFalse(typ.enable_domain) - self.assertFalse(typ.enable_snippet) - # Rules are kept - self.assertEqual(typ.rule_ids.mapped("model_id.model"), ["res.partner"]) diff --git a/edi_oca/views/edi_exchange_type_views.xml b/edi_oca/views/edi_exchange_type_views.xml index 185bba5a1..6e19cd4a3 100644 --- a/edi_oca/views/edi_exchange_type_views.xml +++ b/edi_oca/views/edi_exchange_type_views.xml @@ -50,7 +50,6 @@ - - - - - - - - - -