<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="pos_payment_method_view_form" model="ir.ui.view">
        <field name="name">pos.payment.method.form</field>
        <field name="model">pos.payment.method</field>
        <field name="arch" type="xml">
            <form string="Payment Methods">
                <sheet>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <field name="active" invisible="1"/>
                    <field name="type" invisible="1" />
                    <div class="oe_title">
                        <label for="name"/>
                        <h1><field name="name" placeholder="e.g. Cash" class="oe_inline"/></h1>
                        <field name="image" class="oe_avatar" widget='image'/>
                    </div>
                    <group name="Payment methods">
                        <field name="hide_use_payment_terminal" invisible="1"/>
                        <group>
                            <field name="split_transactions"/>
                            <field name="journal_id" required="not split_transactions" placeholder="Leave empty to use the receivable account of customer" />
                            <field name="outstanding_account_id" groups="account.group_account_readonly" invisible="type != 'bank'" placeholder="Leave empty to use the default account from the company setting" />
                            <field name="receivable_account_id" groups="account.group_account_readonly" invisible="split_transactions" placeholder="Leave empty to use the default account from the company setting" />
                            <field name="company_id" readonly="1" groups="base.group_multi_company" />
                        </group>
                        <group invisible="not hide_use_payment_terminal or type != 'bank'">
                            <div colspan="2">
                                <h2>Tips:</h2>
                                <p>
                                    Go to <a href="#" name="%(action_pos_configuration)d" type="action" class="btn-link o_form_uri" role="button">Configurations > Settings</a>
                                    <strong> > Payment Terminals</strong>
                                    in order to install a Payment Terminal and make a fully integrated payment method.
                                </p>
                            </div>
                        </group>
                        <group invisible="hide_use_payment_terminal">
                            <field name="use_payment_terminal" />
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="pos_payment_method_view_tree" model="ir.ui.view">
        <field name="name">pos.payment.method.tree</field>
        <field name="model">pos.payment.method</field>
        <field name="arch" type="xml">
            <tree string="Payment Methods" create="1" delete="1">
                <field name="type" column_invisible="True"/>
                <field name="sequence" widget="handle"/>
                <field name="name" />
                <field name="split_transactions" optional="hide" />
                <field name="journal_id" required="not split_transactions" />
                <field name="outstanding_account_id" groups="account.group_account_readonly" optional="hide" invisible="type != 'bank'" />
                <field name="receivable_account_id" groups="account.group_account_readonly" optional="hide" invisible="split_transactions" />
                <field name="company_id" groups="base.group_multi_company" />
                <field name="config_ids" widget="many2many_tags"/>
            </tree>
        </field>
    </record>

    <record id="pos_payment_method_view_search" model="ir.ui.view">
        <field name="name">pos.payment.search.view</field>
        <field name="model">pos.payment.method</field>
        <field name="arch" type="xml">
            <search string="Payment Methods">
                <field name="name"/>
                <field name="receivable_account_id" groups="account.group_account_readonly" />
                <group expand="1" string="Group By">
                    <filter name="group_by_receivable_account" string="Account" domain="[]"  context="{'group_by':'receivable_account_id'}"/>
                    <filter name="group_by_pos_config" string="Point of Sale" domain="[]" context="{'group_by':'config_ids'}"/>
                    <filter name="group_by_method_name" string="Method Name" domain="[]" context="{'group_by':'name'}"/>
                    <filter name="group_by_journal_id" string="Journal" domain="[]" context="{'group_by':'journal_id'}"/>
                </group>
                <filter string="Archived" name="active" domain="[('active', '=', False)]"/>
            </search>
        </field>
    </record>

    <record id="action_pos_payment_method_form" model="ir.actions.act_window">
        <field name="name">Payment Methods</field>
        <field name="res_model">pos.payment.method</field>
        <field name="view_mode">tree,kanban,form</field>
        <field name="view_id" eval="False"/>
        <field name="domain">[]</field>
        <field name="context">{'search_default_group_by_account': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Add a new payment method
            </p>
            <p>
                Installing chart of accounts from the General Settings of
                Invocing/Accounting app will create Bank and Cash payment
                methods automatically.
            </p>
        </field>
    </record>

    <menuitem id="menu_pos_payment_method" parent="menu_point_config_product" action="action_pos_payment_method_form" sequence="3" groups="group_pos_manager,group_pos_user"/>

    <record id="action_payment_methods_tree" model="ir.actions.act_window">
        <field name="context">{}</field>
        <field name="name">Payments Methods</field>
        <field name="res_model">pos.payment.method</field>
        <field name="view_id" ref="pos_payment_method_view_tree"/>
        <field name="view_mode">tree,form,kanban</field>
    </record>
</odoo>
