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

        <!-- ============================================================
             My Timesheet — list view (Timesheet2-style columns)
        ============================================================ -->

        <record id="view_timesheet_v2_list" model="ir.ui.view">
            <field name="name">account.analytic.line.list.timesheet.v2</field>
            <field name="model">account.analytic.line</field>
            <field name="arch" type="xml">
                <tree string="Timesheet List"
                      editable="bottom"
                      default_order="date desc, id desc"
                      class="o_timesheet_v2_list"
                      decoration-muted="is_invoiced == True"
                      decoration-info="is_internal == True"
                      decoration-success="is_billable == True and is_internal == False"
                      decoration-warning="is_billable == False"
                      >
                    <field name="date"/>
                    <field name="partner_id" string="Client"/>
                    <field name="project_id" column_invisible="True"/>
                    <field name="task_id" column_invisible="True"/>
                    <field name="project_item_display" string="Project / Item"/>
                    <field name="employee_id" string="User"/>
                    <field name="name" string="Invoice Notes"/>
                    <field name="duration_display" string="Duration" readonly="1"/>
                    <field name="time_in" optional="hide"/>
                    <field name="time_out" optional="hide"/>
                    <field name="unit_amount" string="Hours" widget="float_time" sum="Total Hours"/>
                    <field name="amount" sum="Total Amount"/>
                    <field name="is_invoiced" string="Inv" widget="boolean"/>
                    <field name="write_uid" string="Last User" optional="show"/>
                    <field name="write_date" string="Last Edit" optional="show"/>
                    <field name="billable_flag" string="Bill (B)" readonly="1"/>
                    <field name="is_billable" column_invisible="True"/>
                    <field name="is_internal" column_invisible="True"/>
                    <field name="currency_id" column_invisible="True"/>
                </tree>
            </field>
        </record>

        <!-- Quick-entry form -->
        <record id="view_timesheet_v2_form" model="ir.ui.view">
            <field name="name">account.analytic.line.form.timesheet.v2</field>
            <field name="model">account.analytic.line</field>
            <field name="arch" type="xml">
                <form string="Timesheet Entry">
                    <sheet>
                        <group>
                            <group>
                                <field name="date"/>
                                <field name="employee_id"/>
                                <field name="project_id"/>
                                <field name="task_id" domain="[('project_id', '=', project_id)]"/>
                                <field name="partner_id" readonly="1"/>
                            </group>
                            <group>
                                <field name="time_in" widget="float_time"/>
                                <field name="time_out" widget="float_time"/>
                                <field name="unit_amount" widget="float_time" string="Hours"/>
                                <field name="hourly_rate"/>
                                <field name="amount" readonly="1"/>
                                <field name="is_billable"/>
                                <field name="is_invoiced"/>
                            </group>
                        </group>
                        <group string="Invoice Notes">
                            <field name="name" nolabel="1" placeholder="What did you work on?"/>
                        </group>
                        <group string="Internal Notes">
                            <field name="notes_internal" nolabel="1"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <!-- Search / filter bar -->
        <record id="view_timesheet_v2_search" model="ir.ui.view">
            <field name="name">account.analytic.line.search.timesheet.v2</field>
            <field name="model">account.analytic.line</field>
            <field name="arch" type="xml">
                <search string="My Timesheet">
                    <field name="employee_id"/>
                    <field name="partner_id" string="Client"/>
                    <field name="project_id"/>
                    <field name="task_id"/>
                    <field name="name" string="Notes"/>
                    <separator/>
                    <filter name="filter_my_entries" string="My Entries"
                            domain="[('employee_id.user_id', '=', uid)]"/>
                    <filter name="filter_billable" string="Billable"
                            domain="[('is_billable', '=', True)]"/>
                    <filter name="filter_non_billable" string="Non-Billable"
                            domain="[('is_billable', '=', False)]"/>
                    <filter name="filter_internal" string="Internal"
                            domain="[('is_internal', '=', True)]"/>
                    <filter name="filter_not_invoiced" string="Not Invoiced"
                            domain="[('is_invoiced', '=', False)]"/>
                    <separator/>
                    <filter name="filter_this_month" string="This Month"
                            domain="[
                                ('date', '&gt;=', (context_today() + relativedelta(day=1)).strftime('%Y-%m-%d')),
                                ('date', '&lt;=', (context_today() + relativedelta(months=1, day=1, days=-1)).strftime('%Y-%m-%d')),
                            ]"/>
                    <filter name="filter_last_30" string="Last 30 Days"
                            domain="[('date', '&gt;=', (context_today() - relativedelta(days=30)).strftime('%Y-%m-%d'))]"/>
                    <group expand="0" string="Group By">
                        <filter name="group_date_day" string="Date"
                                context="{'group_by': 'date:day'}"/>
                        <filter name="group_client" string="Client"
                                context="{'group_by': 'partner_id'}"/>
                        <filter name="group_project" string="Project"
                                context="{'group_by': 'project_id'}"/>
                        <filter name="group_employee" string="User"
                                context="{'group_by': 'employee_id'}"/>
                    </group>
                </search>
            </field>
        </record>

        <!-- Action: My Timesheet -->
        <record id="action_timesheet_v2_my_timesheet" model="ir.actions.act_window">
            <field name="name">My Timesheet</field>
            <field name="res_model">account.analytic.line</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('project_id', '!=', False)]</field>
            <field name="view_ids" eval="[
                (5, 0, 0),
                (0, 0, {'view_mode': 'tree', 'view_id': ref('jb_timesheet_v2.view_timesheet_v2_list')}),
                (0, 0, {'view_mode': 'form', 'view_id': ref('jb_timesheet_v2.view_timesheet_v2_form')}),
            ]"/>
            <field name="search_view_id" ref="jb_timesheet_v2.view_timesheet_v2_search"/>
            <field name="context">{
                'search_default_filter_my_entries': 1,
                'search_default_filter_this_month': 1,
                'search_default_group_date_day': 1,
            }</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    Log your first timesheet entry
                </p>
                <p>
                    Click a blank row at the bottom to add time quickly, or use <b>New</b>.
                    Set start/end times and hours calculate automatically.
                </p>
            </field>
        </record>

    </data>
</odoo>
