forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_expiry_configurable: Add migration scripts
- Loading branch information
1 parent
e70d132
commit 916d963
Showing
4 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
product_expiry_configurable/migrations/16.0.1.0.0/post-migrate.py
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,46 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _fill_in_columns(env): | ||
""" | ||
Create columns to fill in the previous module 'specific' fields | ||
""" | ||
if openupgrade.column_exists( | ||
env.cr, "product_category", "specific_expiration_time" | ||
): | ||
query = """ | ||
UPDATE product_category | ||
SET expiration_time = specific_expiration_time | ||
""" | ||
openupgrade.logged_query(env.cr, query) | ||
if openupgrade.column_exists(env.cr, "product_category", "specific_use_time"): | ||
query = """ | ||
UPDATE product_category | ||
SET use_time = specific_use_time | ||
""" | ||
openupgrade.logged_query(env.cr, query) | ||
if openupgrade.column_exists(env.cr, "product_category", "specific_use_time"): | ||
query = """ | ||
UPDATE product_category | ||
SET use_time = specific_use_time | ||
""" | ||
openupgrade.logged_query(env.cr, query) | ||
if openupgrade.column_exists(env.cr, "product_category", "specific_removal_time"): | ||
query = """ | ||
UPDATE product_category | ||
SET removal_time = specific_removal_time | ||
""" | ||
openupgrade.logged_query(env.cr, query) | ||
if openupgrade.column_exists(env.cr, "product_category", "specific_alert_time"): | ||
query = """ | ||
UPDATE product_category | ||
SET alert_time = specific_alert_time | ||
""" | ||
openupgrade.logged_query(env.cr, query) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_fill_in_columns(env) |
50 changes: 50 additions & 0 deletions
50
product_expiry_configurable/migrations/16.0.1.0.0/pre-migrate.py
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,50 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _create_columns(env): | ||
""" | ||
Create columns to fill in the previous module 'specific' fields | ||
""" | ||
field_names = [ | ||
( | ||
"expiration_time", | ||
"product.category", | ||
"product_category", | ||
"integer", | ||
"integer", | ||
"product_expiry_configurable", | ||
), | ||
( | ||
"use_time", | ||
"product.category", | ||
"product_category", | ||
"integer", | ||
"integer", | ||
"product_expiry_configurable", | ||
), | ||
( | ||
"removal_time", | ||
"product.category", | ||
"product_category", | ||
"integer", | ||
"integer", | ||
"product_expiry_configurable", | ||
), | ||
( | ||
"alert_time", | ||
"product.category", | ||
"product_category", | ||
"integer", | ||
"integer", | ||
"product_expiry_configurable", | ||
), | ||
] | ||
if not openupgrade.column_exists(env.cr, "product_category", "expiration_time"): | ||
openupgrade.add_fields(env, field_names) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_create_columns(env) |
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
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