<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="view_hr_overtime_timesheet_form" model="ir.ui.view">
            <field name="name">hr.overtime.timesheet.form</field>
            <field name="model">hr.overtime.timesheet</field>
            <field name="arch" type="xml">
                <form js_class="xeno_overtime_timesheet_form">
                    <header>
                        <button name="action_submit" type="object" string="Submit"
                                class="btn-primary" invisible="not can_submit"/>
                        <button name="action_pull_week_requests" type="object"
                                string="Refresh Approved Days" class="btn-secondary"
                                invisible="state not in ('draft', 'rejected')"/>
                        <button name="action_hod_approve" type="object" string="Approve (HOD)"
                                class="btn-primary" invisible="not can_hod_decide"/>
                        <button name="action_hod_reject" type="object" string="Reject (HOD)"
                                class="btn-secondary" invisible="not can_hod_decide"
                                confirm="Reject this week's timesheet?"/>
                        <button name="action_hr_calculate_charges" type="object" string="Calculate OT Charges"
                                class="btn-primary" invisible="not can_hr_decide"/>
                        <field name="state" widget="statusbar" statusbar_visible="draft,submitted,approved,charged"/>
                    </header>
                    <sheet>
                        <div class="alert alert-warning" role="alert" invisible="state != 'rejected'">
                            <span invisible="not rejection_reason">Reason: <field name="rejection_reason" readonly="1" nolabel="1"/></span>
                            <span invisible="rejection_reason">This timesheet was rejected -- revise and resubmit.</span>
                        </div>
                        <div class="oe_title">
                            <h1>Overtime Timesheet For <field name="employee_id" readonly="1" nolabel="1"/></h1>
                        </div>
                        <group>
                            <group>
                                <field name="employee_id" invisible="1"/>
                                <field name="department_id" readonly="1"/>
                                <field name="supervisor_id" readonly="1"/>
                                <field name="head_of_department_id" readonly="1"/>
                            </group>
                            <group>
                                <field name="week_start" readonly="state not in ('draft', 'rejected')"/>
                                <field name="week_end" readonly="1"/>
                            </group>
                        </group>
                        <field name="request_ids" create="0" delete="0">
                            <list editable="bottom" decoration-muted="state != 'hod_approved'">
                                <field name="date" readonly="1"/>
                                <field name="time_in" widget="float_time" options="{'type': 'time'}" readonly="not can_edit_timesheet_line"/>
                                <field name="time_out" widget="float_time" options="{'type': 'time'}" readonly="not can_edit_timesheet_line"/>
                                <field name="break_hours" widget="float_time" readonly="not can_edit_timesheet_line"/>
                                <field name="hrs_worked" widget="float_time" readonly="1"/>
                                <field name="computed_ot_hours" widget="float_time" readonly="1" string="OT Hrs"/>
                                <field name="description" readonly="not can_edit_timesheet_line" string="Description of Overtime Duties"/>
                                <field name="can_edit_timesheet_line" column_invisible="1"/>
                                <field name="state" column_invisible="1"/>
                            </list>
                        </field>
                        <group class="oe_subtotal_footer">
                            <field name="total_hrs_work" widget="float_time" string="Weekly Summary: Hrs Work"/>
                            <field name="total_ot_hrs" widget="float_time" string="Weekly Summary: OT Hrs"/>
                        </group>
                        <group string="Head of Department Authorisation">
                            <field name="hod_decided_by" readonly="1"/>
                            <field name="hod_decided_at" readonly="1"/>
                        </group>
                    </sheet>
                    <chatter/>
                </form>
            </field>
        </record>

        <record id="view_hr_overtime_timesheet_list" model="ir.ui.view">
            <field name="name">hr.overtime.timesheet.list</field>
            <field name="model">hr.overtime.timesheet</field>
            <field name="arch" type="xml">
                <list decoration-danger="state == 'rejected'" decoration-success="state == 'charged'">
                    <field name="week_start"/>
                    <field name="week_end"/>
                    <field name="employee_id"/>
                    <field name="department_id" optional="show"/>
                    <field name="head_of_department_id" optional="show"/>
                    <field name="total_hrs_work" widget="float_time" optional="show"/>
                    <field name="total_ot_hrs" widget="float_time"/>
                    <field name="state" widget="badge"
                           decoration-info="state in ('draft', 'submitted')"
                           decoration-success="state in ('approved', 'charged')"
                           decoration-danger="state == 'rejected'"/>
                </list>
            </field>
        </record>

        <record id="view_hr_overtime_timesheet_search" model="ir.ui.view">
            <field name="name">hr.overtime.timesheet.search</field>
            <field name="model">hr.overtime.timesheet</field>
            <field name="arch" type="xml">
                <search>
                    <field name="employee_id"/>
                    <field name="head_of_department_id"/>
                    <filter name="draft" string="Draft" domain="[('state', '=', 'draft')]"/>
                    <filter name="pending_hod" string="Pending HOD" domain="[('state', '=', 'submitted')]"/>
                    <filter name="ready_to_charge" string="Ready to Charge" domain="[('state', '=', 'approved')]"/>
                    <filter name="charged" string="Charged" domain="[('state', '=', 'charged')]"/>
                    <filter name="rejected" string="Rejected" domain="[('state', '=', 'rejected')]"/>
                    <group>
                        <filter name="group_by_employee" string="Employee" context="{'group_by': 'employee_id'}"/>
                        <filter name="group_by_week" string="Week" context="{'group_by': 'week_start'}"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="action_hr_overtime_timesheet_my" model="ir.actions.act_window">
            <field name="name">My Overtime Timesheets</field>
            <field name="res_model">hr.overtime.timesheet</field>
            <field name="view_mode">list,form</field>
            <field name="domain">[('employee_id.user_id', '=', uid)]</field>
            <field name="search_view_id" ref="view_hr_overtime_timesheet_search"/>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">No weekly timesheets yet.</p>
                <p>Create one for the week of your approved OT days -- it pulls in every Approved (HOD)
                   OT request that falls in that week automatically. Enter actual In/Out/Break per day,
                   then submit the whole week for your Head of Department to approve.</p>
            </field>
        </record>

        <record id="action_hr_overtime_timesheet_approvals" model="ir.actions.act_window">
            <field name="name">Timesheet Approvals</field>
            <field name="res_model">hr.overtime.timesheet</field>
            <field name="view_mode">list,form</field>
            <field name="domain">[('head_of_department_id.user_id', '=', uid)]</field>
            <field name="search_view_id" ref="view_hr_overtime_timesheet_search"/>
            <field name="context">{'search_default_pending_hod': 1}</field>
        </record>

        <record id="action_hr_overtime_processing" model="ir.actions.act_window">
            <field name="name">OT Processing (HR/Payroll)</field>
            <field name="res_model">hr.overtime.timesheet</field>
            <field name="view_mode">list,form</field>
            <field name="search_view_id" ref="view_hr_overtime_timesheet_search"/>
            <field name="context">{'search_default_ready_to_charge': 1}</field>
        </record>
    </data>
    <data noupdate="1">
        <menuitem id="menu_xeno_overtime_timesheet_my"
                  name="OT Timesheet (Actual - Approval)"
                  parent="menu_xeno_overtime_group"
                  action="action_hr_overtime_timesheet_my"
                  sequence="3"/>

        <menuitem id="menu_xeno_overtime_timesheet_approvals"
                  name="Timesheet Approvals"
                  parent="menu_xeno_overtime_group"
                  action="action_hr_overtime_timesheet_approvals"
                  sequence="4"/>

        <menuitem id="menu_xeno_overtime_processing"
                  name="OT Processing"
                  parent="menu_xeno_overtime_group"
                  action="action_hr_overtime_processing"
                  groups="hr_holidays.group_hr_holidays_user"
                  sequence="5"/>
    </data>
</odoo>
