# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 """Force re-import of the engagement mail templates on 19.0.2.4.0. The mail templates ship in `` so support's later tweaks (different reply-to, custom signature, etc.) aren't blown away by every routine module upgrade. The flip side: a structural change to the template body in our own XML is silently skipped — the next `-u` reads the new XML but Odoo refuses to overwrite the existing row because of the noupdate flag. This release introduces the 3-section email layout (Original Request / Our Reply / Summary) and we DELIBERATELY want it to land. So this pre-migration deletes the existing template records + their ir_model_data anchors BEFORE the upgrade's data load runs. The XML import then re-creates them with the new body_html. Pre-migration > post-migration here because data load happens between the two. If we deleted in post-migration, the data load would already have skipped the update — too late. """ import logging _logger = logging.getLogger(__name__) _TEMPLATE_XMLIDS = ( 'mail_template_engagement', 'mail_template_engagement_bulk', ) def migrate(cr, version): cr.execute( """ SELECT name, res_id FROM ir_model_data WHERE module = 'fusion_helpdesk_central' AND name IN %s """, (_TEMPLATE_XMLIDS,), ) rows = cr.fetchall() if not rows: _logger.info( 'fusion_helpdesk_central 19.0.2.4.0 pre-migration: no ' 'existing engagement templates to delete; nothing to do.' ) return template_ids = [r[1] for r in rows] cr.execute( "DELETE FROM mail_template WHERE id IN %s", (tuple(template_ids),), ) cr.execute( """ DELETE FROM ir_model_data WHERE module = 'fusion_helpdesk_central' AND name IN %s """, (_TEMPLATE_XMLIDS,), ) _logger.info( 'fusion_helpdesk_central 19.0.2.4.0 pre-migration: dropped %s ' 'engagement mail template(s) so the upgrade re-imports them ' 'with the new 3-section layout: %s', len(template_ids), ', '.join(r[0] for r in rows), )