From 1f7f50846052160682a17ebe20df51a9c7fe8162 Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 24 May 2017 14:06:45 +0200 Subject: [PATCH] stock_removal_location_by_priority: Add init_hook to speed up installation --- .../__init__.py | 1 + .../__openerp__.py | 1 + .../init_hook.py | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 stock_removal_location_by_priority/init_hook.py diff --git a/stock_removal_location_by_priority/__init__.py b/stock_removal_location_by_priority/__init__.py index 08f93b3a4..2e7485cc7 100644 --- a/stock_removal_location_by_priority/__init__.py +++ b/stock_removal_location_by_priority/__init__.py @@ -4,3 +4,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models +from .init_hook import pre_init_hook diff --git a/stock_removal_location_by_priority/__openerp__.py b/stock_removal_location_by_priority/__openerp__.py index 87bddda80..91dd2d686 100644 --- a/stock_removal_location_by_priority/__openerp__.py +++ b/stock_removal_location_by_priority/__openerp__.py @@ -16,4 +16,5 @@ "license": "AGPL-3", 'installable': True, 'application': False, + 'pre_init_hook': 'pre_init_hook', } diff --git a/stock_removal_location_by_priority/init_hook.py b/stock_removal_location_by_priority/init_hook.py new file mode 100644 index 000000000..a3055b980 --- /dev/null +++ b/stock_removal_location_by_priority/init_hook.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 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, 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( + """ + ALTER TABLE stock_location + ADD COLUMN removal_priority integer + DEFAULT 10; + """) + + +def set_stock_quant_removal_priority_default(cr): + cr.execute( + """ + ALTER TABLE stock_quant + ADD COLUMN removal_priority integer + DEFAULT 10; + """)