changes
This commit is contained in:
54
fusion_plating/fusion_plating_notifications/hooks.py
Normal file
54
fusion_plating/fusion_plating_notifications/hooks.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_init_hook(env):
|
||||
"""Force-populate report_template_ids on the mail templates.
|
||||
|
||||
The mail-template XML records are tagged noupdate="1" so
|
||||
customer-edited templates aren't overwritten on module update.
|
||||
That means report_template_ids added to the XML AFTER the
|
||||
templates were first installed won't propagate via the usual
|
||||
-u reload. This hook wires the reports onto the branded
|
||||
templates on install/upgrade and is safe to re-run.
|
||||
"""
|
||||
_apply_report_template(
|
||||
env,
|
||||
'fusion_plating_notifications.fp_mail_template_quote_sent',
|
||||
'fusion_plating_reports.action_report_fp_sale_portrait',
|
||||
)
|
||||
_apply_report_template(
|
||||
env,
|
||||
'fusion_plating_notifications.fp_mail_template_so_confirmed',
|
||||
'fusion_plating_reports.action_report_fp_so_acknowledgement',
|
||||
)
|
||||
_apply_report_template(
|
||||
env,
|
||||
'fusion_plating_notifications.fp_mail_template_invoice_posted',
|
||||
'fusion_plating_reports.action_report_fp_invoice_portrait',
|
||||
)
|
||||
|
||||
|
||||
def _apply_report_template(env, mail_template_xmlid, report_xmlid):
|
||||
mail_template = env.ref(mail_template_xmlid, raise_if_not_found=False)
|
||||
report = env.ref(report_xmlid, raise_if_not_found=False)
|
||||
if not mail_template or not report:
|
||||
_logger.warning(
|
||||
'fusion_plating_notifications post_init: missing %s or %s',
|
||||
mail_template_xmlid, report_xmlid,
|
||||
)
|
||||
return
|
||||
if report.id not in mail_template.report_template_ids.ids:
|
||||
mail_template.write({
|
||||
'report_template_ids': [(4, report.id)],
|
||||
})
|
||||
_logger.info(
|
||||
'fusion_plating_notifications: attached report %s to template %s',
|
||||
report_xmlid, mail_template_xmlid,
|
||||
)
|
||||
Reference in New Issue
Block a user