forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_hook.py
54 lines (45 loc) · 1.44 KB
/
init_hook.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
53
54
# Copyright 2017 ForgeFlow, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
logger = logging.getLogger(__name__)
def pre_init_hook(cr):
"""
The objective of this hook is to speed up the installation
of the module on an existing Odoo instance.
Without this script, big databases can take a long time to install this
module.
"""
set_stock_location_removal_priority_default(cr)
set_stock_quant_removal_priority_default(cr)
def set_stock_location_removal_priority_default(cr):
cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_location' AND
column_name='removal_priority'"""
)
if not cr.fetchone():
logger.info("Creating field removal_priority on stock_location")
cr.execute(
"""
ALTER TABLE stock_location
ADD COLUMN removal_priority integer
DEFAULT 10;
"""
)
def set_stock_quant_removal_priority_default(cr):
cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_quant' AND
column_name='removal_priority'"""
)
if not cr.fetchone():
logger.info("Creating field removal_priority on stock_quant")
cr.execute(
"""
ALTER TABLE stock_quant
ADD COLUMN removal_priority integer
DEFAULT 10;
"""
)