# -*- coding: utf-8 -*- # Copyright 2024-2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) """ MOD Funding Denied Wizard — captures the denial reason and sets the order status. Previously action_mod_funding_denied was a bare write with no reason capture; this wizard replaces that flow. """ from odoo import models, fields, api, _ from odoo.exceptions import UserError from markupsafe import Markup class ModFundingDeniedWizard(models.TransientModel): _name = 'fusion_claims.mod.funding.denied.wizard' _description = 'MOD - Funding Denied Reason Capture' sale_order_id = fields.Many2one('sale.order', required=True, readonly=True) denial_date = fields.Date( string='Denial Date', required=True, default=fields.Date.context_today, ) denial_reason_category = fields.Selection( selection=[ ('income_too_high', 'Client income exceeds MOD threshold'), ('residency', 'Residency requirement not met'), ('project_scope', 'Project scope not eligible'), ('missing_docs', 'Missing documentation'), ('funding_depleted', 'MOD funding depleted for this period'), ('other', 'Other'), ], string='Denial Category', required=True, ) denial_reason = fields.Text( string='Denial Details', required=True, help='MOD\'s stated reason for denying funding. Captured for the ' 'audit trail and used when generating the client denial email.', ) @api.model def default_get(self, fields_list): res = super().default_get(fields_list) if self.env.context.get('active_id'): order = self.env['sale.order'].browse(self.env.context['active_id']) res['sale_order_id'] = order.id return res def action_confirm(self): self.ensure_one() order = self.sale_order_id if order.x_fc_mod_status not in ('awaiting_funding', 'quote_submitted', 'handoff_to_client'): raise UserError( _("Funding can only be denied from awaiting_funding, " "quote_submitted or handoff_to_client. Current: %s") % order.x_fc_mod_status ) labels = dict(self._fields['denial_reason_category'].selection) category_label = labels.get(self.denial_reason_category, self.denial_reason_category) full_reason = f'[{category_label}] {self.denial_reason}' order.write({ 'x_fc_mod_status': 'funding_denied', 'x_fc_mod_funding_denial_reason': full_reason, }) body = ( f'