|
|
@@ -1,52 +1,96 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
import logging
|
|
|
from odoo import api, SUPERUSER_ID
|
|
|
+from odoo.tools import sql
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
def migrate(cr, version):
|
|
|
"""Actualizar traducciones para quitar 'Enterprise' de los nombres de módulos"""
|
|
|
- env = api.Environment(cr, SUPERUSER_ID, {})
|
|
|
-
|
|
|
- # Actualizar traducciones en ir.translation
|
|
|
- Translation = env['ir.translation']
|
|
|
-
|
|
|
- # Buscar traducciones problemáticas
|
|
|
- translations = Translation.search([
|
|
|
- ('name', '=', 'helpdesk.affected.module,name'),
|
|
|
- ('lang', '=', 'es_MX'),
|
|
|
- ('value', 'ilike', 'Enterprise'),
|
|
|
- ])
|
|
|
-
|
|
|
- _logger.info(f"Encontradas {len(translations)} traducciones con 'Enterprise' para actualizar")
|
|
|
-
|
|
|
- updates = {
|
|
|
- 'Web de Enterprise': 'Web',
|
|
|
- 'Web Enterprise': 'Web',
|
|
|
- 'Contabilidad Analítica Enterprise': 'Contabilidad Analítica',
|
|
|
- 'Analytic Accounting Enterprise': 'Contabilidad Analítica',
|
|
|
- 'Facturación (Enterprise)': 'Facturación',
|
|
|
- 'Facturación Enterprise': 'Facturación',
|
|
|
- 'Invoicing (Enterprise)': 'Facturación',
|
|
|
- }
|
|
|
-
|
|
|
- updated_count = 0
|
|
|
- for trans in translations:
|
|
|
- old_value = trans.value
|
|
|
- new_value = updates.get(old_value)
|
|
|
+ try:
|
|
|
+ env = api.Environment(cr, SUPERUSER_ID, {})
|
|
|
|
|
|
- if not new_value:
|
|
|
- # Limpieza genérica
|
|
|
- new_value = old_value.replace('Enterprise', '').replace('enterprise', '')
|
|
|
- new_value = new_value.replace(' de ', ' ').replace(' (', '').replace(')', '')
|
|
|
- new_value = ' '.join(new_value.split()).strip()
|
|
|
+ # Verificar si el modelo ir.translation está disponible
|
|
|
+ if 'ir.translation' not in env.registry:
|
|
|
+ _logger.warning("Modelo ir.translation no disponible, usando SQL directo")
|
|
|
+ # Usar SQL directo si el modelo no está disponible
|
|
|
+ if sql.table_exists(cr, '_ir_translation'):
|
|
|
+ cr.execute("""
|
|
|
+ UPDATE _ir_translation
|
|
|
+ SET value = CASE
|
|
|
+ WHEN value = 'Web de Enterprise' THEN 'Web'
|
|
|
+ WHEN value = 'Web Enterprise' THEN 'Web'
|
|
|
+ WHEN value = 'Contabilidad Analítica Enterprise' THEN 'Contabilidad Analítica'
|
|
|
+ WHEN value = 'Analytic Accounting Enterprise' THEN 'Contabilidad Analítica'
|
|
|
+ WHEN value = 'Facturación (Enterprise)' THEN 'Facturación'
|
|
|
+ WHEN value = 'Facturación Enterprise' THEN 'Facturación'
|
|
|
+ WHEN value = 'Invoicing (Enterprise)' THEN 'Facturación'
|
|
|
+ ELSE regexp_replace(
|
|
|
+ regexp_replace(
|
|
|
+ regexp_replace(value, 'Enterprise', '', 'gi'),
|
|
|
+ 'enterprise', '', 'gi'
|
|
|
+ ),
|
|
|
+ '\\s+', ' ', 'g'
|
|
|
+ )
|
|
|
+ END
|
|
|
+ WHERE name = 'helpdesk.affected.module,name'
|
|
|
+ AND lang = 'es_MX'
|
|
|
+ AND (value ILIKE '%Enterprise%' OR value ILIKE '%enterprise%')
|
|
|
+ """)
|
|
|
+ updated_count = cr.rowcount
|
|
|
+ cr.commit()
|
|
|
+ _logger.info(f"✅ {updated_count} traducciones actualizadas exitosamente (vía SQL)")
|
|
|
+ else:
|
|
|
+ _logger.warning("Tabla _ir_translation no existe, saltando actualización")
|
|
|
+ return
|
|
|
|
|
|
- if old_value != new_value:
|
|
|
- trans.write({'value': new_value})
|
|
|
- updated_count += 1
|
|
|
- _logger.info(f"Actualizado: '{old_value}' → '{new_value}'")
|
|
|
-
|
|
|
- cr.commit()
|
|
|
- _logger.info(f"✅ {updated_count} traducciones actualizadas exitosamente")
|
|
|
+ # Actualizar traducciones en ir.translation
|
|
|
+ Translation = env['ir.translation']
|
|
|
+
|
|
|
+ # Buscar traducciones problemáticas
|
|
|
+ translations = Translation.search([
|
|
|
+ ('name', '=', 'helpdesk.affected.module,name'),
|
|
|
+ ('lang', '=', 'es_MX'),
|
|
|
+ ('value', 'ilike', 'Enterprise'),
|
|
|
+ ])
|
|
|
+
|
|
|
+ _logger.info(f"Encontradas {len(translations)} traducciones con 'Enterprise' para actualizar")
|
|
|
+
|
|
|
+ updates = {
|
|
|
+ 'Web de Enterprise': 'Web',
|
|
|
+ 'Web Enterprise': 'Web',
|
|
|
+ 'Contabilidad Analítica Enterprise': 'Contabilidad Analítica',
|
|
|
+ 'Analytic Accounting Enterprise': 'Contabilidad Analítica',
|
|
|
+ 'Facturación (Enterprise)': 'Facturación',
|
|
|
+ 'Facturación Enterprise': 'Facturación',
|
|
|
+ 'Invoicing (Enterprise)': 'Facturación',
|
|
|
+ }
|
|
|
+
|
|
|
+ updated_count = 0
|
|
|
+ for trans in translations:
|
|
|
+ try:
|
|
|
+ old_value = trans.value
|
|
|
+ new_value = updates.get(old_value)
|
|
|
+
|
|
|
+ if not new_value:
|
|
|
+ # Limpieza genérica
|
|
|
+ new_value = old_value.replace('Enterprise', '').replace('enterprise', '')
|
|
|
+ new_value = new_value.replace(' de ', ' ').replace(' (', '').replace(')', '')
|
|
|
+ new_value = ' '.join(new_value.split()).strip()
|
|
|
+
|
|
|
+ if old_value != new_value:
|
|
|
+ trans.write({'value': new_value})
|
|
|
+ updated_count += 1
|
|
|
+ _logger.info(f"Actualizado: '{old_value}' → '{new_value}'")
|
|
|
+ except Exception as e:
|
|
|
+ _logger.warning(f"Error al actualizar traducción {trans.id}: {e}")
|
|
|
+ continue
|
|
|
+
|
|
|
+ cr.commit()
|
|
|
+ _logger.info(f"✅ {updated_count} traducciones actualizadas exitosamente")
|
|
|
+ except Exception as e:
|
|
|
+ _logger.error(f"Error en migración 18.0.1.0.9: {e}", exc_info=True)
|
|
|
+ cr.rollback()
|
|
|
+ # No lanzar la excepción para no bloquear la actualización del módulo
|
|
|
|