From 2eaef82f3ac5253c36b24339a73e684de60901e2 Mon Sep 17 00:00:00 2001 From: snt Date: Thu, 12 Feb 2026 19:57:32 +0100 Subject: [PATCH] [FIX] product_sale_price_from_pricelist: migration timing fix - Move migration from pre-migrate.py to post-migrate.py - pre-migrate runs before ORM creates columns, causing 'column does not exist' errors - post-migrate runs after columns are created, safe for updates - Add check for column existence to handle fresh installations gracefully - Ensures migration only runs when upgrading from older versions with data --- .../{pre-migrate.py => post-migrate.py} | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) rename product_sale_price_from_pricelist/migrations/18.0.2.1.0/{pre-migrate.py => post-migrate.py} (82%) diff --git a/product_sale_price_from_pricelist/migrations/18.0.2.1.0/pre-migrate.py b/product_sale_price_from_pricelist/migrations/18.0.2.1.0/post-migrate.py similarity index 82% rename from product_sale_price_from_pricelist/migrations/18.0.2.1.0/pre-migrate.py rename to product_sale_price_from_pricelist/migrations/18.0.2.1.0/post-migrate.py index 447a730..e80125a 100644 --- a/product_sale_price_from_pricelist/migrations/18.0.2.1.0/pre-migrate.py +++ b/product_sale_price_from_pricelist/migrations/18.0.2.1.0/post-migrate.py @@ -21,6 +21,24 @@ def migrate(cr, version): _logger.info("Migrating price fields from product.template to product.product...") + # Check if columns exist before attempting migration + # (they may not exist in fresh installations) + cr.execute(""" + SELECT EXISTS ( + SELECT FROM information_schema.columns + WHERE table_name = 'product_product' + AND column_name = 'last_purchase_price_received' + ); + """) + columns_exist = cr.fetchone()[0] + + if not columns_exist: + _logger.info( + "Columns do not exist in product_product, skipping migration. " + "Fresh installation detected." + ) + return + # Migrate last_purchase_price_received cr.execute(""" UPDATE product_product pp