forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit_hook.py
55 lines (45 loc) · 1.87 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
55
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, 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, if a database has a few hundred thousand
moves, which is not unlikely, the update will take
at least a few hours.
"""
set_stock_valuation_account_manual_adjustment_in_account_move(cr)
set_stock_valuation_account_manual_adjustment_in_account_move_line(cr)
def set_stock_valuation_account_manual_adjustment_in_account_move(cr):
cr.execute("""SELECT column_name
FROM information_schema.columns
WHERE table_name='account_move' AND
column_name='stock_valuation_account_manual_adjustment_id'""")
if not cr.fetchone():
cr.execute(
"""
ALTER TABLE account_move
ADD COLUMN stock_valuation_account_manual_adjustment_id
integer;
COMMENT ON COLUMN
account_move.stock_valuation_account_manual_adjustment_id IS
'Stock Valuation Account Manual Adjustment';
""")
def set_stock_valuation_account_manual_adjustment_in_account_move_line(cr):
cr.execute("""SELECT column_name
FROM information_schema.columns
WHERE table_name='account_move_line' AND
column_name='stock_valuation_account_manual_adjustment_id'""")
if not cr.fetchone():
cr.execute(
"""
ALTER TABLE account_move_line
ADD COLUMN stock_valuation_account_manual_adjustment_id
integer;
COMMENT ON COLUMN
account_move_line.stock_valuation_account_manual_adjustment_id
IS 'Stock Valuation Account Manual Adjustment';
""")