diff --git a/rental_base_extension/__init__.py b/rental_base_extension/__init__.py index 0650744f6..cc6b6354a 100644 --- a/rental_base_extension/__init__.py +++ b/rental_base_extension/__init__.py @@ -1 +1,2 @@ from . import models +from .hooks import post_init_hook diff --git a/rental_base_extension/__manifest__.py b/rental_base_extension/__manifest__.py index 2fc4f298a..03758cbcf 100644 --- a/rental_base_extension/__manifest__.py +++ b/rental_base_extension/__manifest__.py @@ -11,6 +11,7 @@ "author": "NuoBiT Solutions SL", "website": "https://github.com/nuobit/odoo-addons", "license": "AGPL-3", + "post_init_hook": "post_init_hook", "depends": [ "rental_base", ], diff --git a/rental_base_extension/hooks.py b/rental_base_extension/hooks.py new file mode 100644 index 000000000..08dd1d6cb --- /dev/null +++ b/rental_base_extension/hooks.py @@ -0,0 +1,26 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +import logging + +from odoo import SUPERUSER_ID, api + +_logger = logging.getLogger(__name__) + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + normal_type = env.ref("sale_order_type.normal_sale_type") + cr.execute( + "UPDATE sale_order SET type_id = %s WHERE type_id IS NULL", + [normal_type.id], + ) + _logger.info("Updated %d sale orders with default type_id", cr.rowcount) + cr.execute("UPDATE sale_order_line SET rental = False WHERE rental IS NULL") + _logger.info("Updated %d sale order lines with rental = False", cr.rowcount) + cr.execute( + "UPDATE sale_order_line SET can_sell_rental = False WHERE can_sell_rental IS NULL" + ) + _logger.info( + "Updated %d sale order lines with can_sell_rental = False", cr.rowcount + )