<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2024-2025 Nexa Systems Inc.
    License OPL-1 (Odoo Proprietary License v1.0)
    Part of the Fusion Claim Assistant product family.
-->
<odoo>
    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: Header Fields -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_header" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.header</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">50</field>
        <field name="arch" type="xml">
            <!-- Add hidden helper fields and visible Sale Info fields after payment_term_id -->
            <xpath expr="//field[@name='payment_term_id']" position="after">
                <!-- Hidden helper fields -->
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <field name="x_fc_has_unapproved_devices" invisible="1"/>
                <field name="x_fc_device_verification_complete" invisible="1"/>
                <field name="x_fc_adp_status" invisible="1"/>
                <field name="x_fc_show_authorizer" invisible="1"/>
                <field name="x_fc_show_authorizer_question" invisible="1"/>
                
                <!-- Sale Type -->
                <field name="x_fc_sale_type" string="Sale Type"/>
                
                <!-- Authorizer Required? - only for odsp, direct_private, insurance, other (not rental) -->
                <field name="x_fc_authorizer_required" string="Authorizer Required?"
                       invisible="not x_fc_show_authorizer_question"/>
                
                <!-- Authorizer - shown based on sale type and authorizer_required -->
                <field name="x_fc_authorizer_id" string="Authorizer"
                       options="{'no_create': False, 'no_quick_create': False}"
                       invisible="not x_fc_show_authorizer"
                       required="x_fc_is_adp_sale"/>
                       
                <!-- Client Type - only for ADP sales -->
                <field name="x_fc_client_type" string="Client Type"
                       invisible="x_fc_sale_type not in ('adp', 'adp_odsp')"/>
                       
            </xpath>
        </field>
    </record>
    
    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: Move Salesperson to header (after Quotation Template) -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_salesperson" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.salesperson</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">51</field>
        <field name="arch" type="xml">
            <field name="sale_order_template_id" position="after">
                <field name="user_id" widget="many2one_avatar_user"/>
            </field>
            <xpath expr="//page[@name='other_information']//field[@name='user_id']" position="replace"/>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: March of Dimes Case Details -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_mod" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.mod</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">49</field>
        <field name="arch" type="xml">
            <!-- MOD Case Details after sale header -->
            <xpath expr="//group[@name='sale_header']" position="after">
                <field name="x_fc_show_mod_fields" invisible="1"/>
                <field name="x_fc_is_mod_sale" invisible="1"/>

                <group name="mod_case_details" string="March of Dimes"
                       invisible="not x_fc_show_mod_fields">
                    <group>
                        <field name="x_fc_mod_status" string="Status"
                               required="x_fc_sale_type == 'march_of_dimes'"/>
                        <field name="x_fc_mod_product_type" string="Product Type"/>
                        <field name="x_fc_case_approved" string="Funding Approved"
                               invisible="x_fc_mod_status not in ('funding_approved', 'contract_received', 'in_production', 'project_complete', 'pod_submitted', 'case_closed')"/>
                    </group>
                    <group>
                        <field name="x_fc_estimated_completion_date" string="Est. Completion"
                               invisible="x_fc_mod_status in ('need_to_schedule', 'assessment_scheduled', 'assessment_completed', 'cancelled', False)"/>
                        <field name="x_fc_mod_estimated_weeks" string="Est. Weeks"
                               invisible="x_fc_mod_status in ('need_to_schedule', 'assessment_scheduled', 'assessment_completed', 'cancelled', False)"/>
                    </group>
                </group>

                <!-- Case Worker and PCA (visible after approval) -->
                <group name="mod_contact_pca" string="Case Worker and PCA"
                       invisible="not x_fc_show_mod_fields or x_fc_mod_status not in ('funding_approved', 'contract_received', 'in_production', 'project_complete', 'pod_submitted', 'case_closed')">
                    <group>
                        <field name="x_fc_case_worker" string="Case Worker"
                               help="Assigned by MOD after approval. Added when they contact us."/>
                        <field name="x_fc_case_reference" string="HVMP Ref #"
                               help="Starts with HVW followed by 5 digits (e.g. HVW38845)"/>
                    </group>
                    <group>
                        <field name="x_fc_mod_approval_type" string="Approval" readonly="1"/>
                        <field name="x_fc_mod_approved_amount" string="Approved Amount" readonly="1"
                               invisible="x_fc_mod_approval_type != 'partial'"/>
                    </group>
                </group>

                <!-- Production Stage -->
                <group name="mod_production" string="Production Stage"
                       invisible="not x_fc_show_mod_fields or x_fc_mod_status not in ('in_production', 'project_complete', 'contract_received')">
                    <group>
                        <field name="x_fc_mod_production_status" string="Current Stage"/>
                    </group>
                </group>

                <!-- Follow-up (only during awaiting funding) -->
                <group name="mod_followup" string="Follow-up"
                       invisible="not x_fc_show_mod_fields or x_fc_mod_status not in ('quote_submitted', 'awaiting_funding')">
                    <group>
                        <field name="x_fc_mod_last_followup_date" readonly="1"/>
                        <field name="x_fc_mod_next_followup_date" readonly="1"/>
                    </group>
                    <group>
                        <field name="x_fc_mod_followup_count" readonly="1"/>
                    </group>
                </group>

            </xpath>

            <!-- ============================================= -->
            <!-- MOD WORKFLOW BUTTONS (header) -->
            <!-- ============================================= -->
            <xpath expr="//header" position="inside">
                <field name="x_fc_is_mod_sale" invisible="1"/>

                <!-- Forward flow buttons -->
                <button name="action_mod_schedule_assessment" type="object"
                        string="Book Assessment" class="btn-info" icon="fa-calendar"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'need_to_schedule'"/>

                <button name="action_mod_complete_assessment" type="object"
                        string="Assessment Done" class="btn-info" icon="fa-check-square-o"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'assessment_scheduled'"/>

                <button name="action_mod_processing_drawing" type="object"
                        string="Submit Drawing" class="btn-info" icon="fa-pencil-square-o"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status not in ('assessment_completed', 'processing_drawings')"
                        help="Attach drawing and photos, then send quotation to March of Dimes"/>

                <button name="action_mod_awaiting_funding" type="object"
                        string="Awaiting Funding" class="btn-warning" icon="fa-clock-o"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'quote_submitted'"
                        help="Record application submission date and move to awaiting funding"/>

                <button name="action_mod_funding_approved" type="object"
                        string="Approved" class="btn-success" icon="fa-check"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'awaiting_funding'"/>

                <button name="action_mod_funding_denied" type="object"
                        string="Denied" class="btn-danger" icon="fa-times"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'awaiting_funding'"/>

                <button name="action_mod_contract_received" type="object"
                        string="PCA Received" class="btn-success" icon="fa-file-text"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'funding_approved'"
                        help="Upload PCA document and record receipt"/>

                <button name="action_mod_in_production" type="object"
                        string="Start Production" class="btn-info" icon="fa-cogs"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'contract_received'"/>

                <button name="action_mod_project_complete" type="object"
                        string="Project Done" class="btn-success" icon="fa-check-circle"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'in_production'"/>

                <button name="action_mod_pod_submitted" type="object"
                        string="Submit POD" class="btn-info" icon="fa-camera"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'project_complete'"
                        help="Attach completion photos and proof of delivery, send to case worker"/>

                <button name="action_mod_close_case" type="object"
                        string="Close Case" class="btn-primary" icon="fa-lock"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'pod_submitted'"/>

                <!-- Send to MOD -->
                <button name="action_send_to_mod" type="object"
                        string="Send to MOD" class="btn-primary" icon="fa-paper-plane"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status in ('need_to_schedule', 'assessment_scheduled', 'cancelled', False)"/>

                <!-- Exception buttons -->
                <button name="action_mod_on_hold" type="object"
                        string="Hold" class="btn-warning" icon="fa-pause"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status not in ('contract_received', 'in_production', 'project_complete')"/>

                <button name="action_mod_resume" type="object"
                        string="Resume" class="btn-success" icon="fa-play"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_status != 'on_hold'"/>

            </xpath>

            <!-- ============================================= -->
            <!-- MOD DOCUMENTS TAB (ADP-style tile design) -->
            <!-- ============================================= -->
            <xpath expr="//notebook" position="inside">
                <page string="MOD Documents" name="mod_documents"
                      invisible="not x_fc_is_mod_sale or x_fc_mod_status in ('need_to_schedule', 'cancelled', False)">

                    <!-- Hidden trail fields -->
                    <field name="x_fc_mod_trail_has_drawing" invisible="1"/>
                    <field name="x_fc_mod_trail_has_initial_photos" invisible="1"/>
                    <field name="x_fc_mod_trail_has_pca" invisible="1"/>
                    <field name="x_fc_mod_trail_has_pod" invisible="1"/>
                    <field name="x_fc_mod_trail_has_completion_photos" invisible="1"/>

                    <!-- Stage-specific alerts -->
                    <div class="alert alert-info" role="alert"
                         invisible="x_fc_mod_status not in ('assessment_completed', 'processing_drawings')">
                        <i class="fa fa-upload"/> <strong>Action Required:</strong>
                        Upload the Drawing and Initial Photos before sending the quote.
                    </div>

                    <div class="alert alert-info" role="alert"
                         invisible="x_fc_mod_status not in ('funding_approved',)">
                        <i class="fa fa-upload"/> <strong>Action Required:</strong>
                        Upload the PCA Document received from March of Dimes.
                    </div>

                    <div class="alert alert-info" role="alert"
                         invisible="x_fc_mod_status not in ('project_complete',)">
                        <i class="fa fa-camera"/> <strong>Action Required:</strong>
                        Upload Completion Photos and Proof of Delivery to submit to the case worker.
                    </div>

                    <!-- ===== Row 1: Assessment Documents ===== -->
                    <div class="row">
                        <!-- Column 1: Assessment and Design -->
                        <div class="col-md-6">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-pencil-square-o"/> Assessment &amp; Design
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Drawing Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_mod_drawing" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_mod_drawing" title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_mod_drawing"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Drawing</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_mod_drawing">
                                                <field name="x_fc_mod_drawing_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_mod_drawing">Required for quotation</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_mod_drawing" filename="x_fc_mod_drawing_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>

                                    <!-- Initial Photos Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_mod_initial_photos" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_mod_initial_photos" title="Click to preview">
                                                <i class="fa fa-image fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_mod_initial_photos"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Initial Photos</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_mod_initial_photos">
                                                <field name="x_fc_mod_initial_photos_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_mod_initial_photos">Required for quotation</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_mod_initial_photos" filename="x_fc_mod_initial_photos_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 2: PCA Document -->
                        <div class="col-md-6"
                             invisible="x_fc_mod_status in ('assessment_scheduled', 'assessment_completed', 'processing_drawings', 'quote_submitted', 'awaiting_funding', False)">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text"/> PCA / Contract
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- PCA Document Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_mod_pca" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_mod_pca_document" title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_mod_pca_document"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">PCA Document</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_mod_pca_document">
                                                <field name="x_fc_mod_pca_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_mod_pca_document">Upload when received</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_mod_pca_document" filename="x_fc_mod_pca_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- ===== Row 2: Completion Documents (visible after production) ===== -->
                    <div class="row mt-3"
                         invisible="x_fc_mod_status not in ('in_production', 'project_complete', 'pod_submitted', 'case_closed')">
                        <div class="col-md-6">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-check-circle"/> Completion Documents
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Proof of Delivery Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_mod_pod" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_mod_proof_of_delivery" title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_mod_proof_of_delivery"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Proof of Delivery</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_mod_proof_of_delivery">
                                                <field name="x_fc_mod_pod_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_mod_proof_of_delivery">Required for POD submission</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_mod_proof_of_delivery" filename="x_fc_mod_pod_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>

                                    <!-- Completion Photos Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_mod_completion_photos" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_mod_completion_photos" title="Click to preview">
                                                <i class="fa fa-image fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_mod_completion_photos"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Completion Photos</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_mod_completion_photos">
                                                <field name="x_fc_mod_completion_photos_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_mod_completion_photos">Required for POD submission</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_mod_completion_photos" filename="x_fc_mod_completion_photos_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </page>

                <!-- ============================================= -->
                <!-- MOD AUDIT TRAIL TAB -->
                <!-- ============================================= -->
                <page string="MOD Audit Trail" name="mod_audit_trail"
                      invisible="not x_fc_is_mod_sale or x_fc_mod_status in ('need_to_schedule', 'cancelled', False)">

                    <!-- Hidden trail fields -->
                    <field name="x_fc_mod_trail_assessment_done" invisible="1"/>
                    <field name="x_fc_mod_trail_drawing_done" invisible="1"/>
                    <field name="x_fc_mod_trail_app_submitted" invisible="1"/>
                    <field name="x_fc_mod_trail_funding_approved" invisible="1"/>
                    <field name="x_fc_mod_trail_pca_received" invisible="1"/>
                    <field name="x_fc_mod_trail_production_started" invisible="1"/>
                    <field name="x_fc_mod_trail_project_completed" invisible="1"/>
                    <field name="x_fc_mod_trail_pod_sent" invisible="1"/>
                    <field name="x_fc_mod_trail_case_closed" invisible="1"/>

                    <div class="row">
                        <!-- Workflow Checklist -->
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-list-alt"/> Workflow Checklist</h5>
                                </div>
                                <div class="card-body p-0">
                                    <table class="table table-striped mb-0">
                                        <tbody>
                                            <tr>
                                                <td style="width:40px; text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_assessment_done"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_assessment_done"/>
                                                </td>
                                                <td>Assessment Completed</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_has_drawing"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_has_drawing"/>
                                                </td>
                                                <td>Drawing Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_drawing_done"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_drawing_done"/>
                                                </td>
                                                <td>Quotation Sent to Client</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_app_submitted"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_app_submitted"/>
                                                </td>
                                                <td>Application Submitted to MOD</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_funding_approved"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_funding_approved"/>
                                                </td>
                                                <td>Funding Approved</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>

                        <!-- Production and Completion Checklist -->
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-check-circle"/> Production and Completion</h5>
                                </div>
                                <div class="card-body p-0">
                                    <table class="table table-striped mb-0">
                                        <tbody>
                                            <tr>
                                                <td style="width:40px; text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_pca_received"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_pca_received"/>
                                                </td>
                                                <td>PCA Received</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_production_started"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_production_started"/>
                                                </td>
                                                <td>Production Started</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_project_completed"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_project_completed"/>
                                                </td>
                                                <td>Project Completed</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_pod_sent"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_pod_sent"/>
                                                </td>
                                                <td>POD Submitted to MOD</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align:center;">
                                                    <i class="fa fa-check-circle text-success" title="Done" invisible="not x_fc_mod_trail_case_closed"/>
                                                    <i class="fa fa-circle-o text-muted" title="Pending" invisible="x_fc_mod_trail_case_closed"/>
                                                </td>
                                                <td>Case Closed</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Key Dates -->
                    <div class="row">
                        <div class="col-12">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-calendar"/> Key Dates</h5>
                                </div>
                                <div class="card-body">
                                    <group col="4">
                                        <field name="x_fc_mod_assessment_scheduled_date" readonly="1"/>
                                        <field name="x_fc_mod_assessment_completed_date" readonly="1"/>
                                        <field name="x_fc_mod_drawing_submitted_date" readonly="1"/>
                                        <field name="x_fc_mod_application_submitted_date" readonly="1"/>
                                        <field name="x_fc_case_approved" string="Funding Approved" readonly="1"/>
                                        <field name="x_fc_mod_pca_received_date" readonly="1"/>
                                        <field name="x_fc_mod_production_started_date" readonly="1"/>
                                        <field name="x_fc_mod_project_completed_date" readonly="1"/>
                                        <field name="x_fc_mod_pod_submitted_date" readonly="1"/>
                                        <field name="x_fc_mod_case_closed_date" readonly="1"/>
                                    </group>
                                </div>
                            </div>
                        </div>
                    </div>

                </page>

            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ODSP Section -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_odsp" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.odsp</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">49</field>
        <field name="arch" type="xml">
            <!-- ODSP Case Details after sale header -->
            <xpath expr="//group[@name='sale_header']" position="after">
                <field name="x_fc_show_odsp_fields" invisible="1"/>
                <field name="x_fc_is_odsp_sale" invisible="1"/>

                <group name="odsp_case_details" string="ODSP"
                       invisible="not x_fc_show_odsp_fields">
                    <group>
                        <field name="x_fc_odsp_division" string="Division"
                               required="x_fc_is_odsp_sale"/>
                        <field name="x_fc_sa_status" string="Status"
                               invisible="x_fc_odsp_division != 'sa_mobility'"/>
                        <field name="x_fc_odsp_std_status" string="Status"
                               invisible="x_fc_odsp_division != 'standard'"/>
                        <field name="x_fc_ow_status" string="Status"
                               invisible="x_fc_odsp_division != 'ontario_works'"/>
                        <field name="x_fc_odsp_member_id" string="Member ID"/>
                    </group>
                    <group>
                        <field name="x_fc_odsp_office_id" string="ODSP Office"/>
                        <field name="x_fc_odsp_case_worker_name" string="Case Worker"/>
                    </group>
                </group>
            </xpath>

            <!-- ODSP Workflow buttons in header -->
            <xpath expr="//header" position="inside">

                <!-- === SA Mobility workflow step buttons === -->
                <button name="action_odsp_pre_approved" type="object"
                        string="Pre-Approved" class="btn-success" icon="fa-check"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'submitted_to_sa'"/>

                <button name="action_odsp_ready_delivery" type="object"
                        string="Ready for Delivery" class="btn-primary" icon="fa-truck"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'pre_approved'"/>

                <button name="action_odsp_delivered" type="object"
                        string="Delivered" class="btn-success" icon="fa-check-circle"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'ready_delivery'"/>

                <button name="action_odsp_pod_submitted" type="object"
                        string="Submit to SA Mobility" class="btn-info" icon="fa-paper-plane"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'delivered'"
                        help="Submit POD, signed SA form, and invoice to SA Mobility"/>

                <button name="action_odsp_payment_received" type="object"
                        string="Payment Received" class="btn-success" icon="fa-money"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'pod_submitted'"/>

                <button name="action_odsp_close_case" type="object"
                        string="Close Case" class="btn-primary" icon="fa-lock"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status != 'payment_received'"/>

                <!-- === Standard ODSP workflow step buttons === -->
                <button name="action_odsp_pre_approved" type="object"
                        string="Pre-Approved" class="btn-success" icon="fa-check"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'submitted_to_odsp'"/>

                <button name="action_odsp_ready_delivery" type="object"
                        string="Ready for Delivery" class="btn-primary" icon="fa-truck"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'pre_approved'"/>

                <button name="action_odsp_delivered" type="object"
                        string="Delivered" class="btn-success" icon="fa-check-circle"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'ready_delivery'"/>

                <button name="action_odsp_pod_submitted" type="object"
                        string="Submit to ODSP" class="btn-info" icon="fa-paper-plane"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'delivered'"
                        help="Submit approval document, POD, and invoice to ODSP"/>

                <button name="action_odsp_payment_received" type="object"
                        string="Payment Received" class="btn-success" icon="fa-money"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'pod_submitted'"/>

                <button name="action_odsp_close_case" type="object"
                        string="Close Case" class="btn-primary" icon="fa-lock"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status != 'payment_received'"/>

                <!-- === Ontario Works workflow step buttons === -->
                <button name="action_odsp_submitted_ow" type="object"
                        string="Submitted to Ontario Works" class="btn-info" icon="fa-paper-plane"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status != 'documents_ready'"/>

                <button name="action_odsp_payment_received" type="object"
                        string="Payment Confirmed" class="btn-success" icon="fa-money"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status != 'submitted_to_ow'"
                        help="OW confirmed payment. Creates invoice and opens it."/>

                <button name="action_odsp_ready_delivery" type="object"
                        string="Ready for Delivery" class="btn-primary" icon="fa-truck"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status != 'payment_received'"/>

                <button name="action_odsp_delivered" type="object"
                        string="Delivered" class="btn-success" icon="fa-check-circle"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status != 'ready_delivery'"/>

                <button name="action_odsp_close_case" type="object"
                        string="Close Case" class="btn-primary" icon="fa-lock"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status != 'delivered'"/>

                <!-- === Common buttons (all divisions) === -->
                <button name="action_odsp_on_hold" type="object"
                        string="On Hold" class="btn-warning" icon="fa-pause"
                        invisible="not x_fc_is_odsp_sale or (x_fc_odsp_division == 'sa_mobility' and x_fc_sa_status in ('quotation', 'case_closed', 'cancelled', 'denied', 'on_hold')) or (x_fc_odsp_division == 'standard' and x_fc_odsp_std_status in ('quotation', 'case_closed', 'cancelled', 'denied', 'on_hold')) or (x_fc_odsp_division == 'ontario_works' and x_fc_ow_status in ('quotation', 'case_closed', 'cancelled', 'denied', 'on_hold'))"/>

                <button name="action_odsp_resume" type="object"
                        string="Resume" class="btn-success" icon="fa-play"
                        invisible="not x_fc_is_odsp_sale or (x_fc_odsp_division == 'sa_mobility' and x_fc_sa_status != 'on_hold') or (x_fc_odsp_division == 'standard' and x_fc_odsp_std_status != 'on_hold') or (x_fc_odsp_division == 'ontario_works' and x_fc_ow_status != 'on_hold')"/>

                <button name="action_odsp_denied" type="object"
                        string="Denied" class="btn-danger" icon="fa-times"
                        invisible="not x_fc_is_odsp_sale or (x_fc_odsp_division == 'sa_mobility' and x_fc_sa_status not in ('submitted_to_sa',)) or (x_fc_odsp_division == 'standard' and x_fc_odsp_std_status not in ('submitted_to_odsp',)) or (x_fc_odsp_division == 'ontario_works' and x_fc_ow_status not in ('submitted_to_ow',))"/>

                <!-- === Form filling buttons (always visible for division) === -->
                <button name="action_open_sa_mobility_wizard" type="object"
                        string="SA Mobility Form" class="btn-info" icon="fa-file-text"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility'"/>

                <button name="action_open_discretionary_wizard" type="object"
                        string="Discretionary Form" class="btn-info" icon="fa-file-text"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works'"/>

                <button name="action_open_submit_to_odsp_wizard" type="object"
                        string="Submit to ODSP" class="btn-info" icon="fa-paper-plane"
                        invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard'"/>

            </xpath>

            <!-- ODSP Signature tab in notebook -->
            <xpath expr="//notebook" position="inside">
                <page string="SA Mobility Documents" name="sa_mobility_signature"
                      invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'sa_mobility' or x_fc_sa_status not in ('pre_approved', 'ready_delivery', 'delivered', 'pod_submitted', 'payment_received', 'case_closed')">

                    <div class="row">
                        <!-- Column 1: ODSP Approval Form -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text-o"/> ODSP Approval Form
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_sa_approval_form" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_sa_approval_form"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_sa_approval_form"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Approval Form</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_sa_approval_form">
                                                <field name="x_fc_sa_approval_form_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_sa_approval_form">Upload ODSP approval PDF</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_sa_approval_form" filename="x_fc_sa_approval_form_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                                <group class="mt-2">
                                    <field name="x_fc_sa_signature_page" string="Signature Page"/>
                                </group>
                            </div>
                        </div>

                        <!-- Column 2: Signed Form (auto-generated or physical copy) -->
                        <div class="col-md-4"
                             invisible="x_fc_sa_status not in ('ready_delivery', 'delivered', 'pod_submitted', 'payment_received', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-pencil-square-o"/> Signed Form
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Auto-generated signed form tile -->
                                    <div class="fc-document-tile" invisible="not x_fc_sa_signed_form">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_sa_signed_form" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Signed Form (Digital)</div>
                                            <div class="fc-tile-filename">
                                                <field name="x_fc_sa_signed_form_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Physical signed copy tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_sa_physical_copy" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_sa_physical_signed_copy"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_sa_physical_signed_copy"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Physical Signed Copy</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_sa_physical_signed_copy">
                                                <field name="x_fc_sa_physical_signed_copy_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_sa_physical_signed_copy">Upload scanned signed form</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_sa_physical_signed_copy" filename="x_fc_sa_physical_signed_copy_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 3: Internal POD (generated from report on-the-fly) -->
                        <div class="col-md-4"
                             invisible="x_fc_sa_status not in ('delivered', 'pod_submitted', 'payment_received', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text"/> Internal POD
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile" invisible="not x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_sa_internal_pod" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    title="Click to print POD">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Proof of Delivery</div>
                                            <div class="fc-tile-filename">
                                                Signed by <field name="x_fc_pod_client_name" nolabel="1" class="d-inline"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="fc-document-tile" invisible="x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <i class="fa fa-clock-o fc-empty-icon"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-empty-text">Available after POD is signed</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <field name="x_fc_sa_signed_form" invisible="1"/>
                    <field name="x_fc_sa_signed_form_filename" invisible="1"/>
                </page>

                <!-- Ontario Works Documents tab -->
                <page string="Ontario Works Documents" name="ow_documents"
                      invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'ontario_works' or x_fc_ow_status == 'quotation'">

                    <div class="row">
                        <!-- Column 1: Discretionary Benefits Form -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text-o"/> Discretionary Benefits Form
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_ow_discretionary_form" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_ow_discretionary_form"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-clock-o fc-empty-icon" invisible="x_fc_ow_discretionary_form"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Discretionary Form</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_ow_discretionary_form">
                                                <field name="x_fc_ow_discretionary_form_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_ow_discretionary_form">Generated when form is sent via wizard</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 2: Internal POD -->
                        <div class="col-md-4"
                             invisible="x_fc_ow_status not in ('delivered', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text"/> Proof of Delivery
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile" invisible="not x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_ow_internal_pod" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    title="Click to print POD">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Proof of Delivery</div>
                                            <div class="fc-tile-filename">
                                                Signed by <field name="x_fc_pod_client_name" nolabel="1" class="d-inline"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="fc-document-tile" invisible="x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <i class="fa fa-clock-o fc-empty-icon"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-empty-text">Available after delivery is completed</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 3: Authorizer Letter (optional upload) -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-envelope-o"/> Authorizer Letter
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_ow_authorizer_letter" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_ow_authorizer_letter"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_ow_authorizer_letter"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Authorizer Letter</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_ow_authorizer_letter">
                                                <field name="x_fc_ow_authorizer_letter_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_ow_authorizer_letter">Upload authorizer letter (optional)</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_ow_authorizer_letter" filename="x_fc_ow_authorizer_letter_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <field name="x_fc_ow_discretionary_form" invisible="1"/>
                </page>

                <!-- Standard ODSP Documents tab -->
                <page string="ODSP Documents" name="odsp_std_documents"
                      invisible="not x_fc_is_odsp_sale or x_fc_odsp_division != 'standard' or x_fc_odsp_std_status == 'quotation'">

                    <div class="row">
                        <!-- Column 1: Authorizer Letter -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-envelope-o"/> Authorizer Letter
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_odsp_std_authorizer_letter" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_odsp_authorizer_letter"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_odsp_authorizer_letter"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Authorizer Letter</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_odsp_authorizer_letter">
                                                <field name="x_fc_odsp_authorizer_letter_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_odsp_authorizer_letter">Uploaded via Submit to ODSP wizard</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_odsp_authorizer_letter" filename="x_fc_odsp_authorizer_letter_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 2: ODSP Approval Document -->
                        <div class="col-md-4"
                             invisible="x_fc_odsp_std_status not in ('pre_approved', 'ready_delivery', 'delivered', 'pod_submitted', 'payment_received', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-check-circle-o"/> Approval Document
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_odsp_std_approval_document" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_odsp_approval_document"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_odsp_approval_document"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Approval Document</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_odsp_approval_document">
                                                <field name="x_fc_odsp_approval_document_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_odsp_approval_document">Uploaded during pre-approval</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_odsp_approval_document" filename="x_fc_odsp_approval_document_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 3: Internal POD -->
                        <div class="col-md-4"
                             invisible="x_fc_odsp_std_status not in ('delivered', 'pod_submitted', 'payment_received', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text"/> Proof of Delivery
                                </div>
                                <div class="fc-document-tiles">
                                    <div class="fc-document-tile" invisible="not x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_odsp_std_internal_pod" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    title="Click to print POD">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Proof of Delivery</div>
                                            <div class="fc-tile-filename">
                                                Signed by <field name="x_fc_pod_client_name" nolabel="1" class="d-inline"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="fc-document-tile" invisible="x_fc_pod_signature">
                                        <div class="fc-tile-preview">
                                            <i class="fa fa-clock-o fc-empty-icon"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-empty-text">Available after delivery is completed</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </page>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ADP Invoice Smart Buttons -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_invoice_buttons" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.invoice.buttons</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">48</field>
        <field name="arch" type="xml">
            <!-- Add ADP and Client invoice smart buttons -->
            <xpath expr="//div[@name='button_box']" position="inside">
                <!-- Client Invoice Button (Blue) - only for REG clients -->
                <button name="action_view_client_invoices" type="object"
                        class="oe_stat_button" icon="fa-file-text-o"
                        invisible="not x_fc_is_adp_sale or x_fc_client_invoice_count == 0">
                    <field name="x_fc_client_invoice_count" widget="statinfo" string="Client Invoice"/>
                </button>
                
                <!-- ADP Invoice Button (Green) -->
                <button name="action_view_adp_invoices" type="object"
                        class="oe_stat_button" icon="fa-institution"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_invoice_count == 0">
                    <field name="x_fc_adp_invoice_count" widget="statinfo" string="ADP Invoice"/>
                </button>
                
                <!-- Vendor Bills Button (for audit trail) -->
                <button name="action_view_vendor_bills" type="object"
                        class="oe_stat_button" icon="fa-truck"
                        invisible="not x_fc_is_adp_sale or x_fc_vendor_bill_count == 0">
                    <field name="x_fc_vendor_bill_count" widget="statinfo" string="Vendor Bills"/>
                </button>

                <!-- MOD Invoice Button (March of Dimes cases only) -->
                <button name="action_view_mod_invoices" type="object"
                        class="oe_stat_button" icon="fa-institution"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_invoice_count == 0">
                    <field name="x_fc_mod_invoice_count" widget="statinfo" string="MOD Invoice"/>
                </button>

                <!-- Client Invoice for MOD cases -->
                <button name="action_view_mod_client_invoices" type="object"
                        class="oe_stat_button" icon="fa-file-text-o"
                        invisible="not x_fc_is_mod_sale or x_fc_mod_client_invoice_count == 0">
                    <field name="x_fc_mod_client_invoice_count" widget="statinfo" string="Client Invoice"/>
                </button>

                <!-- Technician Tasks Button -->
                <button name="action_view_technician_tasks" type="object"
                        class="oe_stat_button" icon="fa-wrench"
                        invisible="x_fc_technician_task_count == 0">
                    <field name="x_fc_technician_task_count" widget="statinfo" string="Tasks"/>
                </button>

                <!-- Page 11 Signing Requests -->
                <button name="action_view_page11_requests" type="object"
                        class="oe_stat_button" icon="fa-pencil-square-o"
                        invisible="page11_sign_request_count == 0">
                    <field name="page11_sign_request_count" widget="statinfo" string="Page 11 Requests"/>
                </button>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: Device Approval Alert Banner -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_approval_banner" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.approval.banner</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">45</field>
        <field name="arch" type="xml">
            <!-- Add prominent alert banner at top of form when approval verification is needed -->
            <xpath expr="//form/sheet" position="before">
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <field name="x_fc_device_verification_complete" invisible="1"/>
                <field name="x_fc_has_unapproved_devices" invisible="1"/>
                <field name="x_fc_total_device_count" invisible="1"/>
                
                <!-- Show when ADP sale has devices that need verification -->
                <div class="alert alert-danger" role="alert" 
                     invisible="not x_fc_is_adp_sale or x_fc_device_verification_complete or x_fc_total_device_count == 0 or state not in ('sale', 'done')">
                    <div class="d-flex align-items-center">
                        <i class="fa fa-exclamation-triangle fa-2x me-3"/>
                        <div class="flex-grow-1">
                            <strong>Device Approval Verification Required</strong>
                            <p class="mb-0">
                                Please verify which devices were approved by ADP before creating invoices.
                            </p>
                        </div>
                        <button name="action_open_device_approval_wizard" type="object"
                                string="Verify Device Approval" class="btn btn-danger ms-3"/>
                    </div>
                </div>
                
                <!-- Show info if some devices were NOT approved (after verification is complete) -->
                <div class="alert alert-warning" role="alert" 
                     invisible="not x_fc_is_adp_sale or not x_fc_device_verification_complete or not x_fc_has_unapproved_devices or state not in ('sale', 'done')">
                    <div class="d-flex align-items-center">
                        <i class="fa fa-exclamation-circle fa-2x me-3"/>
                        <div class="flex-grow-1">
                            <strong>Some Devices Were NOT Approved by ADP</strong>
                            <p class="mb-0">
                                Unapproved devices will be billed to the client at 100% and excluded from the ADP invoice.
                            </p>
                        </div>
                        <button name="action_open_device_approval_wizard" type="object"
                                string="Review Approvals" class="btn btn-warning ms-3"/>
                    </div>
                </div>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: Split Invoice Buttons in Header -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_buttons" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.buttons</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">52</field>
        <field name="arch" type="xml">
            <!-- Add split invoice buttons after the standard Create Invoice button -->
            <xpath expr="//button[@name='action_quotation_send']" position="after">
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <field name="x_fc_has_client_invoice" invisible="1"/>
                <field name="x_fc_has_adp_invoice" invisible="1"/>
                <field name="x_fc_client_type" invisible="1"/>
                
                <!-- REG Client: Create Client Invoice (25%) - show if ADP sale, REG client, no client invoice yet -->
                <button name="action_create_client_invoice" type="object"
                        string="Create Client Invoice (25%)" class="btn-primary"
                        invisible="not x_fc_is_adp_sale or x_fc_client_type != 'REG' or x_fc_has_client_invoice or state != 'sale'"/>
                
                <!-- REG Client: Create ADP Invoice (75%) - show after client invoice is created -->
                <button name="action_create_adp_invoice" type="object"
                        string="Create ADP Invoice (75%)" class="btn-warning"
                        invisible="not x_fc_is_adp_sale or x_fc_client_type != 'REG' or x_fc_has_adp_invoice or not x_fc_has_client_invoice or state != 'sale'"/>
                
                <!-- Non-REG Client: Create ADP Invoice (100%) - show if ADP sale, non-REG, no ADP invoice yet -->
                <button name="action_create_adp_invoice" type="object"
                        string="Create ADP Invoice (100%)" class="btn-warning"
                        invisible="not x_fc_is_adp_sale or x_fc_client_type == 'REG' or x_fc_has_adp_invoice or state != 'sale'"/>
                
                <!-- Hidden helper fields for button visibility -->
                <field name="x_fc_has_unapproved_devices" invisible="1"/>
                <field name="x_fc_device_verification_complete" invisible="1"/>
                <field name="x_fc_submission_verified" invisible="1"/>
                <field name="x_fc_adp_application_status" invisible="1"/>
                <field name="x_fc_early_delivery" invisible="1"/>
                
                <!-- ============================================================ -->
                <!-- NEXT STEP WORKFLOW BUTTONS - Always show the next action    -->
                <!-- These appear FIRST in the header for easy access            -->
                <!-- ============================================================ -->
                
                <!-- Quotation -> Schedule Assessment -->
                <button name="action_schedule_assessment" type="object"
                        string="Schedule Assessment" class="btn-info"
                        icon="fa-calendar"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'quotation'"
                        help="Move to Assessment Scheduled status"/>
                
                <!-- Assessment Scheduled (or Quotation override) -> Complete Assessment -->
                <button name="action_complete_assessment" type="object"
                        string="Complete Assessment" class="btn-info"
                        icon="fa-check-square-o"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('quotation', 'assessment_scheduled')"
                        help="Mark assessment as completed (override available from Quotation stage)"/>
                
                <!-- Request Page 11 Remote Signature (before Application Received) -->
                <button name="action_request_page11_signature" type="object"
                        string="Request Page 11 Signature" class="btn-warning"
                        icon="fa-pencil-square-o"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('assessment_completed', 'waiting_for_application', 'application_received') or x_fc_signed_pages_11_12"
                        help="Send Page 11 to a family member or agent for remote digital signing"/>
                <button name="action_request_page11_signature" type="object"
                        string="Re-sign Page 11" class="btn-secondary"
                        icon="fa-repeat"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('assessment_completed', 'waiting_for_application', 'application_received') or not x_fc_signed_pages_11_12"
                        help="Page 11 already signed. Click to request a new signature."/>

                <!-- Waiting for Application -> Application Received -->
                <button name="action_application_received" type="object"
                        string="Application Received" class="btn-info"
                        icon="fa-file-text-o"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('assessment_completed', 'waiting_for_application')"
                        help="Mark application as received from authorizer"/>
                
                <!-- Application Received -> Ready for Submission -->
                <button name="action_ready_for_submission" type="object"
                        string="Ready for Submission" class="btn-info"
                        icon="fa-check"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'application_received'"
                        help="Mark application as ready to submit to ADP"/>
                
                <!-- Ready for Submission / Needs Correction -> Submit Application -->
                <button name="action_submit_application" type="object"
                        string="Submit Application" class="btn-success"
                        icon="fa-paper-plane"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('ready_submission', 'needs_correction')"
                        help="Verify device types and submit application to ADP"/>
                
                <!-- Submitted / Resubmitted / Accepted -> Mark as Approved -->
                <button name="action_mark_approved" type="object"
                        string="Mark as Approved" class="btn-success"
                        icon="fa-check"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('submitted', 'resubmitted', 'accepted')"
                        help="Verify device approval from ADP and mark application as approved"/>
                
                <!-- Delivery Stage -->
                <button name="action_ready_for_delivery" type="object"
                        string="Ready for Delivery" class="btn-info"
                        icon="fa-truck"
                        invisible="not x_fc_is_adp_sale or (not x_fc_early_delivery and x_fc_adp_application_status not in ('approved', 'approved_deduction')) or (x_fc_early_delivery and x_fc_adp_application_status not in ('submitted', 'accepted', 'approved', 'approved_deduction'))"
                        help="Assign delivery technicians and mark as ready for delivery"/>
                
                <!-- Approved / Ready for Delivery -> Ready to Bill -->
                <button name="action_set_ready_to_bill" type="object"
                        string="Ready to Bill" class="btn-primary"
                        icon="fa-dollar"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('approved', 'approved_deduction', 'ready_delivery')"
                        help="Mark as ready to bill (requires POD, delivery date, device verification)"/>
                
                <!-- Ready to Bill -> Mark as Billed -->
                <button name="action_mark_as_billed" type="object"
                        string="Mark as Billed" class="btn-warning"
                        icon="fa-file-text"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'ready_bill'"
                        help="Mark as billed to ADP (requires posted invoices)"/>
                
                <!-- Billed -> Close Case -->
                <button name="action_close_case" type="object"
                        string="Close Case" class="btn-primary"
                        icon="fa-check-circle"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'billed'"
                        help="Verify audit trail and close the case"/>
                
                <!-- Resume from On Hold -->
                <button name="action_resume_from_hold" type="object"
                        string="Resume" class="btn-success"
                        icon="fa-play"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'on_hold'"
                        help="Resume this application from hold"/>
                
                <!-- ============================================================ -->
                <!-- EXCEPTION BUTTONS - Put On Hold / Withdraw                  -->
                <!-- ============================================================ -->
                
                <button name="%(fusion_claims.action_set_status_on_hold)d" 
                        type="action" string="Put On Hold" class="btn-warning"
                        icon="fa-pause"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('submitted', 'resubmitted', 'needs_correction', 'accepted', 'approved', 'approved_deduction', 'ready_delivery', 'ready_bill')"
                        help="Put this application on hold"/>
                
                <button name="%(fusion_claims.action_set_status_withdrawn)d"
                        type="action" string="Withdraw" class="btn-secondary"
                        icon="fa-undo"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status not in ('submitted', 'resubmitted', 'needs_correction', 'accepted', 'approved', 'approved_deduction', 'ready_bill')"
                        help="Withdraw this application"/>

                <button name="action_resubmit_from_withdrawn" type="object"
                        string="Resubmit Application" class="btn-primary"
                        icon="fa-repeat"
                        invisible="not x_fc_is_adp_sale or x_fc_adp_application_status != 'withdrawn'"
                        confirm="This will return the application to Ready for Submission status. Continue?"
                        help="Return this withdrawn application to Ready for Submission"/>

                <!-- ============================================================ -->
                <!-- REVIEW BUTTONS (color changes based on verified/approved)   -->
                <!-- ============================================================ -->

                <!-- Review Submission: GREEN when verified -->
                <button name="action_open_submission_verification_wizard" type="object"
                        string="Review Submission" class="fc-btn-status-good"
                        icon="fa-check-circle"
                        invisible="not x_fc_is_adp_sale or not x_fc_submission_verified or x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received', 'ready_submission', 'needs_correction', 'approved', 'approved_deduction', 'ready_delivery', 'ready_bill', 'billed', 'case_closed', 'on_hold', 'denied', 'withdrawn', 'cancelled', 'expired')"
                        help="Submission verified - click to review"/>

                <!-- Review Submission: LIGHT RED when not yet verified -->
                <button name="action_open_submission_verification_wizard" type="object"
                        string="Review Submission" class="fc-btn-status-bad"
                        icon="fa-exclamation-triangle"
                        invisible="not x_fc_is_adp_sale or x_fc_submission_verified or x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received', 'ready_submission', 'needs_correction', 'approved', 'approved_deduction', 'ready_delivery', 'ready_bill', 'billed', 'case_closed', 'on_hold', 'denied', 'withdrawn', 'cancelled', 'expired')"
                        help="Submission not yet verified - click to review"/>

                <!-- Review Approval: GREEN when all devices approved -->
                <button name="action_open_device_approval_wizard" type="object"
                        string="Review Approval" class="fc-btn-status-good"
                        icon="fa-check-circle"
                        invisible="not x_fc_is_adp_sale or not x_fc_device_verification_complete or x_fc_has_unapproved_devices or x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received', 'ready_submission', 'submitted', 'resubmitted', 'needs_correction', 'billed', 'case_closed')"
                        help="All devices approved - click to review"/>

                <!-- Review Approval: LIGHT RED when has unapproved devices -->
                <button name="action_open_device_approval_wizard" type="object"
                        string="Review Approval" class="fc-btn-status-bad"
                        icon="fa-exclamation-triangle"
                        invisible="not x_fc_is_adp_sale or not x_fc_device_verification_complete or not x_fc_has_unapproved_devices or x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received', 'ready_submission', 'submitted', 'resubmitted', 'needs_correction', 'billed', 'case_closed')"
                        help="Some devices not yet approved - click to review"/>
                
            </xpath>
            
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ADP Status Bar at Top -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_statusbar" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.statusbar</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">48</field>
        <field name="arch" type="xml">
            <!-- Add ADP Status bar at top of form for ADP sales -->
            <xpath expr="//form/sheet" position="before">
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <field name="x_fc_adp_application_status" widget="statusbar" 
                       invisible="not x_fc_is_adp_sale"
                       statusbar_visible="quotation,waiting_for_application,ready_submission,submitted,approved,ready_bill,billed,case_closed"
                       nolabel="1"/>
                <!-- MOD Status bar -->
                <field name="x_fc_is_mod_sale" invisible="1"/>
                <field name="x_fc_mod_status" widget="statusbar"
                       invisible="not x_fc_is_mod_sale"
                       statusbar_visible="need_to_schedule,assessment_scheduled,assessment_completed,processing_drawings,quote_submitted,funding_approved,contract_received,in_production,project_complete,case_closed"
                       nolabel="1"/>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ADP Case Details Tab -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_adp_tab" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.adp.tab</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">55</field>
        <field name="arch" type="xml">
            <!-- Add ADP Case Details tab in notebook -->
            <xpath expr="//notebook" position="inside">
                <!-- Use computed x_fc_is_adp_sale which checks BOTH Studio and module fields -->
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <page string="ADP Case Details" name="adp_case_details"
                      invisible="not x_fc_is_adp_sale">

                    <!-- Case Locked Warning Banner -->
                    <field name="x_fc_case_locked" invisible="1"/>
                    <div class="alert alert-danger mb-3" role="alert" invisible="not x_fc_case_locked">
                        <div class="d-flex align-items-center">
                            <i class="fa fa-lock fa-2x me-3"/>
                            <div>
                                <strong>This Case is Locked</strong>
                                <p class="mb-0">All ADP fields are read-only. To make changes, unlock the case in the ADP Order Trail tab.</p>
                            </div>
                        </div>
                    </div>

                    <!-- Hidden fields for logic -->
                    <field name="x_fc_adp_status" invisible="1"/>
                    <field name="x_fc_under_5_years" invisible="1"/>
                    <field name="x_fc_funding_warning_message" invisible="1"/>
                    <field name="x_fc_funding_warning_level" invisible="1"/>
                    <field name="x_fc_show_expiry_card" invisible="1"/>
                    <field name="x_fc_approval_expiry_days" invisible="1"/>
                    <field name="x_fc_approval_expired" invisible="1"/>
                    <field name="x_fc_billing_warning" invisible="1"/>
                    <field name="x_fc_assessment_expired" invisible="1"/>
                    
                    <!-- Approval Expiry Card - Shows for Approved/Approved with Deduction/On Hold (with claim) -->
                    <div class="row mb-3" invisible="not x_fc_show_expiry_card">
                        <!-- Expiry Countdown Card -->
                        <div class="col-md-4" invisible="x_fc_approval_expired">
                            <div class="card bg-info text-white">
                                <div class="card-body text-center py-3">
                                    <h5 class="card-title mb-1">
                                        <i class="fa fa-clock-o"/> Approval Valid For
                                    </h5>
                                    <h2 class="mb-0">
                                        <field name="x_fc_approval_expiry_days" readonly="1"/> days
                                    </h2>
                                    <small>Deliver within 6 months of approval</small>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Expired Warning Card -->
                        <div class="col-md-6" invisible="not x_fc_approval_expired">
                            <div class="alert alert-danger mb-0">
                                <h5><i class="fa fa-exclamation-circle"/> Approval Expired!</h5>
                                <p class="mb-0">
                                    This approval has exceeded the 6-month validity period.
                                    The application needs to be <strong>resubmitted</strong>.
                                </p>
                            </div>
                        </div>
                        
                        <!-- Billing Warning Card (1 year) -->
                        <div class="col-md-6" invisible="not x_fc_billing_warning">
                            <div class="alert alert-warning mb-0">
                                <h5><i class="fa fa-phone"/> Verbal Permission Required</h5>
                                <p class="mb-0">
                                    More than 1 year has passed since approval.
                                    <strong>Contact ADP for verbal permission</strong> before billing.
                                </p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Assessment Expired Warning (for on_hold resuming) -->
                    <div class="alert alert-warning mb-3" invisible="not x_fc_assessment_expired or x_fc_adp_application_status != 'on_hold'">
                        <i class="fa fa-exclamation-triangle"/> <strong>Assessment Expired</strong>
                        <p class="mb-0 mt-1">
                            The assessment is more than 3 months old. A new assessment must be completed 
                            before resuming this application.
                        </p>
                    </div>

                    <!-- Core Details -->
                    <group>
                        <!-- Hidden stage computation fields -->
                        <field name="x_fc_stage_after_assessment_initiated" invisible="1"/>
                        <field name="x_fc_stage_after_assessment_completed" invisible="1"/>
                        <field name="x_fc_stage_after_application_received" invisible="1"/>
                        <field name="x_fc_stage_after_ready_submission" invisible="1"/>
                        <field name="x_fc_stage_after_submitted" invisible="1"/>
                        <field name="x_fc_stage_after_approved" invisible="1"/>
                        <field name="x_fc_stage_after_ready_bill" invisible="1"/>
                        <field name="x_fc_stage_after_billed" invisible="1"/>
                        <field name="x_fc_requires_previous_funding" invisible="1"/>
                        
                        <group string="Core Details">
                            <field name="x_fc_adp_application_status" string="Status" required="x_fc_is_adp_sale"
                                   widget="filtered_status_selection" readonly="x_fc_case_locked"/>
                            <field name="x_fc_client_type" string="Client Type" required="x_fc_is_adp_sale"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_reason_for_application" 
                                   invisible="not x_fc_stage_after_ready_submission"
                                   required="x_fc_stage_after_ready_submission"
                                   readonly="x_fc_case_locked"/>
                            
                            <!-- Status Action Buttons (require reason popup) - Hidden when locked -->
                            <div class="mt-2" colspan="2" 
                                 invisible="x_fc_case_locked or x_fc_adp_application_status in ('quotation', 'cancelled', 'case_closed', 'expired')">
                                <button name="%(fusion_claims.action_set_status_on_hold)d" 
                                        type="action" string="Put On Hold" 
                                        class="btn-secondary btn-sm me-1"
                                        icon="fa-pause"
                                        invisible="x_fc_adp_application_status in ('on_hold', 'denied', 'withdrawn', 'cancelled', 'case_closed')"/>
                                <button name="action_resume_from_hold" type="object"
                                        string="Resume"
                                        class="btn-success btn-sm me-1"
                                        icon="fa-play"
                                        invisible="x_fc_adp_application_status != 'on_hold'"/>
                                <button name="action_resubmit_from_withdrawn" type="object"
                                        string="Resubmit Application"
                                        class="btn-primary btn-sm me-1"
                                        icon="fa-repeat"
                                        invisible="x_fc_adp_application_status != 'withdrawn'"
                                        confirm="This will return the application to Ready for Submission status. Continue?"/>
                                <button name="%(fusion_claims.action_set_status_withdrawn)d" 
                                        type="action" string="Withdraw" 
                                        class="btn-secondary btn-sm me-1"
                                        icon="fa-undo"
                                        invisible="x_fc_adp_application_status in ('withdrawn', 'denied', 'cancelled', 'case_closed')"/>
                                <!-- NEW: Mark as Accepted by ADP -->
                                <button name="action_mark_accepted" type="object" 
                                        string="Mark Accepted" 
                                        class="btn-success btn-sm me-1"
                                        icon="fa-check"
                                        invisible="x_fc_adp_application_status not in ('submitted', 'resubmitted')"/>
                                <!-- NEW: Mark as Rejected by ADP -->
                                <button name="%(fusion_claims.action_set_status_rejected)d" 
                                        type="action" string="Mark Rejected" 
                                        class="btn-danger btn-sm me-1"
                                        icon="fa-times"
                                        invisible="x_fc_adp_application_status not in ('submitted', 'resubmitted')"/>
                                <button name="%(fusion_claims.action_set_status_denied)d" 
                                        type="action" string="Denied" 
                                        class="btn-secondary btn-sm me-1"
                                        icon="fa-times-circle"
                                        invisible="x_fc_adp_application_status not in ('accepted',)"/>
                                <button name="%(fusion_claims.action_set_status_needs_correction)d" 
                                        type="action" string="Needs Correction" 
                                        class="btn-warning btn-sm me-1"
                                        icon="fa-exclamation-triangle"
                                        invisible="x_fc_adp_application_status not in ('submitted', 'resubmitted', 'rejected')"/>
                                <button name="%(fusion_claims.action_set_status_cancelled)d" 
                                        type="action" string="Cancel" 
                                        class="btn-danger btn-sm"
                                        icon="fa-ban"
                                        invisible="x_fc_adp_application_status in ('quotation', 'cancelled', 'case_closed', 'expired')"/>
                            </div>
                        </group>
                        <group string="Service Period">
                            <field name="x_fc_has_service" string="Is this a Service?" readonly="x_fc_case_locked"/>
                            <field name="x_fc_service_start_date" 
                                   invisible="not x_fc_has_service" 
                                   required="x_fc_has_service"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_service_end_date" 
                                   invisible="not x_fc_has_service"
                                   required="x_fc_has_service"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- Assessment Dates - Show from Assessment Initiated onwards -->
                    <group string="Assessment Dates" invisible="not x_fc_stage_after_assessment_initiated">
                        <group>
                            <field name="x_fc_assessment_start_date" 
                                   required="x_fc_stage_after_assessment_initiated"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_assessment_end_date" 
                                   invisible="not x_fc_stage_after_assessment_completed"
                                   required="x_fc_stage_after_assessment_completed"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- Application Details - Show after Ready for Submission stage -->
                    <group string="Application Details" invisible="not x_fc_stage_after_ready_submission">
                        <group>
                            <field name="x_fc_client_ref_1" placeholder="e.g., JODO"
                                   required="x_fc_stage_after_ready_submission"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_client_ref_2" placeholder="e.g., 1234"
                                   required="x_fc_stage_after_ready_submission"
                                   readonly="x_fc_case_locked"/>
                        </group>
                        <group>
                            <field name="x_fc_claim_authorization_date"
                                   required="x_fc_stage_after_ready_submission"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- Previous Funding History - Show when reason requires it -->
                    <group string="Previous Funding History" invisible="not x_fc_requires_previous_funding">
                        <group>
                            <field name="x_fc_previous_funding_date" required="x_fc_requires_previous_funding"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_years_since_funding" readonly="1"/>
                        </group>
                        <group>
                            <!-- Red alert for within 1 year -->
                            <div class="alert alert-danger" role="alert"
                                 invisible="x_fc_funding_warning_level != 'danger'">
                                <i class="fa fa-exclamation-circle"/> <strong>Warning:</strong> 
                                <field name="x_fc_funding_warning_message" nolabel="1" readonly="1"/>
                                <br/>
                                <small>Funding within 1 year - high likelihood of deductions or denial.</small>
                            </div>
                            <!-- Yellow alert for within 5 years -->
                            <div class="alert alert-warning" role="alert"
                                 invisible="x_fc_funding_warning_level != 'warning'">
                                <i class="fa fa-exclamation-triangle"/> 
                                <field name="x_fc_funding_warning_message" nolabel="1" readonly="1"/>
                                <br/>
                                <small>Less than 5 years since previous funding - ADP may apply deductions.</small>
                            </div>
                        </group>
                    </group>
                    
                    <!-- Submission Details - Show after Submitted stage -->
                    <group string="Submission Details" invisible="not x_fc_stage_after_submitted">
                        <group>
                            <field name="x_fc_claim_submission_date"
                                   required="x_fc_adp_application_status in ('submitted', 'resubmitted')"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- Approval Details - Show after Approved stage -->
                    <group string="Approval Details" invisible="not x_fc_stage_after_approved">
                        <group>
                            <field name="x_fc_claim_number" placeholder="10 digits only"
                                   required="x_fc_stage_after_approved"
                                   readonly="x_fc_case_locked"/>
                        </group>
                        <group>
                            <field name="x_fc_claim_approval_date"
                                   required="x_fc_stage_after_approved"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- Delivery Details - Show after application submitted -->
                    <group string="Delivery Details" invisible="x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received', 'ready_submission')">
                        <group>
                            <field name="x_fc_early_delivery" widget="boolean_toggle"
                                   invisible="x_fc_adp_application_status in ('approved', 'approved_deduction', 'ready_delivery', 'ready_bill', 'billed', 'case_closed')"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_scheduled_delivery_datetime"
                                   invisible="x_fc_adp_application_status not in ('ready_delivery', 'ready_bill', 'billed', 'case_closed')"
                                   readonly="x_fc_case_locked"/>
                        </group>
                        <group>
                            <field name="x_fc_delivery_technician_ids" widget="many2many_tags"
                                   options="{'color_field': 'color'}"
                                   invisible="x_fc_adp_application_status not in ('ready_delivery', 'ready_bill', 'billed', 'case_closed')"
                                   readonly="x_fc_case_locked"/>
                            <field name="x_fc_ready_for_delivery_date" 
                                   invisible="x_fc_adp_application_status not in ('ready_delivery', 'ready_bill', 'billed', 'case_closed')"
                                   readonly="1"/>
                        </group>
                    </group>
                    
                    <!-- Billing Details - Show after Ready to Bill stage -->
                    <group string="Billing Details" invisible="not x_fc_stage_after_ready_bill">
                        <group>
                            <field name="x_fc_adp_delivery_date"
                                   required="x_fc_stage_after_ready_bill"
                                   readonly="x_fc_case_locked"/>
                        </group>
                        <group>
                            <field name="x_fc_billing_date"
                                   invisible="not x_fc_stage_after_billed"
                                   required="x_fc_stage_after_billed"
                                   readonly="x_fc_case_locked"/>
                        </group>
                    </group>
                    
                    <!-- ========================================= -->
                    <!-- INVOICE MAPPING SECTION -->
                    <!-- ========================================= -->
                    <group string="Invoice Mapping" name="invoice_mapping">
                        <group>
                            <field name="x_fc_adp_invoice_id" 
                                   readonly="x_fc_case_locked"
                                   options="{'no_create': True}"/>
                        </group>
                        <group>
                            <field name="x_fc_client_invoice_id" 
                                   readonly="x_fc_case_locked"
                                   options="{'no_create': True}"/>
                        </group>
                    </group>
                    
                </page>
                
                <!-- ADP Documents Tab -->
                <page string="ADP Documents" name="adp_documents"
                      invisible="not x_fc_is_adp_sale or x_fc_adp_application_status in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application')">

                    <!-- Case Locked Warning Banner -->
                    <div class="alert alert-danger mb-3" role="alert" invisible="not x_fc_case_locked">
                        <div class="d-flex align-items-center">
                            <i class="fa fa-lock fa-2x me-3"/>
                            <div>
                                <strong>This Case is Locked</strong>
                                <p class="mb-0">Documents cannot be modified. To make changes, unlock the case in the ADP Order Trail tab.</p>
                            </div>
                        </div>
                    </div>

                    <!-- Dynamic info alerts based on current stage -->
                    <div class="alert alert-info" role="alert"
                         invisible="x_fc_adp_application_status != 'application_received'">
                        <i class="fa fa-upload"/> <strong>Action Required:</strong>
                        Upload the Original ADP Application and signed Pages 11 &amp; 12 to proceed.
                    </div>


                    <div class="alert alert-info" role="alert"
                         invisible="x_fc_adp_application_status not in ('approved', 'approved_deduction')">
                        <i class="fa fa-upload"/> <strong>Action Required:</strong>
                        Upload Proof of Delivery before moving to "Ready to Bill" status.
                    </div>

                    <!-- ========================================================= -->
                    <!-- Next Step Banner - Shows what action to take -->
                    <!-- ========================================================= -->
                    <!-- Ready for Submission: Show Submit Application prompt -->
                    <div class="alert alert-info mb-3" role="alert"
                         invisible="x_fc_adp_application_status != 'ready_submission'">
                        <div class="d-flex align-items-center">
                            <i class="fa fa-paper-plane fa-2x me-3"/>
                            <div class="flex-grow-1">
                                <strong>Ready to Submit</strong>
                                <p class="mb-0">
                                    Documents are ready. Use the <strong>"Submit Application"</strong> button in the header
                                    to verify device types and submit to ADP.
                                </p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Submitted: Waiting for approval -->
                    <div class="alert alert-info mb-3" role="alert"
                         invisible="x_fc_adp_application_status not in ('submitted', 'resubmitted')">
                        <div class="d-flex align-items-center">
                            <i class="fa fa-clock-o fa-2x me-3"/>
                            <div class="flex-grow-1">
                                <strong>Awaiting ADP Response</strong>
                                <p class="mb-0">
                                    Application submitted. When the approval letter arrives, use the 
                                    <strong>"Mark as Approved"</strong> button in the header.
                                </p>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Approved: Show Ready to Bill prompt -->
                    <div class="alert alert-success mb-3" role="alert"
                         invisible="x_fc_adp_application_status not in ('approved', 'approved_deduction')">
                        <div class="d-flex align-items-center">
                            <i class="fa fa-check-circle fa-2x me-3"/>
                            <div class="flex-grow-1">
                                <strong>Application Approved</strong>
                                <p class="mb-0">
                                    Upload Proof of Delivery and set delivery date, then use the 
                                    <strong>"Ready to Bill"</strong> button in the header.
                                </p>
                            </div>
                        </div>
                    </div>

                    <!-- ========================================================= -->
                    <!-- Documents Grid - 3 Column Layout -->
                    <!-- ========================================================= -->
                    <div class="row">
                        <!-- Column 1: Application Documents -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-file-text-o"/> Application Documents
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Original ADP Application Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_original_application" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_original_application"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_original_application"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Original ADP Application</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_original_application">
                                                <field name="x_fc_original_application_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_original_application">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_original_application" filename="x_fc_original_application_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   required="x_fc_is_adp_sale and x_fc_adp_application_status not in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received')"
                                                   readonly="x_fc_case_locked"/>
                                        </div>
                                    </div>

                                    <!-- Signed Pages 11 & 12 Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_signed_pages" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_signed_pages_11_12"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_signed_pages_11_12"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Signed Pages 11 &amp; 12</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_signed_pages_11_12">
                                                <field name="x_fc_signed_pages_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_signed_pages_11_12">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_signed_pages_11_12" filename="x_fc_signed_pages_filename" 
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   required="x_fc_is_adp_sale and x_fc_adp_application_status not in ('quotation', 'assessment_scheduled', 'assessment_completed', 'waiting_for_application', 'application_received')"
                                                   readonly="x_fc_case_locked"/>
                                            <button name="action_request_page11_signature" type="object"
                                                    class="btn btn-sm btn-outline-primary mt-1"
                                                    string="Request Signature"
                                                    title="Send Page 11 to a family member or agent for remote signing"
                                                    invisible="x_fc_signed_pages_11_12 or not x_fc_is_adp_sale"/>
                                        </div>
                                    </div>
                                    <field name="page11_sign_status" invisible="1"/>
                                </div>
                            </div>
                        </div>

                        <!-- Column 2: Submission Documents -->
                        <div class="col-md-4"
                             invisible="x_fc_adp_application_status == 'application_received'">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-paper-plane-o"/> Submission Documents
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Final Submitted Application Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_final_application" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_final_submitted_application"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_final_submitted_application"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Final Application</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_final_submitted_application">
                                                <field name="x_fc_final_application_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_final_submitted_application">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_final_submitted_application" filename="x_fc_final_application_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   readonly="x_fc_case_locked"/>
                                        </div>
                                    </div>

                                    <!-- XML File Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_xml_file" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_xml_file"
                                                    title="Click to download">
                                                <i class="fa fa-file-code-o fc-xml-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_xml_file"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">XML File</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_xml_file">
                                                <field name="x_fc_xml_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_xml_file">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_xml_file" filename="x_fc_xml_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   readonly="x_fc_case_locked"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Column 3: Approval Documents -->
                        <div class="col-md-4"
                             invisible="x_fc_adp_application_status not in ('approved', 'approved_deduction', 'ready_bill', 'billed', 'payment_received', 'case_closed')">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-check-circle"/> Approval Documents
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Approval Letter Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_approval_letter" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_approval_letter"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_approval_letter"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">ADP Approval Letter</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_approval_letter">
                                                <field name="x_fc_approval_letter_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_approval_letter">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_approval_letter" filename="x_fc_approval_letter_filename"
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   readonly="x_fc_case_locked"/>
                                        </div>
                                    </div>
                                    
                                    <!-- Approval Screenshots Gallery -->
                                    <field name="x_fc_approval_photo_count" invisible="1"/>
                                    <div class="fc-gallery-section">
                                        <div class="fc-gallery-header d-flex justify-content-between align-items-center mb-2">
                                            <span class="fc-tile-label">Approval Screenshots</span>
                                            <div class="d-flex align-items-center gap-2">
                                                <button name="action_view_approval_photos" type="object"
                                                        class="btn btn-sm btn-outline-success"
                                                        invisible="x_fc_approval_photo_count == 0"
                                                        title="View in Gallery">
                                                    <i class="fa fa-eye me-1"/> View
                                                </button>
                                                <span class="badge bg-secondary" invisible="x_fc_approval_photo_count == 0">
                                                    <field name="x_fc_approval_photo_count" nolabel="1"/> files
                                                </span>
                                            </div>
                                        </div>
                                        <div class="fc-gallery-content">
                                            <field name="x_fc_approval_photo_ids" 
                                                   widget="many2many_binary" 
                                                   string="Add Screenshots"
                                                   nolabel="1"
                                                   readonly="x_fc_case_locked"
                                                   class="fc-gallery-upload"/>
                                        </div>
                                        <div class="fc-gallery-empty text-muted text-center py-3" 
                                             invisible="x_fc_approval_photo_count > 0">
                                            <i class="fa fa-image fa-2x mb-2 d-block opacity-50"/>
                                            <small>No screenshots uploaded</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- ========================================================= -->
                    <!-- Row 2: Delivery Documents (separate row for clarity) -->
                    <!-- ========================================================= -->
                    <div class="row mt-3"
                         invisible="x_fc_adp_application_status not in ('approved', 'approved_deduction', 'ready_bill', 'billed', 'payment_received', 'case_closed')">
                        <!-- Column: Delivery Documents -->
                        <div class="col-md-4">
                            <div class="fc-doc-section h-100">
                                <div class="fc-doc-section-header">
                                    <i class="fa fa-truck"/> Delivery Documents
                                </div>
                                <div class="fc-document-tiles">
                                    <!-- Proof of Delivery Tile -->
                                    <div class="fc-document-tile">
                                        <div class="fc-tile-preview">
                                            <button name="action_open_proof_of_delivery" type="object"
                                                    class="btn btn-link p-0 w-100 h-100 d-flex align-items-center justify-content-center border-0"
                                                    invisible="not x_fc_proof_of_delivery"
                                                    title="Click to preview">
                                                <i class="fa fa-file-pdf-o fc-pdf-icon"/>
                                            </button>
                                            <i class="fa fa-plus-circle fc-empty-icon" invisible="x_fc_proof_of_delivery"/>
                                        </div>
                                        <div class="fc-tile-info">
                                            <div class="fc-tile-label">Proof of Delivery</div>
                                            <div class="fc-tile-filename" invisible="not x_fc_proof_of_delivery">
                                                <field name="x_fc_proof_of_delivery_filename" nolabel="1" class="text-truncate"/>
                                            </div>
                                            <div class="fc-tile-empty-text" invisible="x_fc_proof_of_delivery">No file uploaded</div>
                                        </div>
                                        <div class="fc-tile-actions">
                                            <field name="x_fc_proof_of_delivery" filename="x_fc_proof_of_delivery_filename" 
                                                   widget="binary" nolabel="1" class="fc-tile-upload-field"
                                                   required="x_fc_is_adp_sale and x_fc_adp_application_status in ('ready_bill', 'billed', 'payment_received', 'case_closed')"
                                                   readonly="x_fc_case_locked"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </page>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ADP Summary Tab -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">60</field>
        <field name="arch" type="xml">
            <!-- Add ADP Summary tab in notebook -->
            <xpath expr="//notebook" position="inside">
                <!-- Use computed x_fc_is_adp_sale which checks BOTH Studio and module fields -->
                <page string="ADP Summary" name="adp_summary"
                      invisible="not x_fc_is_adp_sale">
                    
                    <!-- DEVICE APPROVAL STATUS - AT TOP for easy visibility -->
                    <field name="x_fc_has_unapproved_devices" invisible="1"/>
                    <field name="x_fc_device_verification_complete" invisible="1"/>
                    <field name="x_fc_approved_device_count" invisible="1"/>
                    <field name="x_fc_total_device_count" invisible="1"/>
                    
                    <!-- Show when verification NOT yet complete -->
                    <div class="alert alert-info mb-3" role="alert" invisible="x_fc_device_verification_complete or x_fc_total_device_count == 0">
                        <strong><i class="fa fa-info-circle"/> Device Verification Required</strong>
                        <p class="mb-2">
                            Click the button below to verify which devices were approved by ADP.
                            <br/><strong>This must be completed before creating invoices.</strong>
                        </p>
                        <button name="action_open_device_approval_wizard" type="object"
                                string="Verify Device Approval" class="btn-info"
                                icon="fa-check-square-o"/>
                    </div>
                    
                    <!-- Show when verification complete but some items NOT approved -->
                    <div class="alert alert-warning mb-3" role="alert" invisible="not x_fc_device_verification_complete or not x_fc_has_unapproved_devices">
                        <strong><i class="fa fa-exclamation-triangle"/> Some Devices NOT Approved by ADP</strong>
                        <p class="mb-2">
                            <field name="x_fc_approved_device_count" readonly="1" class="oe_inline"/> of 
                            <field name="x_fc_total_device_count" readonly="1" class="oe_inline"/> devices approved.
                            <br/>Unapproved devices will be billed to the client at 100% and excluded from the ADP invoice.
                        </p>
                        <button name="action_open_device_approval_wizard" type="object"
                                string="Review Approvals" class="btn-warning"
                                icon="fa-check-square-o"/>
                    </div>
                    
                    <!-- Show success when all verified and approved -->
                    <div class="alert alert-success mb-3" role="alert" invisible="not x_fc_device_verification_complete or x_fc_has_unapproved_devices or x_fc_total_device_count == 0">
                        <strong><i class="fa fa-check-circle"/> All Devices Approved</strong>
                        <p class="mb-0">
                            All <field name="x_fc_total_device_count" readonly="1" class="oe_inline"/> devices have been verified as approved by ADP.
                        </p>
                    </div>
                    
                    <!-- SPLIT INVOICING -->
                    <div class="alert alert-success mb-3" role="alert">
                        <strong>Split Invoicing:</strong>
                        <p class="mb-2">Create separate invoices for client and ADP portions.</p>
                        
                        <!-- Hidden fields for invoice status tracking -->
                        <field name="x_fc_has_client_invoice" invisible="1"/>
                        <field name="x_fc_has_adp_invoice" invisible="1"/>
                        <field name="x_fc_client_type" invisible="1"/>
                        
                        <!-- Invoice status indicators -->
                        <div class="mb-2">
                            <span class="badge bg-success me-2" invisible="not x_fc_has_client_invoice">
                                ✓ Client Invoice Created
                            </span>
                            <span class="badge bg-secondary me-2" invisible="x_fc_has_client_invoice or x_fc_client_type != 'REG'">
                                ○ Client Invoice Pending
                            </span>
                            <span class="badge bg-success me-2" invisible="not x_fc_has_adp_invoice">
                                ✓ ADP Invoice Created
                            </span>
                            <span class="badge bg-secondary" invisible="x_fc_has_adp_invoice">
                                ○ ADP Invoice Pending
                            </span>
                        </div>
                        
                        <div>
                            <!-- REG Client: Show 25% button if not created -->
                            <button name="action_create_client_invoice" type="object" 
                                    string="Create Client Invoice (25%)" class="btn-primary me-2"
                                    invisible="x_fc_client_type != 'REG' or x_fc_has_client_invoice"
                                    confirm="Create a 25% client invoice for this order?"/>
                            
                            <!-- REG Client: Show 75% button if not created -->
                            <button name="action_create_adp_invoice" type="object" 
                                    string="Create ADP Invoice (75%)" class="btn-warning me-2"
                                    invisible="x_fc_client_type != 'REG' or x_fc_has_adp_invoice"
                                    confirm="Create a 75% ADP invoice for this order?"/>
                            
                            <!-- Non-REG Client: Show 100% button if not created -->
                            <button name="action_create_adp_invoice" type="object" 
                                    string="Create ADP Invoice (100%)" class="btn-warning"
                                    invisible="x_fc_client_type == 'REG' or x_fc_has_adp_invoice"
                                    confirm="Create a 100% ADP invoice for this order?"/>
                            
                            <!-- All done message -->
                            <span class="text-success fw-bold" 
                                  invisible="not x_fc_has_adp_invoice or (x_fc_client_type == 'REG' and not x_fc_has_client_invoice)">
                                ✓ All invoices created!
                            </span>
                        </div>
                    </div>
                    
                    <!-- DEDUCTION ALERT - Only show when there are deductions -->
                    <field name="x_fc_has_deductions" invisible="1"/>
                    <field name="x_fc_total_deduction_amount" invisible="1"/>
                    
                    <div class="alert alert-warning mb-3" role="alert" invisible="not x_fc_has_deductions">
                        <strong><i class="fa fa-minus-circle"/> Deductions Applied</strong>
                        <p class="mb-0">
                            ADP deductions have been applied to this order. 
                            Total deduction impact: <strong><field name="x_fc_total_deduction_amount" widget="monetary" class="oe_inline"/></strong>
                            - This amount will be the client's responsibility.
                        </p>
                    </div>
                    
                    <group>
                        <group string="ADP Portion Breakdown">
                            <field name="x_fc_adp_portion_total" string="Total ADP Portion" widget="monetary"/>
                            <field name="x_fc_client_portion_total" string="Total Client Portion" widget="monetary"/>
                        </group>
                        <group string="Order Information">
                            <!-- Hidden - using Studio fields instead -->
                            <field name="x_fc_sale_type" invisible="1"/>
                        </group>
                    </group>
                    
                    <!-- Product lines list - with conditional deduction columns -->
                    <field name="x_fc_product_lines" mode="list" readonly="1" nolabel="1" class="w-100"
                           context="{'show_deductions': x_fc_has_deductions}">
                        <list string="Line Details" create="0" delete="0" limit="50" 
                              decoration-success="x_fc_adp_approved" 
                              decoration-danger="not x_fc_adp_approved and x_fc_adp_device_type"
                              decoration-warning="x_fc_deduction_type and x_fc_deduction_type != 'none'">
                            <field name="x_fc_adp_approved" string="✓" widget="boolean" width="40px"
                                   help="Device approved by ADP"/>
                            <field name="name" string="Description" class="text-wrap"/>
                            <field name="x_fc_adp_device_type" string="Device Type" optional="show" width="150px"/>
                            <field name="x_fc_adp_build_type" string="Build" optional="show" width="100px"/>
                            <field name="x_fc_serial_number" string="S/N" optional="show" width="90px"/>
                            <field name="product_uom_qty" string="Qty" width="60px"/>
                            <field name="price_unit" string="Unit $" width="100px"/>
                            <field name="x_fc_deduction_type" string="Ded." width="70px"
                                   column_invisible="not parent.x_fc_has_deductions"/>
                            <field name="x_fc_deduction_value" string="Ded.$" width="80px"
                                   column_invisible="not parent.x_fc_has_deductions"/>
                            <field name="x_fc_adp_portion" string="ADP $" width="100px"/>
                            <field name="x_fc_client_portion" string="Client $" width="100px"/>
                            <field name="price_subtotal" string="Total" width="100px"/>
                            <field name="x_fc_device_placement" string="Plcmt" optional="hide" width="70px"/>
                        </list>
                    </field>
                    <div class="alert alert-info" role="alert">
                        <strong>Calculation Rules:</strong>
                        <ul>
                            <li><strong>REG Client:</strong> ADP Portion = 75%, Client Portion = 25%</li>
                            <li><strong>ODS/OWP/ACS/LTC/SEN/CCA:</strong> ADP Portion = 100%, Client Portion = 0%</li>
                            <li><strong>PCT Deduction:</strong> ADP pays X% of their normal portion</li>
                            <li><strong>AMT Deduction:</strong> Fixed $ amount deducted from ADP portion</li>
                        </ul>
                        <div class="mt-3">
                            <button name="action_recalculate_adp_portions" type="object" 
                                    string="Recalculate Portions" class="btn-secondary me-2"
                                    help="Manually recalculate ADP and Client portions"/>
                        </div>
                    </div>
                </page>
                
                <!-- ============================================================= -->
                <!-- ADP ORDER TRAIL TAB - Audit Trail & Case Lock -->
                <!-- ============================================================= -->
                <page string="ADP Order Trail" name="adp_order_trail"
                      invisible="not x_fc_is_adp_sale">
                    
                    <!-- Hidden fields for trail computation -->
                    <field name="x_fc_trail_has_assessment_dates" invisible="1"/>
                    <field name="x_fc_trail_has_authorization" invisible="1"/>
                    <field name="x_fc_trail_has_original_app" invisible="1"/>
                    <field name="x_fc_trail_has_signed_pages" invisible="1"/>
                    <field name="x_fc_trail_has_final_app" invisible="1"/>
                    <field name="x_fc_trail_has_xml" invisible="1"/>
                    <field name="x_fc_trail_has_approval_letter" invisible="1"/>
                    <field name="x_fc_trail_has_pod" invisible="1"/>
                    <field name="x_fc_trail_has_vendor_bills" invisible="1"/>
                    <field name="x_fc_trail_invoices_posted" invisible="1"/>
                    
                    <!-- Case Lock Control -->
                    <div class="row mb-4">
                        <div class="col-12">
                            <div class="alert alert-danger d-flex align-items-center justify-content-between mb-0">
                                <div class="d-flex align-items-center">
                                    <i class="fa fa-lock fa-2x me-3"/>
                                    <div>
                                        <strong>Case Lock</strong>
                                        <p class="mb-0 small">When locked, all ADP fields become read-only</p>
                                    </div>
                                </div>
                                <field name="x_fc_case_locked" widget="boolean_toggle"/>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Order Trail Checklist -->
                    <div class="row">
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-list-alt"/> Workflow Checklist</h5>
                                </div>
                                <div class="card-body p-0">
                                    <table class="table table-striped mb-0">
                                        <tbody>
                                            <tr>
                                                <td style="width: 40px; text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_assessment_dates"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_assessment_dates"/>
                                                </td>
                                                <td>Assessment Dates Set</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_authorization"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_authorization"/>
                                                </td>
                                                <td>Authorization Date Set</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_original_app"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_original_app"/>
                                                </td>
                                                <td>Original Application Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_signed_pages"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_signed_pages"/>
                                                </td>
                                                <td>Signed Pages 11 &amp; 12 Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_submission_verified"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_submission_verified"/>
                                                </td>
                                                <td>Submission Verified</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-file-text-o"/> Documents Checklist</h5>
                                </div>
                                <div class="card-body p-0">
                                    <table class="table table-striped mb-0">
                                        <tbody>
                                            <tr>
                                                <td style="width: 40px; text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_final_app"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_final_app"/>
                                                </td>
                                                <td>Final Application Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_xml"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_xml"/>
                                                </td>
                                                <td>XML File Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_approval_letter"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_approval_letter"/>
                                                </td>
                                                <td>Approval Letter Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_pod"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_pod"/>
                                                </td>
                                                <td>Proof of Delivery Uploaded</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_device_verification_complete"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_device_verification_complete"/>
                                                </td>
                                                <td>Device Verification Complete</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Billing & Audit Trail -->
                    <div class="row">
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-dollar"/> Billing Status</h5>
                                </div>
                                <div class="card-body p-0">
                                    <table class="table table-striped mb-0">
                                        <tbody>
                                            <tr>
                                                <td style="width: 40px; text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_invoices_posted"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_invoices_posted"/>
                                                </td>
                                                <td>Invoices Created &amp; Posted</td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center;">
                                                    <i class="fa fa-check-circle text-success" invisible="not x_fc_trail_has_vendor_bills"/>
                                                    <i class="fa fa-circle-o text-muted" invisible="x_fc_trail_has_vendor_bills"/>
                                                </td>
                                                <td>Vendor Bills Linked</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h5 class="mb-0"><i class="fa fa-truck"/> Vendor Bills (Audit Trail)</h5>
                                </div>
                                <div class="card-body">
                                    <field name="x_fc_vendor_bill_ids" 
                                           widget="many2many_tags"
                                           options="{'no_create': True, 'no_quick_create': True}"
                                           domain="[('move_type', '=', 'in_invoice'), ('state', '=', 'posted')]"
                                           placeholder="Search and link vendor bills..."
                                           readonly="x_fc_case_locked"/>
                                    <div class="text-muted small mt-2">
                                        <i class="fa fa-info-circle"/> Link vendor invoices/bills to this order for audit purposes.
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </page>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER LINE: Add ADP Portion and Client Portion columns -->
    <!-- These columns are only visible when x_fc_is_adp_sale is True -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_order_lines" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.order.lines</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">75</field>
        <field name="arch" type="xml">
            <!-- Hide Description column so Product is the only flex column -->
            <xpath expr="//field[@name='order_line']/list/field[@name='name']" position="attributes">
                <attribute name="optional">hide</attribute>
            </xpath>

            <!-- Serial Number and Build Type: after description -->
            <xpath expr="//field[@name='order_line']/list/field[@name='name']" position="after">
                <field name="x_fc_serial_number" string="S/N" optional="show"/>
                <field name="x_fc_adp_build_type" string="Build" optional="hide"
                       column_invisible="not parent.x_fc_is_adp_sale"/>
            </xpath>

            <!-- Shorten Qty label -->
            <xpath expr="//field[@name='order_line']/list/field[@name='product_uom_qty']" position="attributes">
                <attribute name="string">Qty</attribute>
            </xpath>

            <!-- ADP/Client Portion: only visible for ADP and ADP/ODSP -->
            <xpath expr="//field[@name='order_line']/list/field[@name='price_subtotal'][1]" position="after">
                <field name="x_fc_adp_portion" string="ADP $" widget="monetary"
                       column_invisible="not parent.x_fc_is_adp_sale"/>
                <field name="x_fc_client_portion" string="Client $" widget="monetary"
                       column_invisible="not parent.x_fc_is_adp_sale"/>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER FORM: ADP Totals in Summary Footer -->
    <!-- ===================================================================== -->
    <record id="view_order_form_fusion_claims_totals" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.central.totals</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">70</field>
        <field name="arch" type="xml">
            <!-- Add ADP totals after the tax_totals field (the totals widget) -->
            <xpath expr="//field[@name='tax_totals']" position="after">
                <field name="x_fc_is_adp_sale" invisible="1"/>
                <div id="fc_adp_totals" invisible="not x_fc_is_adp_sale" class="oe_right mt-2">
                    <div class="d-flex justify-content-end">
                        <span class="me-2 text-muted">Total ADP Portion:</span>
                        <field name="x_fc_adp_portion_total" widget="monetary"/>
                    </div>
                    <div class="d-flex justify-content-end">
                        <span class="me-2 text-muted">Total Client Portion:</span>
                        <field name="x_fc_client_portion_total" widget="monetary"/>
                    </div>
                </div>
            </xpath>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- SALE ORDER SEARCH: Filters -->
    <!-- ===================================================================== -->
    <record id="view_sales_order_filter_fusion_claims" model="ir.ui.view">
        <field name="name">sale.order.search.fusion.central</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_sales_order_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//search" position="inside">
                <separator/>
                <!-- ADP Status Filters (using x_fc_adp_application_status) -->
                <filter string="ADP Sales" name="adp_sales" 
                        domain="[('x_fc_is_adp_sale', '=', True)]"/>
                <filter string="Quotation Stage" name="quotation_stage" 
                        domain="[('x_fc_adp_application_status', '=', 'quotation')]"/>
                <filter string="Assessment Scheduled" name="assessment_scheduled" 
                        domain="[('x_fc_adp_application_status', '=', 'assessment_scheduled')]"/>
                <filter string="Assessment Completed" name="assessment_completed" 
                        domain="[('x_fc_adp_application_status', '=', 'assessment_completed')]"/>
                <filter string="Waiting for Application" name="waiting_for_application" 
                        domain="[('x_fc_adp_application_status', '=', 'waiting_for_application')]"/>
                <filter string="Application Received" name="application_received" 
                        domain="[('x_fc_adp_application_status', '=', 'application_received')]"/>
                <filter string="Ready for Submission" name="ready_submission" 
                        domain="[('x_fc_adp_application_status', '=', 'ready_submission')]"/>
                <filter string="Application Submitted" name="submitted" 
                        domain="[('x_fc_adp_application_status', 'in', ['submitted', 'resubmitted'])]"/>
                <filter string="Needs Correction" name="needs_correction" 
                        domain="[('x_fc_adp_application_status', '=', 'needs_correction')]"/>
                <filter string="Application Approved" name="approved" 
                        domain="[('x_fc_adp_application_status', 'in', ['approved', 'approved_deduction'])]"/>
                <filter string="Ready for Delivery" name="ready_delivery" 
                        domain="[('x_fc_adp_application_status', '=', 'ready_delivery')]"/>
                <filter string="Ready for Billing" name="ready_billing" 
                        domain="[('x_fc_adp_application_status', '=', 'ready_bill')]"/>
                <filter string="Billed to ADP" name="billed" 
                        domain="[('x_fc_adp_application_status', '=', 'billed')]"/>
                <filter string="Case Closed" name="closed" 
                        domain="[('x_fc_adp_application_status', '=', 'case_closed')]"/>
                <separator/>
                <!-- Special Status Filters -->
                <filter string="On Hold" name="on_hold" 
                        domain="[('x_fc_adp_application_status', '=', 'on_hold')]"/>
                <filter string="Withdrawn" name="withdrawn" 
                        domain="[('x_fc_adp_application_status', '=', 'withdrawn')]"/>
                <filter string="Denied" name="denied" 
                        domain="[('x_fc_adp_application_status', '=', 'denied')]"/>
                <filter string="Cancelled" name="cancelled" 
                        domain="[('x_fc_adp_application_status', '=', 'cancelled')]"/>
                <filter string="Expired" name="expired" 
                        domain="[('x_fc_adp_application_status', '=', 'expired')]"/>
                <separator/>
                <!-- Technician Filters -->
                <filter string="My Deliveries" name="my_deliveries" 
                        domain="[('x_fc_delivery_technician_ids', 'in', uid)]"
                        help="Orders assigned to me for delivery"/>
                <filter string="Early Delivery" name="early_delivery" 
                        domain="[('x_fc_early_delivery', '=', True)]"/>
                <separator/>
                <!-- Client Type Filters (using x_fc_client_type - module field) -->
                <filter string="REG Clients" name="reg_clients" 
                        domain="[('x_fc_client_type', '=', 'REG')]"/>
                <filter string="ODS/OWP/ACS" name="full_funding" 
                        domain="[('x_fc_client_type', 'in', ['ODS', 'OWP', 'ACS'])]"/>
                <separator/>
                <!-- Group By -->
                <filter string="ADP Application Status" name="group_adp_status" 
                        context="{'group_by': 'x_fc_adp_application_status'}"/>
                <filter string="Client Type" name="group_client_type" 
                        context="{'group_by': 'x_fc_client_type'}"/>
                <filter string="Authorizer" name="group_authorizer" 
                        context="{'group_by': 'x_fc_authorizer_id'}"/>
            </xpath>
        </field>
    </record>

</odoo>
