From 0636f75ef0babf3e147a33765cf08fb0f46010f6 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Sun, 10 Sep 2023 14:58:04 +0200 Subject: [PATCH] edi: rename consumer mixin disable_edi_auto field --- edi_oca/migrations/pre-migrate.py | 45 +++++++++++++++++++ edi_oca/models/edi_exchange_consumer_mixin.py | 3 +- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 edi_oca/migrations/pre-migrate.py diff --git a/edi_oca/migrations/pre-migrate.py b/edi_oca/migrations/pre-migrate.py new file mode 100644 index 000000000..04bb489ee --- /dev/null +++ b/edi_oca/migrations/pre-migrate.py @@ -0,0 +1,45 @@ +# 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 psycopg2 import sql + +from odoo import SUPERUSER_ID, api, tools + +_logger = logging.getLogger(__name__) + + +def migrate(cr, version): + if not version: + return + env = api.Environment(cr, SUPERUSER_ID, {}) + rename_disable_auto_columns(env) + + +def rename_disable_auto_columns(env): + tables = _get_consumer_model_tables(env) + for table in tables: + if tools.sql.column_exists(env.cr, table, "disable_edi_auto"): + env.cr.execute(_make_query(table)) + _logger.info( + "table %s: renamed column `disable_edi_auto` to `edi_disable_auto`" + ) + + +def _make_query(table): + return sql.SQL( + "ALTER TABLE {} RENAME COLUMN 'disable_edi_auto' TO 'edi_disable_auto'" + ).format( + sql.Identifier(table), + ) + + +def _get_consumer_model_tables(env): + tables = [] + mixin = "edi.exchange.consumer.mixin" + for model in env.values(): + if model._name != mixin and not model._abstract and mixin in model._inherit: + tables.append(model._table) + return tables diff --git a/edi_oca/models/edi_exchange_consumer_mixin.py b/edi_oca/models/edi_exchange_consumer_mixin.py index 11c1a522f..2bd791dc3 100644 --- a/edi_oca/models/edi_exchange_consumer_mixin.py +++ b/edi_oca/models/edi_exchange_consumer_mixin.py @@ -44,8 +44,7 @@ class EDIExchangeConsumerMixin(models.AbstractModel): default={}, ) edi_has_form_config = fields.Boolean(compute="_compute_edi_config") - # TODO: rename to `edi_disable_auto` - disable_edi_auto = fields.Boolean( + edi_disable_auto = fields.Boolean( string="Disable auto", help="When marked, EDI automatic processing will be avoided", # Each extending module should override `states` as/if needed.