<?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>
    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Tree View -->
    <!-- ===================================================================== -->
    <record id="view_adp_export_record_list" model="ir.ui.view">
        <field name="name">fusion_claims.adp.export.record.list</field>
        <field name="model">fusion_claims.adp.export.record</field>
        <field name="arch" type="xml">
            <list string="ADP Claim Submission Files"
                  default_order="year desc, month asc, posting_period_date desc, export_date desc">
                <field name="name"/>
                <field name="export_date"/>
                <field name="posting_period_label" string="Posting Period"/>
                <field name="payment_date" string="Payment Date"/>
                <field name="vendor_code"/>
                <field name="line_count" string="Lines"/>
                <field name="invoice_count" string="Invoices"/>
                <field name="user_id" string="Exported By" widget="many2one_avatar_user"/>
                <field name="year" column_invisible="True"/>
                <field name="month" column_invisible="True"/>
                <field name="month_number" column_invisible="True"/>
            </list>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Kanban View -->
    <!-- ===================================================================== -->
    <record id="view_adp_export_record_kanban" model="ir.ui.view">
        <field name="name">fusion_claims.adp.export.record.kanban</field>
        <field name="model">fusion_claims.adp.export.record</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile" default_order="year desc, month asc, posting_period_date desc, export_date desc">
                <templates>
                    <t t-name="card">
                        <div class="d-flex justify-content-between mb-1">
                            <strong><field name="name"/></strong>
                            <field name="vendor_code" class="text-muted"/>
                        </div>
                        <div class="text-muted small mb-1">
                            <field name="posting_period_label"/>
                        </div>
                        <div class="d-flex justify-content-between align-items-center">
                            <div class="small">
                                <span class="me-3"><i class="fa fa-list-ol me-1"/>
                                    <field name="line_count"/> lines</span>
                                <span><i class="fa fa-file-text-o me-1"/>
                                    <field name="invoice_count"/> invoices</span>
                            </div>
                            <field name="user_id" widget="many2one_avatar_user"/>
                        </div>
                        <div class="text-muted small mt-1">
                            <i class="fa fa-calendar me-1"/><field name="export_date"/>
                        </div>
                        <field name="year" invisible="1"/>
                        <field name="month" invisible="1"/>
                        <field name="month_number" invisible="1"/>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Form View -->
    <!-- ===================================================================== -->
    <record id="view_adp_export_record_form" model="ir.ui.view">
        <field name="name">fusion_claims.adp.export.record.form</field>
        <field name="model">fusion_claims.adp.export.record</field>
        <field name="arch" type="xml">
            <form string="ADP Claim Submission File">
                <header>
                    <button name="action_download" string="Download File"
                            type="object" class="btn-primary" icon="fa-download"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_view_invoices" type="object"
                                class="oe_stat_button" icon="fa-pencil-square-o"
                                invisible="invoice_count == 0">
                            <field name="invoice_count" widget="statinfo"
                                   string="Invoices"/>
                        </button>
                    </div>
                    <div class="oe_title">
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group string="Export Details">
                            <field name="export_date" readonly="1"/>
                            <field name="posting_period_date" readonly="1"/>
                            <field name="posting_period_label" readonly="1"/>
                            <field name="payment_date" readonly="1"/>
                            <field name="vendor_code" readonly="1"/>
                            <field name="line_count" readonly="1"/>
                        </group>
                        <group string="File">
                            <field name="file_data" filename="filename" readonly="1"/>
                            <field name="filename" invisible="1"/>
                            <field name="user_id" readonly="1"/>
                            <field name="company_id" readonly="1" groups="base.group_multi_company"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="File Preview" name="preview"
                              invisible="not file_preview">
                            <field name="file_preview" readonly="1" nolabel="1"
                                   widget="text"/>
                        </page>
                        <page string="Exported Invoices" name="invoices">
                            <field name="invoice_ids" readonly="1" nolabel="1">
                                <list string="Invoices" create="0" delete="0">
                                    <field name="name" string="Invoice"/>
                                    <field name="partner_id" string="Customer"
                                           widget="many2one"/>
                                    <field name="invoice_date"/>
                                    <field name="currency_id" column_invisible="True"/>
                                    <field name="amount_total" string="Total" sum="Grand Total"/>
                                    <field name="state" widget="badge"
                                           decoration-success="state == 'posted'"
                                           decoration-info="state == 'draft'"/>
                                </list>
                            </field>
                        </page>
                        <page string="Notes" name="notes" invisible="not notes">
                            <field name="notes" readonly="1"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Search View -->
    <!-- ===================================================================== -->
    <record id="view_adp_export_record_search" model="ir.ui.view">
        <field name="name">fusion_claims.adp.export.record.search</field>
        <field name="model">fusion_claims.adp.export.record</field>
        <field name="arch" type="xml">
            <search string="ADP Claim Submission Files">
                <field name="name"/>
                <field name="vendor_code"/>
                <field name="user_id"/>
                <separator/>
                <filter string="Year" name="group_year"
                        context="{'group_by': 'year'}"/>
                <filter string="Month" name="group_month"
                        context="{'group_by': 'month'}"/>
                <filter string="Posting Period" name="group_posting"
                        context="{'group_by': 'posting_period_label'}"/>
                <filter string="Exported By" name="group_user"
                        context="{'group_by': 'user_id'}"/>
            </search>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Action -->
    <!-- ===================================================================== -->
    <record id="action_adp_export_records" model="ir.actions.act_window">
        <field name="name">Claim Submission Files</field>
        <field name="res_model">fusion_claims.adp.export.record</field>
        <field name="view_mode">list,kanban,form</field>
        <field name="search_view_id" ref="view_adp_export_record_search"/>
        <field name="context">{'search_default_group_year': 1, 'search_default_group_month': 1, 'search_default_group_posting': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No claim submission files yet
            </p>
            <p>
                ADP claim submission files will appear here after you export invoices using the
                <strong>Export ADP</strong> button on ADP portion invoices.
            </p>
        </field>
    </record>

    <!-- ===================================================================== -->
    <!-- ADP EXPORT RECORD: Server Action for Bulk ZIP Download -->
    <!-- ===================================================================== -->
    <record id="action_adp_export_download_zip" model="ir.actions.server">
        <field name="name">Download as ZIP</field>
        <field name="model_id" ref="model_fusion_claims_adp_export_record"/>
        <field name="binding_model_id" ref="model_fusion_claims_adp_export_record"/>
        <field name="binding_view_types">list</field>
        <field name="state">code</field>
        <field name="code">action = records.action_download_zip()</field>
    </record>

</odoo>
