forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
52 lines (45 loc) · 1.56 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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"):
_logger.info("Create date_priority column")
cr.execute(
"""
ALTER TABLE stock_move
ADD COLUMN date_priority timestamp;
"""
)
_logger.info("Initialize date_priority field")
cr.execute(
"""
UPDATE stock_move
SET date_priority = create_date
where state not in ('done', 'cancel')
"""
)
_logger.info(f"{cr.rowcount} rows updated")
init_release_policy(cr)