<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_task_form2_inherited" model="ir.ui.view">
        <field name="name">Add timesheet time controls</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="hr_timesheet.view_task_form2_inherited" />
        <field name="arch" type="xml">
            <!-- Main task form action buttons -->
            <div name="button_box" position="inside">
                <field
                    name="show_time_control"
                    invisible="1"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <button
                    name="button_start_work"
                    string="Start work"
                    type="object"
                    icon="fa-play-circle text-success"
                    attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
                    class="oe_stat_button"
                    title="Start work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <button
                    name="button_end_work"
                    string="Stop work"
                    type="object"
                    icon="fa-stop-circle text-warning"
                    attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                    class="oe_stat_button"
                    title="End work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
            </div>
            <!-- Sub-tree view for timesheet_ids -->
            <xpath
                expr="//field[@name='timesheet_ids']/tree//field[@name='date']"
                position="attributes"
            >
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath
                expr="//field[@name='timesheet_ids']/tree//field[@name='date']"
                position="after"
            >
                <field name="date_time" string="Date" required="1" />
            </xpath>
            <xpath expr="//field[@name='timesheet_ids']/tree" position="inside">
                <field name="show_time_control" invisible="1" />
                <button
                    name="button_resume_work"
                    title="Resume work"
                    tabindex="-1"
                    type="object"
                    icon="fa-play-circle text-success"
                    attrs="{'invisible': [('show_time_control', '!=', 'resume')]}"
                    class="oe_stat_button"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <button
                    name="button_end_work"
                    title="Stop work"
                    tabindex="-1"
                    type="object"
                    icon="fa-stop-circle text-warning"
                    attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                    class="oe_stat_button"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
            </xpath>
            <xpath expr="//field[@name='timesheet_ids']/tree" position="attributes">
                <attribute name="default_order">date_time</attribute>
            </xpath>
            <!-- Sub-kanban view for timesheet_ids -->
            <xpath
                expr="//field[@name='timesheet_ids']/kanban//*[@t-esc='record.date.value']"
                position="attributes"
            >
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath
                expr="//field[@name='timesheet_ids']/kanban//*[@t-esc='record.date.value']"
                position="after"
            >
                <field name="date_time" required="1" />
            </xpath>
            <xpath
                expr="//field[@name='timesheet_ids']/kanban//templates//field[@name='unit_amount']"
                position="after"
            >
                <field
                    name="show_time_control"
                    invisible="1"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <a
                    name="button_resume_work"
                    tabindex="-1"
                    type="object"
                    string="Resume work"
                    attrs="{'invisible': [('show_time_control', '!=', 'resume')]}"
                    class="o_kanban_inline_block fa fa-lg fa-play-circle text-success"
                    title="Resume work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <a
                    name="button_end_work"
                    tabindex="-1"
                    type="object"
                    string="Stop work"
                    attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                    class="o_kanban_inline_block fa fa-lg fa-stop-circle text-warning"
                    title="Stop work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
            </xpath>
            <!-- Sub-form view for timesheet_ids -->
            <xpath
                expr="//field[@name='timesheet_ids']/form//field[@name='date']"
                position="attributes"
            >
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath
                expr="//field[@name='timesheet_ids']/form//field[@name='date']"
                position="after"
            >
                <field name="date_time" required="1" />
            </xpath>
            <xpath expr="//field[@name='timesheet_ids']/form/sheet/*" position="before">
                <div class="oe_button_box" name="button_box">
                    <field
                        name="show_time_control"
                        invisible="1"
                        groups="hr_timesheet.group_hr_timesheet_user"
                    />
                    <button
                        name="button_resume_work"
                        tabindex="-1"
                        type="object"
                        icon="fa-play-circle text-success"
                        attrs="{'invisible': [('show_time_control', '!=', 'resume')]}"
                        class="oe_stat_button"
                        context="{'show_created_timer': True}"
                        title="Resume work"
                        groups="hr_timesheet.group_hr_timesheet_user"
                    />
                    <button
                        name="button_end_work"
                        tabindex="-1"
                        type="object"
                        icon="fa-stop-circle text-warning"
                        attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                        class="oe_stat_button"
                        title="Stop work"
                        groups="hr_timesheet.group_hr_timesheet_user"
                    />
                </div>
            </xpath>
        </field>
    </record>
    <record id="view_task_kanban" model="ir.ui.view">
        <field name="name">Add timesheet time controls</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="project.view_task_kanban" />
        <field name="arch" type="xml">
            <xpath expr="//*[hasclass('oe_kanban_bottom_left')]" position="inside">
                <field
                    name="show_time_control"
                    invisible="1"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <a
                    name="button_start_work"
                    attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
                    class="o_kanban_inline_block fa fa-lg fa-play-circle text-success"
                    tabindex="-1"
                    type="object"
                    title="Start work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <a
                    name="button_end_work"
                    attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                    class="o_kanban_inline_block fa fa-lg fa-stop-circle text-warning"
                    tabindex="-1"
                    type="object"
                    title="Stop work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
            </xpath>
        </field>
    </record>
    <record id="view_task_tree2_inherited" model="ir.ui.view">
        <field name="name">Add timesheet time controls</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="hr_timesheet.view_task_tree2_inherited" />
        <field name="arch" type="xml">
            <tree position="inside">
                <field
                    name="show_time_control"
                    invisible="1"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <button
                    name="button_start_work"
                    string="Start work"
                    tabindex="-1"
                    type="object"
                    icon="fa-play-circle text-success"
                    attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
                    class="oe_stat_button"
                    title="Start work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
                <button
                    name="button_end_work"
                    string="Stop work"
                    tabindex="-1"
                    type="object"
                    icon="fa-stop-circle text-warning"
                    attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
                    class="oe_stat_button"
                    title="End work"
                    groups="hr_timesheet.group_hr_timesheet_user"
                />
            </tree>
        </field>
    </record>
</odoo>
