post-migration.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from odoo import api, SUPERUSER_ID
  4. _logger = logging.getLogger(__name__)
  5. def migrate(cr, version):
  6. """Actualizar traducciones para quitar 'Enterprise' de los nombres de módulos"""
  7. env = api.Environment(cr, SUPERUSER_ID, {})
  8. # Actualizar traducciones en ir.translation
  9. Translation = env['ir.translation']
  10. # Buscar traducciones problemáticas
  11. translations = Translation.search([
  12. ('name', '=', 'helpdesk.affected.module,name'),
  13. ('lang', '=', 'es_MX'),
  14. ('value', 'ilike', 'Enterprise'),
  15. ])
  16. _logger.info(f"Encontradas {len(translations)} traducciones con 'Enterprise' para actualizar")
  17. updates = {
  18. 'Web de Enterprise': 'Web',
  19. 'Web Enterprise': 'Web',
  20. 'Contabilidad Analítica Enterprise': 'Contabilidad Analítica',
  21. 'Analytic Accounting Enterprise': 'Contabilidad Analítica',
  22. 'Facturación (Enterprise)': 'Facturación',
  23. 'Facturación Enterprise': 'Facturación',
  24. 'Invoicing (Enterprise)': 'Facturación',
  25. }
  26. updated_count = 0
  27. for trans in translations:
  28. old_value = trans.value
  29. new_value = updates.get(old_value)
  30. if not new_value:
  31. # Limpieza genérica
  32. new_value = old_value.replace('Enterprise', '').replace('enterprise', '')
  33. new_value = new_value.replace(' de ', ' ').replace(' (', '').replace(')', '')
  34. new_value = ' '.join(new_value.split()).strip()
  35. if old_value != new_value:
  36. trans.write({'value': new_value})
  37. updated_count += 1
  38. _logger.info(f"Actualizado: '{old_value}' → '{new_value}'")
  39. cr.commit()
  40. _logger.info(f"✅ {updated_count} traducciones actualizadas exitosamente")