<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!-- ============================================================ -->
    <!-- Fusion Batch Payment - List View                             -->
    <!-- ============================================================ -->
    <record id="fusion_batch_payment_view_list" model="ir.ui.view">
        <field name="name">fusion.batch.payment.list</field>
        <field name="model">fusion.batch.payment</field>
        <field name="arch" type="xml">
            <list string="Batch Payments"
                  decoration-info="state == 'draft'"
                  decoration-success="state == 'reconciled'"
                  decoration-warning="state == 'sent'">
                <field name="name"/>
                <field name="date"/>
                <field name="journal_id"/>
                <field name="payment_method_id"/>
                <field name="payment_count" string="# Payments"/>
                <field name="amount_total" sum="Total"/>
                <field name="currency_id" column_invisible="True"/>
                <field name="state" widget="badge"
                       decoration-info="state == 'draft'"
                       decoration-success="state == 'reconciled'"
                       decoration-warning="state == 'sent'"/>
            </list>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Fusion Batch Payment - Form View                             -->
    <!-- ============================================================ -->
    <record id="fusion_batch_payment_view_form" model="ir.ui.view">
        <field name="name">fusion.batch.payment.form</field>
        <field name="model">fusion.batch.payment</field>
        <field name="arch" type="xml">
            <form string="Batch Payment">
                <header>
                    <button name="validate_batch"
                            string="Validate"
                            type="object"
                            class="btn-primary"
                            invisible="state != 'draft'"/>
                    <button name="action_draft"
                            string="Reset to Draft"
                            type="object"
                            invisible="state != 'sent'"/>
                    <button name="action_reconcile"
                            string="Mark Reconciled"
                            type="object"
                            class="btn-primary"
                            invisible="state != 'sent'"/>
                    <button name="print_batch"
                            string="Print"
                            type="object"
                            invisible="state == 'draft'"/>
                    <field name="state" widget="statusbar"
                           statusbar_visible="draft,sent,reconciled"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="name" readonly="True"/>
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field name="journal_id"
                                   readonly="state != 'draft'"/>
                            <field name="payment_method_id"
                                   readonly="state != 'draft'"/>
                            <field name="date"
                                   readonly="state != 'draft'"/>
                        </group>
                        <group>
                            <field name="amount_total"/>
                            <field name="payment_count"/>
                            <field name="currency_id" invisible="True"/>
                            <field name="company_id" invisible="True"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Payments" name="payments">
                            <field name="payment_ids"
                                   readonly="state != 'draft'"
                                   widget="many2many"
                                   domain="[('journal_id', '=', journal_id), ('state', '=', 'posted')]">
                                <list>
                                    <field name="name"/>
                                    <field name="partner_id"/>
                                    <field name="date"/>
                                    <field name="amount"/>
                                    <field name="currency_id"
                                           column_invisible="True"/>
                                    <field name="state" widget="badge"/>
                                </list>
                            </field>
                        </page>
                    </notebook>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Fusion Batch Payment - Kanban View                           -->
    <!-- ============================================================ -->
    <record id="fusion_batch_payment_view_kanban" model="ir.ui.view">
        <field name="name">fusion.batch.payment.kanban</field>
        <field name="model">fusion.batch.payment</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile" sample="1">
                <templates>
                    <t t-name="card">
                        <div class="d-flex justify-content-between mb-2">
                            <strong>
                                <field name="name"/>
                            </strong>
                            <field name="state" widget="label_selection"
                                   options="{'classes': {
                                       'draft': 'info',
                                       'sent': 'warning',
                                       'reconciled': 'success'
                                   }}"/>
                        </div>
                        <div class="d-flex justify-content-between text-muted">
                            <span><field name="date"/></span>
                            <span>
                                <field name="payment_count"/> payments
                            </span>
                        </div>
                        <div class="d-flex justify-content-between mt-2">
                            <field name="journal_id"/>
                            <strong>
                                <field name="amount_total"
                                       widget="monetary"/>
                            </strong>
                        </div>
                        <field name="currency_id" invisible="True"/>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Fusion Batch Payment - Search View                           -->
    <!-- ============================================================ -->
    <record id="fusion_batch_payment_view_search" model="ir.ui.view">
        <field name="name">fusion.batch.payment.search</field>
        <field name="model">fusion.batch.payment</field>
        <field name="arch" type="xml">
            <search string="Search Batch Payments">
                <field name="name"/>
                <field name="journal_id"/>
                <field name="payment_method_id"/>
                <separator/>
                <filter string="Draft" name="draft"
                        domain="[('state', '=', 'draft')]"/>
                <filter string="Sent" name="sent"
                        domain="[('state', '=', 'sent')]"/>
                <filter string="Reconciled" name="reconciled"
                        domain="[('state', '=', 'reconciled')]"/>
                <separator/>
                <group>
                    <filter string="Journal" name="group_journal"
                            context="{'group_by': 'journal_id'}"/>
                    <filter string="Status" name="group_state"
                            context="{'group_by': 'state'}"/>
                    <filter string="Date" name="group_date"
                            context="{'group_by': 'date'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Action                                                       -->
    <!-- ============================================================ -->
    <record id="fusion_batch_payment_action" model="ir.actions.act_window">
        <field name="name">Batch Payments</field>
        <field name="res_model">fusion.batch.payment</field>
        <field name="view_mode">list,kanban,form</field>
        <field name="search_view_id" ref="fusion_batch_payment_view_search"/>
        <field name="context">{'search_default_draft': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first batch payment
            </p>
            <p>
                Group multiple payments together for bulk processing
                and streamlined bank submission.
            </p>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Menu Item: Accounting > Vendors > Batch Payments             -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_batch_payment"
              name="Batch Payments"
              parent="account.menu_finance_payables"
              action="fusion_batch_payment_action"
              sequence="30"
              groups="account.group_account_user"/>

</odoo>
