fix(migration): Synchronize related fields (area_id, category) from ows.machine to maintenance.equipment

The related fields in maintenance.equipment with store=True were not automatically
synchronized during migration. Added explicit SQL UPDATE statements to copy values:
- ows_area_id from area_id
- ows_category from category

This ensures the maintenance.equipment records have all the OWS-specific data
from the original ows.machine records after migration.
This commit is contained in:
Matthias Lotz 2025-12-15 20:36:41 +01:00
parent a5f8fd32c3
commit bd235e3ca0

View File

@ -99,7 +99,30 @@ def migrate(cr, version):
except Exception as e:
_logger.error(f"Failed to migrate machine {m_id}: {e}")
# 3. Validierung
# 3. Synchronisiere related fields von ows.machine nach maintenance.equipment
_logger.info("Synchronizing related fields (area_id, category) to maintenance.equipment...")
cr.execute("""
UPDATE maintenance_equipment me
SET ows_area_id = om.area_id
FROM ows_machine om
WHERE om.equipment_id = me.id
AND om.area_id IS NOT NULL
""")
synced_areas = cr.rowcount
_logger.info(f"✅ Synchronized {synced_areas} area_id values")
cr.execute("""
UPDATE maintenance_equipment me
SET ows_category = om.category
FROM ows_machine om
WHERE om.equipment_id = me.id
AND om.category IS NOT NULL
""")
synced_categories = cr.rowcount
_logger.info(f"✅ Synchronized {synced_categories} category values")
# 4. Validierung
cr.execute("SELECT COUNT(*) FROM ows_machine WHERE equipment_id IS NULL")
remaining = cr.fetchone()[0]
@ -109,3 +132,4 @@ def migrate(cr, version):
_logger.info(f"✅ Successfully migrated {migrated_count} machines to equipment")
_logger.info("Post-migration completed")