<odoo>
    <data>
        <record id="payment_orders_form" model="ir.ui.view">
            <field name="name">payment.orders.form</field>
            <field name="model">payment.orders</field>
            <field name="arch" type="xml">
                <form string="Payment Orders" create="false">
                    <header>
                        <button name="action_manager_approval" type="object" states="draft"
                                groups="odex_benefit.group_benefit_payment_accountant_accept"
                                string="Manager approval" class="oe_highlight"/>
                        <button name="action_refuse" type="object"
                                states="draft"
                                groups="odex_benefit.group_benefit_payment_accountant_accept"
                                string="Refuse" class="btn btn-danger"/>

                        <button name="action_head_approval" type="object"
                                states="waiting_head"
                                groups="odex25_account_payment_fix.group_depart_manager"
                                string="Approve" class="oe_highlight"/>
                        <button name="action_reset_to_draft" type="object"
                                states="waiting_head"
                                groups="odex25_account_payment_fix.group_depart_manager"
                                string="Reset" class="btn btn-warning"/>

                        <button name="action_finance_approval" type="object"
                                states="waiting_finance"
                                groups="odex25_account_payment_fix.group_accounting_manager"
                                string="Approve" class="oe_highlight"/>
                        <button name="action_reset_to_draft" type="object"
                                states="waiting_finance"
                                groups="odex25_account_payment_fix.group_accounting_manager"
                                string="Reset" class="btn btn-warning"/>

                        <button name="action_gm_approval" type="object"
                                states="waiting_gm"
                                groups="odex25_account_payment_fix.group_general_manager"
                                string="Approve" class="oe_highlight"/>
                        <button name="action_reset_to_draft" type="object"
                                states="waiting_gm"
                                groups="odex25_account_payment_fix.group_general_manager"
                                string="Reset" class="btn btn-warning"/>

                        <button name="create_entry" type="object"
                                groups="odex_benefit.group_benefit_payment_accountant_accept"
                                string="Create Entry" class="oe_highlight"
                                attrs="{'invisible': ['|',('state','!=','waiting_deposit'),('move_id', '!=',False)]}"
                        />
                        <button name="action_deposit" type="object"
                                groups="odex_benefit.group_benefit_payment_accountant_accept"
                                string="Deposit Completed" class="oe_highlight"
                                attrs="{'invisible': ['|',('state','!=','waiting_deposit'),('move_id', '=',False)]}"
                        />

                        <field name="state" widget="statusbar"/>
                    </header>
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button icon="fa-usd" name="action_open_related_move_records"
                                    type="object" attrs="{'invisible': [('move_count','=',0)]}">
                                <field name="move_count" string="Moves" widget="statinfo"/>
                            </button>
                            <button name="action_view_all_required_attachments"
                                    type="object" class="oe_stat_button"
                                    icon="fa-paperclip"
                                    attrs="{'invisible': ['|',('attachment_line_count', '=', 0),('type','!=','services')]}">
                                <field name="attachment_line_count" string="Service Required Attachments"
                                       widget="statinfo"/>
                            </button>
                        </div>
                        <group>
                            <div class="oe_title">
                                <h1>
                                    <field name="name" readonly="1"/>
                                </h1>
                            </div>
                            <group>
                                <field name="payment_order_date" readonly="1"/>
                                <field name="type" readonly="1"/>
                                <field name="accountant_id" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                                <field name="journal_id"
                                       attrs="{'readonly': [('state', 'in', ['done'])]}"/>
                            </group>
                            <group>
                                <field name="payment_order_description" readonly="1"/>
                                <field name="ref_num" readonly="1"/>
                                <field name="is_seasonal" invisible="1"/>
                                <field name="move_id" invisible="1"/>
                                <field name="company_id" groups="base.group_multi_company"/>
                                <field name="currency_id" groups="base.group_multi_currency" invisible="1"/>
                                <field name="total_amount" widget="monetary"
                                       options="{'currency_field': 'currency_id'}"/>
                            </group>
                        </group>
                        <notebook>
                            <page string="Services Requests"
                                  attrs="{'invisible':[('type','not in',['seasonal_services','services'])]}">
                                <field name="service_requests_ids" readonly="1">
                                    <tree>
                                        <field name="family_code"/>
                                        <field name="family_id"/>
                                        <field name="benefit_type" optional="hidden"/>
                                        <field name="member_id" optional="hidden"/>
                                        <field name="branch_custom_id" optional="hidden"/>
                                        <field name="researcher_id" optional="hidden"/>
                                        <field name="family_category"/>
                                        <field name="benefit_member_count"/>
                                        <field name="service_benefit_count"/>
                                        <field name="requested_service_amount"/>
                                        <field name="state" widget="badge"
                                               decoration-success="state in ['gm_assistant']"
                                               decoration-muted="state == 'draft'"
                                               decoration-danger="state in ['refused']"
                                               decoration-info="state in ['first_approve','waiting_approve']"
                                               decoration-warning="state in ['researcher']"/>
                                        <field name="return_reason_id" optional="hide"/>
                                        <button name="action_return_bank"
                                                type="object"
                                                string="Bank Return"
                                                class="btn btn-danger"
                                                attrs="{'invisible': ['|',('state', '!=', 'accounting_approve'),('parent.state', '!=', 'waiting_deposit')]}"
                                        />
                                    </tree>
                                </field>
                            </page>
                            <page string="Confirm Benefit Expenses"
                                  attrs="{'invisible':[('type','!=','benefit_expense')]}">
                                <field name="benefit_expense_line_ids" widget="one2many_list"
                                       readonly="1">
                                    <tree>
                                        <field name="family_id"/>
                                        <field name="branch_id"/>
                                        <field name="family_category_id"/>
                                        <field name="start_date" invisible="1"/>
                                        <field name="end_date" invisible="1"/>
                                        <field name="meal_card"/>
                                        <field name="benefit_member_count"/>
                                        <field name="family_monthly_income"/>
                                        <field name="family_monthly_meals"/>
                                        <field name="family_monthly_clotting"/>
                                        <field name="total_family_expenses"/>
                                        <field name="payment_order_id" invisible="1"/>
                                        <field name="is_return" optional="hide"/>
                                        <field name="return_reason_id" optional="hide"/>
                                        <button name="action_return_bank"
                                                type="object"
                                                string="Bank Return"
                                                class="btn btn-danger"
                                                attrs="{'invisible': ['|',('is_return', '=', True),('parent.state', '!=', 'waiting_deposit')]}"
                                        />
                                    </tree>
                                </field>
                            </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers"
                               groups="base.group_user"/>
                        <field name="activity_ids"/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </form>
            </field>
        </record>
        <record id="payment_orders_tree" model="ir.ui.view">
            <field name="name">payment.orders.tree</field>
            <field name="model">payment.orders</field>
            <field name="arch" type="xml">
                <tree string="Payment Orders" create="false">
                    <field name="name" readonly="1"/>
                    <field name="payment_order_date"/>
                    <field name="accountant_id" widget="many2one_avatar_user"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <field name="currency_id" groups="base.group_multi_currency" invisible="1"/>
                    <field name="total_amount" widget="monetary" decoration-bf="1"
                           options="{'currency_field': 'currency_id'}"/>
                    <field name="type"/>
                    <field name="move_id" invisible="1"/>
                    <field name="state"
                           widget="badge"
                           decoration-info="state == 'draft'"
                           decoration-warning="state not in ['draft','done']"
                           decoration-success="state == 'done'"
                    />
                    <field name="can_user_act" invisible="1"/>
                    <button name="action_manager_approval" type="object"
                            attrs="{'invisible': ['|', ('state','!=','draft'), ('can_user_act','=',False)]}"
                            string="Manager approval" class="oe_highlight"/>
                    <button name="action_refuse" type="object"
                            attrs="{'invisible': ['|', ('state','!=','draft'), ('can_user_act','=',False)]}"
                            string="Refuse" class="btn btn-danger"/>

                    <button name="action_head_approval" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_head'), ('can_user_act','=',False)]}"
                            string="Approve" class="oe_highlight"/>
                    <button name="action_reset_to_draft" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_head'), ('can_user_act','=',False)]}"
                            string="Reset" class="btn btn-warning"/>

                    <button name="action_finance_approval" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_finance'), ('can_user_act','=',False)]}"
                            string="Approve" class="oe_highlight"/>
                    <button name="action_reset_to_draft" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_finance'), ('can_user_act','=',False)]}"
                            string="Reset" class="btn btn-warning"/>

                    <button name="action_gm_approval" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_gm'), ('can_user_act','=',False)]}"
                            string="Approve" class="oe_highlight"/>
                    <button name="action_reset_to_draft" type="object"
                            attrs="{'invisible': ['|', ('state','!=','waiting_gm'), ('can_user_act','=',False)]}"
                            string="Reset" class="btn btn-warning"/>

                    <button name="create_entry" type="object"
                            string="Create Entry" class="oe_highlight"
                            attrs="{'invisible': ['|', '|',('state','!=','waiting_deposit'),('move_id', '!=',False), ('can_user_act','=',False)]}"
                    />
                    <button name="action_deposit" type="object"
                            string="Deposit Completed" class="oe_highlight"
                            attrs="{'invisible': ['|', '|',('state','!=','waiting_deposit'),('move_id', '=',False), ('can_user_act','=',False)]}"
                    />
                </tree>
            </field>
        </record>
        <record model="ir.ui.view" id="view_payment_ordres_search">
            <field name="name">payment.orders</field>
            <field name="model">payment.orders</field>
            <field name="arch" type="xml">
                <search>
                    <separator/>
                    <filter string="Draft" name="draft" domain="[('state','=','draft')]"/>
                    <separator/>
                    <separator/>
                    <filter string="Refused" name="refused" domain="[('state', '=', 'refused')]"/>
                    <separator/>
                </search>
            </field>
        </record>
        <!-- Action -->
        <record id="action_payment_orders" model="ir.actions.act_window">
            <field name="name">Payment Orders</field>
            <field name="res_model">payment.orders</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="payment_orders_tree"/>
        </record>
    </data>
</odoo>