feat(notifications): workflow hooks + views + menu
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,4 +3,56 @@
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
# Placeholder — implemented in Task 3.
|
||||
import logging
|
||||
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def action_post(self):
|
||||
res = super().action_post()
|
||||
for move in self:
|
||||
if move.move_type == 'out_invoice' and move.partner_id:
|
||||
# Find linked SO
|
||||
so = False
|
||||
if move.invoice_origin:
|
||||
so = self.env['sale.order'].search(
|
||||
[('name', '=', move.invoice_origin)], limit=1,
|
||||
)
|
||||
self._send_fp_notification(
|
||||
'invoice_posted', move, move.partner_id, sale_order=so,
|
||||
)
|
||||
return res
|
||||
|
||||
def _send_fp_notification(self, trigger_event, record, partner, sale_order=None):
|
||||
"""Send a notification email and log it."""
|
||||
template = self.env['fp.notification.template'].search(
|
||||
[('trigger_event', '=', trigger_event), ('active', '=', True)], limit=1,
|
||||
)
|
||||
if not template or not template.mail_template_id:
|
||||
return
|
||||
try:
|
||||
template.mail_template_id.send_mail(record.id, force_send=False)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'sent',
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning('FP notification failed (%s): %s', trigger_event, e)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'failed',
|
||||
'error_message': str(e),
|
||||
})
|
||||
|
||||
@@ -3,4 +3,50 @@
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
# Placeholder — implemented in Task 3.
|
||||
import logging
|
||||
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FpReceiving(models.Model):
|
||||
_inherit = 'fp.receiving'
|
||||
|
||||
def action_accept(self):
|
||||
res = super().action_accept()
|
||||
for rec in self:
|
||||
self._send_fp_notification(
|
||||
'parts_received', rec, rec.partner_id,
|
||||
sale_order=rec.sale_order_id,
|
||||
)
|
||||
return res
|
||||
|
||||
def _send_fp_notification(self, trigger_event, record, partner, sale_order=None):
|
||||
"""Send a notification email and log it."""
|
||||
template = self.env['fp.notification.template'].search(
|
||||
[('trigger_event', '=', trigger_event), ('active', '=', True)], limit=1,
|
||||
)
|
||||
if not template or not template.mail_template_id:
|
||||
return
|
||||
try:
|
||||
template.mail_template_id.send_mail(record.id, force_send=False)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'sent',
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning('FP notification failed (%s): %s', trigger_event, e)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'failed',
|
||||
'error_message': str(e),
|
||||
})
|
||||
|
||||
@@ -3,4 +3,49 @@
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
# Placeholder — implemented in Task 3.
|
||||
import logging
|
||||
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def action_confirm(self):
|
||||
res = super().action_confirm()
|
||||
for order in self:
|
||||
self._send_fp_notification(
|
||||
'so_confirmed', order, order.partner_id, sale_order=order,
|
||||
)
|
||||
return res
|
||||
|
||||
def _send_fp_notification(self, trigger_event, record, partner, sale_order=None):
|
||||
"""Send a notification email and log it."""
|
||||
template = self.env['fp.notification.template'].search(
|
||||
[('trigger_event', '=', trigger_event), ('active', '=', True)], limit=1,
|
||||
)
|
||||
if not template or not template.mail_template_id:
|
||||
return
|
||||
try:
|
||||
template.mail_template_id.send_mail(record.id, force_send=False)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'sent',
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning('FP notification failed (%s): %s', trigger_event, e)
|
||||
self.env['fp.notification.log'].create({
|
||||
'template_id': template.id,
|
||||
'trigger_event': trigger_event,
|
||||
'sale_order_id': sale_order.id if sale_order else False,
|
||||
'partner_id': partner.id if partner else False,
|
||||
'recipient_email': partner.email if partner else '',
|
||||
'status': 'failed',
|
||||
'error_message': str(e),
|
||||
})
|
||||
|
||||
@@ -1,3 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Log — List -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_log_list" model="ir.ui.view">
|
||||
<field name="name">fp.notification.log.list</field>
|
||||
<field name="model">fp.notification.log</field>
|
||||
<field name="arch" type="xml">
|
||||
<list default_order="sent_date desc">
|
||||
<field name="sent_date"/>
|
||||
<field name="trigger_event"/>
|
||||
<field name="partner_id" string="Customer"/>
|
||||
<field name="recipient_email"/>
|
||||
<field name="status" widget="badge"
|
||||
decoration-success="status == 'sent'"
|
||||
decoration-danger="status == 'failed'"/>
|
||||
<field name="template_id"/>
|
||||
</list>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Log — Form -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_log_form" model="ir.ui.view">
|
||||
<field name="name">fp.notification.log.form</field>
|
||||
<field name="model">fp.notification.log</field>
|
||||
<field name="arch" type="xml">
|
||||
<form edit="0">
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="sent_date"/>
|
||||
<field name="trigger_event"/>
|
||||
<field name="template_id"/>
|
||||
<field name="status" widget="badge"
|
||||
decoration-success="status == 'sent'"
|
||||
decoration-danger="status == 'failed'"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="partner_id" string="Customer"/>
|
||||
<field name="recipient_email"/>
|
||||
<field name="sale_order_id"/>
|
||||
<field name="mail_mail_id"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="Attachments" invisible="not attachment_names">
|
||||
<field name="attachment_names" nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
<group string="Error Details" invisible="status != 'failed'">
|
||||
<field name="error_message" nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Log — Search -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_log_search" model="ir.ui.view">
|
||||
<field name="name">fp.notification.log.search</field>
|
||||
<field name="model">fp.notification.log</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="partner_id" string="Customer"/>
|
||||
<field name="trigger_event"/>
|
||||
<separator/>
|
||||
<filter name="filter_sent" string="Sent"
|
||||
domain="[('status', '=', 'sent')]"/>
|
||||
<filter name="filter_failed" string="Failed"
|
||||
domain="[('status', '=', 'failed')]"/>
|
||||
<separator/>
|
||||
<filter name="filter_today" string="Today"
|
||||
domain="[('sent_date', '>=', (context_today()).strftime('%Y-%m-%d'))]"/>
|
||||
<filter name="filter_this_week" string="This Week"
|
||||
domain="[('sent_date', '>=', (context_today() - datetime.timedelta(days=context_today().weekday())).strftime('%Y-%m-%d'))]"/>
|
||||
<separator/>
|
||||
<group expand="1">
|
||||
<filter name="group_trigger" string="Trigger Event"
|
||||
context="{'group_by': 'trigger_event'}"/>
|
||||
<filter name="group_status" string="Status"
|
||||
context="{'group_by': 'status'}"/>
|
||||
<filter name="group_partner" string="Customer"
|
||||
context="{'group_by': 'partner_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Log — Action -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="action_fp_notification_log" model="ir.actions.act_window">
|
||||
<field name="name">Notification Log</field>
|
||||
<field name="res_model">fp.notification.log</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="search_view_id" ref="view_fp_notification_log_search"/>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
No notifications sent yet
|
||||
</p>
|
||||
<p>
|
||||
This log records every notification email sent by the system,
|
||||
including failures for troubleshooting.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,3 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Template — List -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_template_list" model="ir.ui.view">
|
||||
<field name="name">fp.notification.template.list</field>
|
||||
<field name="model">fp.notification.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<list decoration-muted="not active">
|
||||
<field name="name"/>
|
||||
<field name="trigger_event"/>
|
||||
<field name="mail_template_id"/>
|
||||
<field name="active" widget="boolean_toggle"/>
|
||||
</list>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Template — Form -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_template_form" model="ir.ui.view">
|
||||
<field name="name">fp.notification.template.form</field>
|
||||
<field name="model">fp.notification.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
<h1>
|
||||
<field name="name" placeholder="e.g. Order Confirmed Notification"/>
|
||||
</h1>
|
||||
</div>
|
||||
<group>
|
||||
<group>
|
||||
<field name="trigger_event"/>
|
||||
<field name="mail_template_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="active" widget="boolean_toggle"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="Attachments">
|
||||
<group>
|
||||
<field name="attach_coc"/>
|
||||
<field name="attach_thickness_report"/>
|
||||
<field name="attach_invoice"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="attach_packing_list"/>
|
||||
<field name="attach_pod"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="CC Recipients">
|
||||
<field name="cc_internal_ids" widget="many2many_tags" nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Template — Search -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="view_fp_notification_template_search" model="ir.ui.view">
|
||||
<field name="name">fp.notification.template.search</field>
|
||||
<field name="model">fp.notification.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name"/>
|
||||
<field name="trigger_event"/>
|
||||
<filter name="filter_active" string="Active" domain="[('active', '=', True)]"/>
|
||||
<filter name="filter_inactive" string="Inactive" domain="[('active', '=', False)]"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Template — Action -->
|
||||
<!-- ============================================================ -->
|
||||
<record id="action_fp_notification_template" model="ir.actions.act_window">
|
||||
<field name="name">Notification Templates</field>
|
||||
<field name="res_model">fp.notification.template</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="search_view_id" ref="view_fp_notification_template_search"/>
|
||||
<field name="context">{'active_test': False}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Create a notification template
|
||||
</p>
|
||||
<p>
|
||||
Map trigger events to email templates to automatically notify
|
||||
customers at key workflow milestones.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<menuitem id="menu_fp_notification_templates"
|
||||
name="Notification Templates"
|
||||
parent="fusion_plating.menu_fp_config"
|
||||
action="action_fp_notification_template"
|
||||
sequence="80"
|
||||
groups="fusion_plating.group_fusion_plating_manager"/>
|
||||
|
||||
<menuitem id="menu_fp_notification_log"
|
||||
name="Notification Log"
|
||||
parent="fusion_plating.menu_fp_config"
|
||||
action="action_fp_notification_log"
|
||||
sequence="85"
|
||||
groups="fusion_plating.group_fusion_plating_supervisor"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user