# -*- coding: utf-8 -*- # Copyright 2024-2025 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) from odoo import models, fields, api, _ from odoo.exceptions import UserError from markupsafe import Markup import logging _logger = logging.getLogger(__name__) class ApplicationReceivedWizard(models.TransientModel): """Wizard to upload ADP application documents when application is received.""" _name = 'fusion_claims.application.received.wizard' _description = 'Application Received Wizard' sale_order_id = fields.Many2one( 'sale.order', string='Sale Order', required=True, readonly=True, ) # Document uploads original_application = fields.Binary( string='Original ADP Application', required=True, help='Upload the original ADP application PDF received from the client', ) original_application_filename = fields.Char( string='Application Filename', ) signed_pages_11_12 = fields.Binary( string='Signed Pages 11 & 12', required=True, help='Upload the signed pages 11 and 12 from the application', ) signed_pages_filename = fields.Char( string='Pages Filename', ) notes = fields.Text( string='Notes', help='Any notes about the received application', ) @api.model def default_get(self, fields_list): res = super().default_get(fields_list) active_id = self._context.get('active_id') if active_id: order = self.env['sale.order'].browse(active_id) res['sale_order_id'] = order.id # Pre-fill if documents already exist if order.x_fc_original_application: res['original_application'] = order.x_fc_original_application res['original_application_filename'] = order.x_fc_original_application_filename if order.x_fc_signed_pages_11_12: res['signed_pages_11_12'] = order.x_fc_signed_pages_11_12 res['signed_pages_filename'] = order.x_fc_signed_pages_filename return res @api.constrains('original_application_filename') def _check_application_file_type(self): for wizard in self: if wizard.original_application_filename: if not wizard.original_application_filename.lower().endswith('.pdf'): raise UserError( "Original Application must be a PDF file.\n" f"Uploaded file: '{wizard.original_application_filename}'" ) @api.constrains('signed_pages_filename') def _check_pages_file_type(self): for wizard in self: if wizard.signed_pages_filename: if not wizard.signed_pages_filename.lower().endswith('.pdf'): raise UserError( "Signed Pages 11 & 12 must be a PDF file.\n" f"Uploaded file: '{wizard.signed_pages_filename}'" ) def action_confirm(self): """Save documents and mark application as received.""" self.ensure_one() order = self.sale_order_id if order.x_fc_adp_application_status not in ('assessment_completed', 'waiting_for_application'): raise UserError("Can only receive application from 'Waiting for Application' status.") # Validate files are uploaded if not self.original_application: raise UserError("Please upload the Original ADP Application.") if not self.signed_pages_11_12: raise UserError("Please upload the Signed Pages 11 & 12.") # Update sale order with documents order.with_context(skip_status_validation=True).write({ 'x_fc_adp_application_status': 'application_received', 'x_fc_original_application': self.original_application, 'x_fc_original_application_filename': self.original_application_filename, 'x_fc_signed_pages_11_12': self.signed_pages_11_12, 'x_fc_signed_pages_filename': self.signed_pages_filename, }) # Post to chatter from datetime import date notes_html = f'
Notes: {self.notes}
' if self.notes else '' order.message_post( body=Markup( 'Date: {date.today().strftime("%B %d, %Y")}
' 'Documents Uploaded:
' '