diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..180fc49789 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +openupgradelib diff --git a/stock_available_to_promise_release/__init__.py b/stock_available_to_promise_release/__init__.py index cedd78e82c..0eff9147b6 100644 --- a/stock_available_to_promise_release/__init__.py +++ b/stock_available_to_promise_release/__init__.py @@ -1,3 +1,3 @@ from . import models from . import wizards -from .hooks import pre_init_hook +from .hooks import init_release_policy, pre_init_hook diff --git a/stock_available_to_promise_release/__manifest__.py b/stock_available_to_promise_release/__manifest__.py index d4e1e808f5..06732e8d05 100644 --- a/stock_available_to_promise_release/__manifest__.py +++ b/stock_available_to_promise_release/__manifest__.py @@ -25,4 +25,5 @@ "application": False, "development_status": "Beta", "pre_init_hook": "pre_init_hook", + "external_dependencies": {"python": ["openupgradelib"]}, } diff --git a/stock_available_to_promise_release/hooks.py b/stock_available_to_promise_release/hooks.py index 6f895a78e3..4a00ceb42e 100644 --- a/stock_available_to_promise_release/hooks.py +++ b/stock_available_to_promise_release/hooks.py @@ -1,13 +1,35 @@ # Copyright 2023 ACSONE SA/NV # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). - import logging +from openupgradelib import openupgrade + +from odoo import SUPERUSER_ID, api from odoo.tools import sql _logger = logging.getLogger(__name__) +def init_release_policy(cr): + if not sql.column_exists(cr, "stock_picking", "release_policy"): + # Use the default sql query instead relying on ORM as all records will + # be updated. + _logger.info("Creating 'release_policy' field on stock.picking") + env = api.Environment(cr, SUPERUSER_ID, {}) + field_spec = [ + ( + "release_policy", + "stock.picking", + False, + "selection", + False, + "stock_available_to_promise_release", + "direct", + ) + ] + openupgrade.add_fields(env, field_spec=field_spec) + + def pre_init_hook(cr): """create and initialize the date priority column on the stock move""" if not sql.column_exists(cr, "stock_move", "date_priority"): @@ -27,3 +49,4 @@ def pre_init_hook(cr): """ ) _logger.info(f"{cr.rowcount} rows updated") + init_release_policy(cr) diff --git a/stock_available_to_promise_release/migrations/16.0.3.1.0/pre-migrate.py b/stock_available_to_promise_release/migrations/16.0.3.1.0/pre-migrate.py index 9487130dbd..57482b4ad6 100644 --- a/stock_available_to_promise_release/migrations/16.0.3.1.0/pre-migrate.py +++ b/stock_available_to_promise_release/migrations/16.0.3.1.0/pre-migrate.py @@ -2,23 +2,14 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from openupgradelib import openupgrade +# pylint: disable=odoo-addons-relative-import +from odoo.addons.stock_available_to_promise_release.hooks import init_release_policy + @openupgrade.migrate() def migrate(env, version): """ - Initialize default value when adding field instead updating every record. + Use the default sql query instead relying on ORM as all records will + be updated. """ - - field_spec = [ - ( - "release_policy", - "stock.picking", - False, - "char", - "varchar", - "stock_available_to_promise_release", - "direct", - ) - ] - - openupgrade.add_fields(env, field_spec=field_spec) + init_release_policy(env.cr)