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

    <!-- Penalty List View -->
    <record id="view_fusion_clock_penalty_list" model="ir.ui.view">
        <field name="name">fusion.clock.penalty.list</field>
        <field name="model">fusion.clock.penalty</field>
        <field name="arch" type="xml">
            <list string="Clock Penalties" default_order="date desc">
                <field name="date"/>
                <field name="employee_id"/>
                <field name="penalty_type"/>
                <field name="scheduled_time" widget="datetime"/>
                <field name="actual_time" widget="datetime"/>
                <field name="difference_minutes" string="Diff (min)"/>
                <field name="penalty_minutes" string="Deducted (min)"/>
                <field name="company_id" groups="base.group_multi_company"/>
            </list>
        </field>
    </record>

    <!-- Penalty Form View -->
    <record id="view_fusion_clock_penalty_form" model="ir.ui.view">
        <field name="name">fusion.clock.penalty.form</field>
        <field name="model">fusion.clock.penalty</field>
        <field name="arch" type="xml">
            <form string="Clock Penalty">
                <sheet>
                    <group>
                        <group>
                            <field name="employee_id"/>
                            <field name="penalty_type"/>
                            <field name="date"/>
                            <field name="attendance_id"/>
                        </group>
                        <group>
                            <field name="scheduled_time"/>
                            <field name="actual_time"/>
                            <field name="difference_minutes"/>
                            <field name="penalty_minutes"/>
                        </group>
                    </group>
                    <group>
                        <field name="note" nolabel="1" colspan="2" placeholder="Additional notes..."/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Penalty Search View -->
    <record id="view_fusion_clock_penalty_search" model="ir.ui.view">
        <field name="name">fusion.clock.penalty.search</field>
        <field name="model">fusion.clock.penalty</field>
        <field name="arch" type="xml">
            <search string="Search Penalties">
                <field name="employee_id"/>
                <field name="penalty_type"/>
                <filter name="late_in" string="Late Clock-In" domain="[('penalty_type', '=', 'late_in')]"/>
                <filter name="early_out" string="Early Clock-Out" domain="[('penalty_type', '=', 'early_out')]"/>
                <separator/>
                <filter name="this_week" string="This Week"
                        domain="[('date', '>=', (context_today() - datetime.timedelta(days=context_today().weekday())).strftime('%Y-%m-%d'))]"/>
                <filter name="this_month" string="This Month"
                        domain="[('date', '>=', context_today().strftime('%Y-%m-01'))]"/>
                <separator/>
                <filter name="group_employee" string="Employee" context="{'group_by': 'employee_id'}"/>
                <filter name="group_type" string="Penalty Type" context="{'group_by': 'penalty_type'}"/>
                <filter name="group_date" string="Date" context="{'group_by': 'date:month'}"/>
            </search>
        </field>
    </record>

    <!-- Penalty Action -->
    <record id="action_fusion_clock_penalty" model="ir.actions.act_window">
        <field name="name">Penalties</field>
        <field name="res_model">fusion.clock.penalty</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_fusion_clock_penalty_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No penalties recorded
            </p>
            <p>
                Penalties are automatically created when employees clock in late or clock out early.
            </p>
        </field>
    </record>

</odoo>
