<commit_before># 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;
        """)<commit_msg>[FIX] stock_removal_by_priority: avoid pre-init-hook if reinstalled<commit_after># 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("""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;
            """)
{'fraction_non_alphanumeric': 0.07552504038772213, 'fraction_numerical': 0.008077544426494346, 'mean_word_length': 3.021103896103896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5443575', 'n_tokens_mistral': 724, 'n_tokens_neox': 699, 'n_words': 197}