forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
34 lines (28 loc) · 1.07 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
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import logging
_logger = logging.getLogger(__name__)
def column_exists(cr, tablename, columnname):
"""Return whether the given column exists."""
query = """ SELECT 1 FROM information_schema.columns
WHERE table_name=%s AND column_name=%s """
cr.execute(query, (tablename, columnname))
return cr.rowcount
def pre_init_hook(cr):
_logger.info("Initialize product_restriction on table stock_location")
if not column_exists(cr, "stock_location", "product_restriction"):
cr.execute(
"""
ALTER TABLE stock_location
ADD COLUMN product_restriction character varying;
ALTER TABLE stock_location
ADD COLUMN parent_product_restriction character varying;
"""
)
cr.execute(
"""
UPDATE stock_location set product_restriction = 'any';
UPDATE stock_location set parent_product_restriction = 'any'
where location_id is not null;
"""
)