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

    <record id="payment_transaction_form_inherit_poynt" model="ir.ui.view">
        <field name="name">payment.transaction.form.inherit.poynt</field>
        <field name="model">payment.transaction</field>
        <field name="inherit_id" ref="payment.payment_transaction_form"/>
        <field name="arch" type="xml">

            <!-- Voided banner at top of form -->
            <xpath expr="//header" position="before">
                <div class="alert alert-warning text-center mb-0"
                     role="alert"
                     invisible="not poynt_voided">
                    <strong>VOIDED</strong> — This transaction was voided on Poynt
                    on <field name="poynt_void_date" widget="datetime" readonly="1" class="d-inline"/>.
                    The payment has been reversed before settlement.
                </div>
            </xpath>

            <!-- Void button in header -->
            <xpath expr="//header/button[@name='action_void']" position="after">
                <button string="Void Transaction"
                        name="action_poynt_void"
                        type="object"
                        class="btn-secondary"
                        invisible="state != 'done' or provider_code != 'poynt'"
                        confirm="Are you sure you want to void this transaction? This reverses the payment before settlement and cannot be undone. Only works same-day before closeout (6 PM)."/>
            </xpath>

            <!-- Add Poynt fields and linked records after provider_reference -->
            <xpath expr="//field[@name='provider_reference']" position="after">
                <field name="poynt_voided" invisible="1"/>
                <field name="poynt_void_date" invisible="not poynt_voided"/>
                <field name="poynt_order_id" invisible="provider_code != 'poynt'" readonly="1"/>
                <field name="poynt_transaction_id" invisible="provider_code != 'poynt'" readonly="1"/>
                <field name="sale_order_ids" widget="many2many_tags" readonly="1"
                       string="Sale Orders"/>
                <field name="invoice_ids" widget="many2many_tags" readonly="1"
                       string="Invoices"/>
            </xpath>

        </field>
    </record>

</odoo>
