Skip to content

Commit

Permalink
edi: rename consumer mixin disable_edi_auto field
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Sep 10, 2023
1 parent 3c464a2 commit 0636f75
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
45 changes: 45 additions & 0 deletions edi_oca/migrations/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 Camptocamp SA (http://www.camptocamp.com)
# @author: Simone Orsi <[email protected]>
# 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
3 changes: 1 addition & 2 deletions edi_oca/models/edi_exchange_consumer_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0636f75

Please sign in to comment.