Skip to content

Commit

Permalink
Merge PR OCA#931 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Oct 7, 2024
2 parents 57c3edb + 16f88b2 commit b16e9c7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
openupgradelib
2 changes: 1 addition & 1 deletion stock_available_to_promise_release/__init__.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions stock_available_to_promise_release/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
"application": False,
"development_status": "Beta",
"pre_init_hook": "pre_init_hook",
"external_dependencies": {"python": ["openupgradelib"]},
}
25 changes: 24 additions & 1 deletion stock_available_to_promise_release/hooks.py
Original file line number Diff line number Diff line change
@@ -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"):
Expand All @@ -27,3 +49,4 @@ def pre_init_hook(cr):
"""
)
_logger.info(f"{cr.rowcount} rows updated")
init_release_policy(cr)
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b16e9c7

Please sign in to comment.