Files
Odoo-Modules/fusion_plating/fusion_plating_notifications/hooks.py
gsinghpal 8c76a16366 chore(plating): de-dash shipped code + intake-neutral customer emails
Replace em-dashes and en-dashes with hyphens across 789 shipped source
files (py/xml/js/scss) so the delivered module reads as human-written;
em-dashes had become a recognizable AI-generated tell. Internal .md dev
notes are excluded. The WO-sticker mojibake strippers keep their dash
search targets (now written — / –). No logic changes: comments
and display strings only; validated with py_compile + lxml parse.

Rewrite the 7 customer notification emails to be intake-neutral
(ship-in / drop-off / pickup) and repair-aware, and fix the Shipped
email documents line (packing slip vs bill of lading; certificate only
when issued). Subjects use a hyphen separator.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 00:16:19 -04:00

89 lines
3.4 KiB
Python

# -*- 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):
"""Wire reports onto mail templates + clean up double-attach flags.
Both the mail-template and fp.notification.template XML records
are tagged noupdate="1" so user customizations aren't overwritten
on module update. This hook runs once to:
1. Point report_template_ids at the current branded reports.
2. Turn off attach_quotation / attach_sale_order / attach_invoice
flags on fp.notification.template - those would duplicate the
PDF that's now auto-attached via the mail template's
report_template_ids.
"""
# 1. Attach correct reports to mail templates
_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_sale_portrait',
)
_apply_report_template(
env,
'fusion_plating_notifications.fp_mail_template_invoice_posted',
'fusion_plating_reports.action_report_fp_invoice_portrait',
)
# 2. Clear duplicate-attach flags on the auto-dispatch records.
# The PDF is already auto-attached by the mail.template's
# report_template_ids; leaving these flags on produces 2 PDFs.
for xmlid, flags in [
('fusion_plating_notifications.fp_notif_quote_sent',
{'attach_quotation': False}),
('fusion_plating_notifications.fp_notif_so_confirmed',
{'attach_sale_order': False}),
('fusion_plating_notifications.fp_notif_invoice_posted',
{'attach_invoice': False}),
]:
rec = env.ref(xmlid, raise_if_not_found=False)
if not rec:
continue
needs_write = any(rec[k] != v for k, v in flags.items())
if needs_write:
rec.write(flags)
_logger.info(
'fusion_plating_notifications: cleared duplicate-attach '
'flags on %s (%s)', xmlid, flags,
)
def _apply_report_template(env, mail_template_xmlid, report_xmlid):
"""Replace the template's report_template_ids with exactly [report].
We use `set` semantics (replace all) rather than `add` so that old
attachments from previous refactors get cleaned up - e.g. when the
Acknowledgement report was consolidated into the Sales Order report,
the now-stale Acknowledgement reference gets removed here.
"""
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
current_ids = set(mail_template.report_template_ids.ids)
if current_ids != {report.id}:
mail_template.write({
'report_template_ids': [(6, 0, [report.id])],
})
_logger.info(
'fusion_plating_notifications: set report %s on template %s',
report_xmlid, mail_template_xmlid,
)