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

    <record id="hr_expense_change_form" model="ir.ui.view">
        <field name="name">Expense Change</field>
        <field name="model">hr.expense.change</field>
        <field name="arch" type="xml">
            <form string="Expense Change">
                <group>
                    <group name="group_left">
                        <field name="expense_id" invisible="1"/>
                        <field name="expense_company_id" invisible="1"/>
                        <field name="date"/>
                    </group>
                    <group name="group_right"/>
                </group>
                <footer>
                    <button name="affect_change" string="Change" type="object" class="btn-primary"/>
                    <button string="Cancel" class="btn-default" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="action_view_hr_expense_change" model="ir.actions.act_window">
        <field name="name">Expense Change Wizard</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">hr.expense.change</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

    <!-- Add Button to Existing Forms -->
    <record id="hr_expense_form_view_inherit" model="ir.ui.view">
        <field name="name">hr.expense.form.inherit</field>
        <field name="model">hr.expense</field>
        <field name="inherit_id" ref="hr_expense.hr_expense_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='state']" position="before">
                <button name="%(action_view_hr_expense_change)d" string="Change"
                        type="action" class="btn-secondary"
                        attrs="{'invisible': [('state', 'in', ('draft', 'refused'))]}"
                        context="{'default_expense_id': active_id}"
                        groups="account.group_account_manager" />
            </xpath>
       </field>
    </record>

    <record id="view_hr_expense_sheet_form_inherit" model="ir.ui.view">
        <field name="name">hr.expense.sheet.form.inherit</field>
        <field name="model">hr.expense.sheet</field>
        <field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='expense_line_ids']/tree" position="inside">
                <field name="id" invisible="1"/>
                <button name="%(action_view_hr_expense_change)d" string="Change" icon="fa-exchange"
                        type="action"
                        attrs="{'invisible': [('state', 'in', ('draft', 'refused'))]}"
                        context="{'default_expense_id': id}"
                        groups="account.group_account_manager" />
            </xpath>
       </field>
    </record>

</odoo>