changes
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
{
|
||||
'name': 'Fusion Plating — Notifications',
|
||||
'version': '19.0.4.0.0',
|
||||
'version': '19.0.4.1.0',
|
||||
'category': 'Manufacturing/Plating',
|
||||
'summary': 'Auto-email notifications at workflow milestones with configurable templates, PDF attachments, and audit log.',
|
||||
'author': 'Nexa Systems Inc.',
|
||||
@@ -35,6 +35,7 @@
|
||||
'views/fp_notification_log_views.xml',
|
||||
'views/fp_notifications_menu.xml',
|
||||
],
|
||||
'post_init_hook': 'post_init_hook',
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
|
||||
@@ -61,6 +61,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
<field name="report_template_ids"
|
||||
eval="[(6, 0, [ref('fusion_plating_reports.action_report_fp_sale_portrait')])]"/>
|
||||
<field name="report_name">Quotation_{{ (object.name or '').replace('/','_') }}</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================= -->
|
||||
@@ -118,6 +121,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
<field name="report_template_ids"
|
||||
eval="[(6, 0, [ref('fusion_plating_reports.action_report_fp_so_acknowledgement')])]"/>
|
||||
<field name="report_name">Acknowledgement_{{ (object.name or '').replace('/','_') }}</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================= -->
|
||||
@@ -342,6 +348,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
<field name="report_template_ids"
|
||||
eval="[(6, 0, [ref('fusion_plating_reports.action_report_fp_invoice_portrait')])]"/>
|
||||
<field name="report_name">Invoice_{{ (object.name or '').replace('/','_') }}</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================= -->
|
||||
|
||||
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,
|
||||
)
|
||||
@@ -9,6 +9,24 @@ from odoo import models
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def _get_mail_template(self):
|
||||
"""Prefer the Fusion Plating-branded invoice template over Odoo default.
|
||||
|
||||
Called by the account.move.send wizard when the user clicks
|
||||
"Send" on an invoice. Override returns our
|
||||
fp_mail_template_invoice_posted (which attaches the branded
|
||||
Invoice PDF) for out_invoice moves. Credit notes / self-billing
|
||||
fall back to Odoo's built-in templates.
|
||||
"""
|
||||
if all(m.move_type == 'out_invoice' for m in self):
|
||||
tpl = self.env.ref(
|
||||
'fusion_plating_notifications.fp_mail_template_invoice_posted',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
if tpl:
|
||||
return tpl
|
||||
return super()._get_mail_template()
|
||||
|
||||
def action_post(self):
|
||||
res = super().action_post()
|
||||
Dispatch = self.env['fp.notification.template']
|
||||
|
||||
@@ -9,6 +9,40 @@ from odoo import models
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def _find_mail_template(self):
|
||||
"""Prefer Fusion Plating-branded templates over Odoo defaults.
|
||||
|
||||
Called by sale.order.action_quotation_send (the "Send" button on
|
||||
both quotations and confirmed orders) to resolve the template
|
||||
the composer pre-selects.
|
||||
|
||||
Override returns:
|
||||
- state in ('draft', 'sent') -> fp_mail_template_quote_sent
|
||||
(attaches Quotation PDF)
|
||||
- state == 'sale' or 'done' -> fp_mail_template_so_confirmed
|
||||
(attaches Acknowledgement PDF)
|
||||
|
||||
Falls back to Odoo's default template if ours can't be resolved
|
||||
(e.g. fusion_plating_reports not installed, or template record
|
||||
missing).
|
||||
"""
|
||||
self.ensure_one()
|
||||
ref = self.env.ref
|
||||
if self.env.context.get('proforma'):
|
||||
return super()._find_mail_template()
|
||||
fp_tpl = False
|
||||
if self.state in ('draft', 'sent'):
|
||||
fp_tpl = ref(
|
||||
'fusion_plating_notifications.fp_mail_template_quote_sent',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
elif self.state in ('sale', 'done'):
|
||||
fp_tpl = ref(
|
||||
'fusion_plating_notifications.fp_mail_template_so_confirmed',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
return fp_tpl or super()._find_mail_template()
|
||||
|
||||
def action_quotation_send(self):
|
||||
"""Fire the quote_sent trigger when a quotation is emailed."""
|
||||
res = super().action_quotation_send()
|
||||
|
||||
Reference in New Issue
Block a user