<?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"/>
                    <field name="default_pos_receivable_account_name" invisible="1" />
                    <div class="d-flex justify-content-between">
                        <div class="oe_title">
                            <label for="name"/>
                            <h1><field name="name" placeholder="e.g. Cash" class="oe_inline"/></h1>
                        </div>
                        <field name="image" class="oe_avatar" widget='image'/>
                    </div>
                    <group name="Payment methods">
                        <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'" required="type == 'bank'" placeholder="Selection of outstanding account is required" />
                            <field name="receivable_account_id" groups="account.group_account_readonly" invisible="split_transactions" widget="many2one" options="{'placeholder_field': 'default_pos_receivable_account_name'}"/>
                            <field name="company_id" readonly="1" groups="base.group_multi_company" />
                            <field name="config_ids" widget="many2many_tags" placeholder="No Point of Sale" />
                        </group>
                        <div>
                            <group>
                                <field name="hide_use_payment_terminal" invisible="1"/>
                                <field name="hide_qr_code_method" invisible="1"/>
                                <field name="payment_method_type" />
                                <field name="use_payment_terminal" string="Integrate with" invisible="hide_use_payment_terminal"/>
                                <field name="qr_code_method" invisible="hide_qr_code_method" required="payment_method_type == 'qr_code'"/>
                            </group>
                            <widget name="pos_payment_provider_cards" invisible="use_payment_terminal or payment_method_type != 'terminal'" />
                        </div>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="pos_payment_method_view_tree" model="ir.ui.view">
        <field name="name">pos.payment.method.list</field>
        <field name="model">pos.payment.method</field>
        <field name="arch" type="xml">
            <list 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"/>
            </list>
        </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>
                    <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">list,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">list,form,kanban</field>
    </record>
</odoo>
