From 6ad89cf98da37d9a8f829ef13c72e38d160f4f42 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Wed, 25 Mar 2026 23:17:34 +0100 Subject: [PATCH] [FIX] website_sale_extra_fields: slug_name NOT NULL on fresh install Add pre_init_hook to pre-create the slug_name column and fill existing rows with a placeholder value before _auto_init runs. This prevents the SET NOT NULL constraint from failing when product_public_category records already exist from website_sale demo data. --- website_sale_extra_fields/__init__.py | 1 + website_sale_extra_fields/__manifest__.py | 3 ++- website_sale_extra_fields/hooks.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 website_sale_extra_fields/hooks.py diff --git a/website_sale_extra_fields/__init__.py b/website_sale_extra_fields/__init__.py index 0650744f6..6d58305f5 100644 --- a/website_sale_extra_fields/__init__.py +++ b/website_sale_extra_fields/__init__.py @@ -1 +1,2 @@ from . import models +from .hooks import pre_init_hook diff --git a/website_sale_extra_fields/__manifest__.py b/website_sale_extra_fields/__manifest__.py index 630a1358d..2ec2efca3 100644 --- a/website_sale_extra_fields/__manifest__.py +++ b/website_sale_extra_fields/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Website Sale Extra Fields", - "version": "14.0.0.1.0", + "version": "14.0.0.1.1", "author": "NuoBiT Solutions, S.L.", "license": "AGPL-3", "category": "Website", @@ -16,4 +16,5 @@ "views/product_template.xml", "views/product_product.xml", ], + "pre_init_hook": "pre_init_hook", } diff --git a/website_sale_extra_fields/hooks.py b/website_sale_extra_fields/hooks.py new file mode 100644 index 000000000..cfe07a521 --- /dev/null +++ b/website_sale_extra_fields/hooks.py @@ -0,0 +1,20 @@ +# Copyright NuoBiT Solutions - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +import logging + +_logger = logging.getLogger(__name__) + + +def pre_init_hook(cr): + _logger.info( + "Pre-creating slug_name column on product_public_category" + " to avoid NOT NULL constraint failure" + ) + cr.execute( + "ALTER TABLE product_public_category" + " ADD COLUMN IF NOT EXISTS slug_name varchar" + ) + cr.execute( + "UPDATE product_public_category SET slug_name = '/' WHERE slug_name IS NULL" + )