-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edi: rename consumer mixin disable_edi_auto field
- Loading branch information
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters