[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
This commit is contained in:
parent
6d94484710
commit
2eaef82f3a
1 changed files with 18 additions and 0 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue