<?xml version="1.0"?>
<odoo>

    <record id="account_payment_view_form" model="ir.ui.view">
            <field name="model">account.payment</field>
            <field name="inherit_id" ref="account.view_account_payment_form" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='communication']" position="after">
                    <field name="folio_id"/>
                    <field name="save_amount" invisible="1"/>
                    <field name="save_journal_id" invisible="1"/>
                    <field name="save_date" invisible="1"/>
                </xpath>
            </field>
    </record>

    <record id="account_payment_view_form_folio" model="ir.ui.view">
        <field name="name">account.payment.folio.form</field>
        <field name="model">account.payment</field>
        <field name="priority">20</field>
        <field name="arch" type="xml">
            <form string="Register Payment" version="7">
                <header>
                    <button name="action_draft" class="oe_highlight" states="cancelled" string="Set To Draft" type="object"/>
                    <button string="Validate" name="post" type="object" class="btn-primary"
                        attrs="{'invisible': [('state','!=','draft')]}"/>
                    <button string="Modify" name="modify" type="object" class="oe_edit_only btn-primary"
                        attrs="{'invisible': [('state','=','draft')]}"/>
                    <button string="Return" name="return_payment_folio" type="object" class="oe_edit_only btn-primary"
                        attrs="{'invisible': [('state','=','draft')]}"/>
                    <button string="Delete" name="delete" type="object" class="oe_read_only btn-primary"
                        attrs="{'invisible': [('state','=','draft')]}"/>
                    <button string="Cancel" class="oe_read_only btn-default" special="cancel"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,posted,reconciled,cancelled"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button class="oe_stat_button" name="button_journal_entries"
                                string="Journal Items" type="object"
                                groups="account.group_account_user"
                                attrs="{'invisible':[('move_line_ids','=',[])]}" icon="fa-bars"/>
                        <field name="move_line_ids" invisible="1"/>
                        <button class="oe_stat_button" name="button_invoices"
                                string="Invoices" type="object"
                                attrs="{'invisible':[('has_invoices','=',False)]}" icon="fa-bars"/>
                        <button class="oe_stat_button" name="open_payment_matching_screen"
                                string="Payment Matching" type="object"
                                attrs="{'invisible':[('move_reconciled','=',True)]}" icon="fa-university"/>
                        <field name="has_invoices" invisible="1"/>
                        <field name="move_reconciled" invisible="1"/>
                    </div>
                    <field name="id" invisible="1"/>
                    <div class="oe_title" attrs="{'invisible': [('state', '=', 'draft')]}">
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="payment_type" invisible="1"/>
                            <field name="save_amount" invisible="1"/>
                            <field name="save_date" invisible="1"/>
                            <field name="save_journal_id" invisible="1"/>
                            <field name="partner_type" widget="selection" invisible="1"/>
                            <field name="partner_id" attrs="{'required': [('state', '=', 'draft'), ('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))]}" context="{'default_is_company': True, 'default_supplier': payment_type == 'outbound', 'default_customer': payment_type == 'inbound'}"/>
                            <label for="amount"/>
                            <div name="amount_div" class="o_row">
                                <field name="amount" />
                                <field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                            </div>
                            <field name="journal_id" widget="selection" />
                            <field name="destination_journal_id" widget="selection" attrs="{'required': [('payment_type', '=', 'transfer')], 'invisible': [('payment_type', '!=', 'transfer')], 'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="hide_payment_method" invisible="1"/>
                            <field name="payment_method_id" string=" " widget="radio" attrs="{'invisible': [('hide_payment_method', '=', True)]}"/>
                            <field name="payment_method_code" invisible="1"/>
                        </group>
                        <group>
                            <field name="payment_date" />
                            <field name="communication" attrs="{'invisible': [('state', '!=', 'draft'), ('communication', '=', False)]}"/>
                            <field name="folio_id" readonly="1" force_save="1"/>
                        </group>
                    </group>
                </sheet>
                <footer>

                </footer>
                <div class="oe_chatter">
                  <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                  <field name="message_ids" widget="mail_thread"/>
              </div>
            </form>
        </field>
    </record>

    <record id="account_payment_view_tree_folio" model="ir.ui.view">
        <field name="name">account.payment.folio.tree</field>
        <field name="model">account.payment</field>
        <field name="priority">20</field>
        <field name="arch" type="xml">
            <tree decoration-info="state == 'draft'" decoration-muted="state in ['reconciled', 'cancelled']" edit="false">
                <field name="payment_date" />
                <field name="name" />
                <field name="journal_id" />
                <field name="payment_method_id" />
                <field name="partner_id" string="Customer" />
                <field name="amount" sum="Amount" />
                <field name="state" />
                <field name="company_id" groups="base.group_multi_company" />
                <field name="currency_id" invisible="1" />
                <field name="partner_type" invisible="1" />
                <button type="object" class="oe_stat_button"
                  icon="fa fa-2x fa-pencil"
                  name="modify_payment" />
            </tree>
        </field>
    </record>

</odoo>
