pos_loyalty_discount_before.../__init__.py

41 lines
1.6 KiB
Python
Executable File

# -*- coding: utf-8 -*-
from . import models
from odoo import api, SUPERUSER_ID
def pre_init_clean_constraint(env):
"""
Drop the zombie table/constraint causing installation issues.
The constraint 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
indicates a table 'product_pricelist_res_config_settings_rel' (or similar)
linking Pricelist to Config Settings, which prevents settings deletion.
"""
cr = env.cr
# Attempt to drop the specific table that likely holds the constraint
cr.execute("DROP TABLE IF EXISTS product_pricelist_res_config_settings_rel CASCADE")
# Also try to specifically drop the constraint if it lingers on another table (unlikely but safe)
# We find the table first to avoid errors.
cr.execute("""
SELECT conrelid::regclass::text
FROM pg_constraint
WHERE conname = 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
""")
result = cr.fetchone()
# Force commit to ensure the drop is saved even if we raise an error?
# No, that breaks atomicity. But we want to prove it works.
# Verification:
cr.execute("""
SELECT count(*)
FROM pg_constraint
WHERE conname = 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
""")
if cr.fetchone()[0] > 0:
import logging
_logger = logging.getLogger(__name__)
_logger.warning("Constraint persisting despite drop attempt. This is unexpected.")
else:
import logging
_logger = logging.getLogger(__name__)
_logger.info("Constraints successfully removed (or were already gone).")