Files
Odoo-Modules/fusion_plating/fusion_plating_notifications/hooks.py
gsinghpal f09bef9083 refactor(reports): consolidate SO Acknowledgement back into the Sales Order PDF
Earlier I built report_fp_so_acknowledgement.xml as a separate
customer-facing document. On review there was no good reason — our
existing report_fp_sale.xml already flips its title between
"Quotation" and "Sales Order" based on state, and carried ~90% of
the same content. Two documents would have meant the shop had to
remember which to send when, and the customer would get two
near-identical PDFs in their inbox.

Consolidation:

1. Merged the four unique blocks from the acknowledgement into
   report_fp_sale.xml (both portrait AND landscape variants):
   - CUSTOMER JOB # / PLANNED START / CUSTOMER DEADLINE / SHIP VIA
     info row (shown only when any of those fields is populated)
   - Blanket / block-partial highlight-box callout (shown only
     when the flags are set)
   - External notes (x_fc_external_note) block above Terms and
     Conditions

2. Deleted fusion_plating_reports/report/report_fp_so_acknowledgement.xml
   and removed it from the module manifest. Also purged the orphan
   ir.actions.report and ir.ui.view DB rows + the stale
   ir.model.data entries.

3. Re-pointed the fp_mail_template_so_confirmed mail template's
   report_template_ids from the now-gone acknowledgement report to
   action_report_fp_sale_portrait. Updated hooks.py accordingly; the
   hook now uses "set" semantics (replace all) instead of "add" so
   re-running it cleans up stale attachments from prior refactors.

4. UAT on S00071: the Send button pre-selects the FP: Order
   Confirmation template with SalesOrder_S00071.pdf attached. The
   PDF renders with the new plating rows populated — Customer Job #
   AMPH-2026-0420-01, Customer Deadline 05/14/2026 08:00:00 PM,
   "Partial shipments blocked" callout, all lines + totals.

One PDF, one Send button behaviour, matching what Odoo and most
ERP systems do.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 01:30:06 -04:00

63 lines
2.3 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):
"""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_sale_portrait',
)
_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):
"""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,
)