From bd235e3ca06c80b6a593a1e9e9269a3f33e5034a Mon Sep 17 00:00:00 2001 From: "matthias.lotz" Date: Mon, 15 Dec 2025 20:36:41 +0100 Subject: [PATCH] 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. --- .../migrations/18.0.1.0.4/post-migration.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/open_workshop_base/migrations/18.0.1.0.4/post-migration.py b/open_workshop_base/migrations/18.0.1.0.4/post-migration.py index 249a3a4..18bf034 100644 --- a/open_workshop_base/migrations/18.0.1.0.4/post-migration.py +++ b/open_workshop_base/migrations/18.0.1.0.4/post-migration.py @@ -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") +