# -*- coding: utf-8 -*- # Copyright 2024-2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) """ MOD Submission Path Wizard — asks the office which party is submitting the March of Dimes application. Sets x_fc_mod_submitted_by on the order and, when the path is 'internal', auto-triggers the VOD request email to the authorizer the first time it is selected. """ from odoo import models, fields, api, _ from odoo.exceptions import UserError from markupsafe import Markup class ModSubmissionPathWizard(models.TransientModel): _name = 'fusion_claims.mod.submission.path.wizard' _description = 'MOD - Set Submission Path' sale_order_id = fields.Many2one('sale.order', required=True, readonly=True) submitted_by = fields.Selection( selection=[ ('internal', 'We submit on client\'s behalf'), ('client', 'Client submits themselves'), ('authorizer', 'Authorizer (OT) submits'), ], string='Who is submitting to March of Dimes?', required=True, ) notes = fields.Text(string='Notes') @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 if order.x_fc_mod_submitted_by: res['submitted_by'] = order.x_fc_mod_submitted_by return res def action_confirm(self): self.ensure_one() order = self.sale_order_id previous = order.x_fc_mod_submitted_by vals = {'x_fc_mod_submitted_by': self.submitted_by} order.with_context(skip_status_emails=True).write(vals) labels = dict(self._fields['submitted_by'].selection) body = ( f'' order.message_post( body=Markup(body), message_type='notification', subtype_xmlid='mail.mt_note', ) # First-time internal path → auto-trigger the VOD request email so # the authorizer knows to fill and send the VOD form back. if ( self.submitted_by == 'internal' and previous != 'internal' and not order.x_fc_mod_vod_requested_date ): try: order._send_mod_vod_request_email() except Exception: # Don't block the wizard if the email fails — office can # retry via the manual "Request VOD" button. pass return {'type': 'ir.actions.act_window_close'}