<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_xeno_orr_reimbursement_list" model="ir.ui.view">
        <field name="name">xeno.orr.reimbursement.list</field>
        <field name="model">xeno.orr.reimbursement</field>
        <field name="arch" type="xml">
            <list string="Reimbursements" decoration-success="state in ('management_approve', 'complete')"
                  decoration-danger="state in ('supervisor_reject', 'management_reject')"
                  decoration-muted="not is_current">
                <field name="request_id"/>
                <field name="employee_id"/>
                <field name="attempt_number"/>
                <field name="is_current" string="Current"/>
                <field name="reimbursement_type"/>
                <field name="total_amount" sum="Total"/>
                <field name="state" widget="badge"/>
                <field name="category"/>
            </list>
        </field>
    </record>

    <record id="view_xeno_orr_reimbursement_form" model="ir.ui.view">
        <field name="name">xeno.orr.reimbursement.form</field>
        <field name="model">xeno.orr.reimbursement</field>
        <field name="arch" type="xml">
            <form string="Reimbursement">
                <header>
                    <button name="action_supervisor_approve" type="object" string="Approve"
                            class="btn-primary" invisible="state != 'submitted' or not can_supervisor_decide"/>
                    <button name="%(xeno_orr.action_xeno_orr_reimbursement_reject_wizard)d" type="action"
                            string="Reject" invisible="state != 'submitted' or not can_supervisor_decide"
                            context="{'default_reimbursement_id': id}"/>
                    <button name="action_management_approve" type="object" string="Approve"
                            class="btn-primary" invisible="state != 'supervisor_approve' or not can_management_decide"/>
                    <button name="%(xeno_orr.action_xeno_orr_management_reject_wizard)d" type="action"
                            string="Reject" invisible="state != 'supervisor_approve' or not can_management_decide"
                            context="{'default_reimbursement_id': id}"/>
                    <button name="action_finance_complete" type="object" string="Complete"
                            class="btn-primary" invisible="state != 'management_approve' or not can_finance_decide"/>
                    <button name="%(xeno_orr.action_xeno_orr_resend_wizard)d" type="action"
                            string="Resend Reimburse" invisible="state != 'supervisor_reject' or not is_current"
                            context="{'default_request_id': request_id, 'default_resend_of_id': id}"/>
                    <button name="%(xeno_orr.action_xeno_orr_ask_back_wizard)d" type="action"
                            string="Ask Back" invisible="state not in ('management_approve', 'complete') or not can_management_decide"
                            context="{'default_reimbursement_id': id}"/>
                    <field name="state" widget="statusbar"
                           statusbar_visible="submitted,supervisor_approve,management_approve,complete"/>
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="request_id" readonly="1"/>
                            <field name="employee_id" readonly="1"/>
                            <field name="attempt_number" readonly="1"/>
                            <field name="is_current" readonly="1"/>
                            <field name="reimbursement_type" readonly="1"/>
                        </group>
                        <group>
                            <field name="fuel_distance_km" readonly="1" invisible="reimbursement_type != 'fuel'"/>
                            <field name="fuel_rate" readonly="1" invisible="reimbursement_type != 'fuel'"/>
                            <field name="fuel_amount" readonly="1" invisible="reimbursement_type != 'fuel'"/>
                            <field name="total_amount" readonly="1"/>
                            <field name="category" groups="xeno_orr.group_orr_finance,hr.group_hr_manager"/>
                        </group>
                    </group>
                    <field name="line_ids" readonly="1" invisible="reimbursement_type != 'other'">
                        <list>
                            <field name="place"/>
                            <field name="description"/>
                            <field name="amount" sum="Total"/>
                            <field name="proof_image" widget="image" optional="show"/>
                        </list>
                    </field>
                    <div invisible="not reject_reason" class="alert alert-danger" role="alert">
                        <field name="reject_reason" readonly="1" nolabel="1"/>
                    </div>
                    <field name="ask_back_ids" invisible="not ask_back_ids">
                        <list>
                            <field name="amount" sum="Total"/>
                            <field name="reason"/>
                            <field name="requested_by"/>
                            <field name="request_date"/>
                        </list>
                    </field>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <record id="view_xeno_orr_reimbursement_search" model="ir.ui.view">
        <field name="name">xeno.orr.reimbursement.search</field>
        <field name="model">xeno.orr.reimbursement</field>
        <field name="arch" type="xml">
            <search string="Reimbursements">
                <field name="request_id"/>
                <field name="employee_id"/>
                <filter name="filter_current" string="Current Attempt" domain="[('is_current', '=', True)]"/>
                <filter name="filter_submitted" string="Submitted" domain="[('state', '=', 'submitted')]"/>
                <filter name="filter_supervisor_approve" string="Supervisor Approved" domain="[('state', '=', 'supervisor_approve')]"/>
                <filter name="filter_management_approve" string="Management Approved" domain="[('state', '=', 'management_approve')]"/>
                <filter name="filter_complete" string="Complete" domain="[('state', '=', 'complete')]"/>
                <group>
                    <filter name="groupby_employee" string="Employee" context="{'group_by': 'employee_id'}"/>
                    <filter name="groupby_state" string="Status" context="{'group_by': 'state'}"/>
                    <filter name="groupby_current" string="Current / Past" context="{'group_by': 'is_current'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="action_xeno_orr_reimbursement" model="ir.actions.act_window">
        <field name="name">Reimbursements</field>
        <field name="res_model">xeno.orr.reimbursement</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_xeno_orr_reimbursement_search"/>
        <field name="context">{'search_default_filter_current': 1}</field>
    </record>

    <record id="action_xeno_orr_reimbursement_supervisor" model="ir.actions.act_window">
        <field name="name">Reimbursements – Supervisor</field>
        <field name="res_model">xeno.orr.reimbursement</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_xeno_orr_reimbursement_search"/>
        <field name="domain">[('state', '=', 'submitted')]</field>
        <field name="context">{'search_default_filter_submitted': 1}</field>
    </record>

    <record id="action_xeno_orr_reimbursement_management" model="ir.actions.act_window">
        <field name="name">Reimbursements – Management</field>
        <field name="res_model">xeno.orr.reimbursement</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_xeno_orr_reimbursement_search"/>
        <field name="domain">[('state', '=', 'supervisor_approve')]</field>
        <field name="context">{'search_default_filter_supervisor_approve': 1}</field>
    </record>

    <record id="action_xeno_orr_reimbursement_finance" model="ir.actions.act_window">
        <field name="name">Reimbursements – Finance</field>
        <field name="res_model">xeno.orr.reimbursement</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_xeno_orr_reimbursement_search"/>
        <field name="domain">[('state', 'in', ('management_approve', 'complete'))]</field>
        <field name="context">{'search_default_filter_management_approve': 1}</field>
    </record>

    <record id="action_xeno_orr_report" model="ir.actions.act_window">
        <field name="name">Report</field>
        <field name="res_model">xeno.orr.reimbursement</field>
        <field name="view_mode">list,pivot</field>
        <field name="search_view_id" ref="view_xeno_orr_reimbursement_search"/>
    </record>
</odoo>
