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

    <record id="project_sharing_inherit_project_task_view_form" model="ir.ui.view">
        <field name="name">project.task.form.inherit.timesheet</field>
        <field name="model">project.task</field>
        <field name="priority">600</field>
        <field name="inherit_id" ref="hr_timesheet.project_sharing_inherit_project_task_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='timesheet_ids']/list" position="attributes">
                <attribute name="decoration-muted">reinvoice_move_id != False</attribute>
            </xpath>
            <xpath expr="//field[@name='timesheet_ids']/list/field[@name='unit_amount']" position="before">
                <field name="reinvoice_move_id" column_invisible="True"/>
                <field name="so_line" widget="so_line_field"
                    column_invisible="not parent.allow_billable"
                    context="{'with_remaining_hours': True, 'with_price_unit': True}" options="{'no_create': True, 'no_open': True}"
                    optional="hide"/>
            </xpath>
            <xpath expr="//field[@name='child_ids']/list/field[@name='remaining_hours']" position="after">
                <field name="remaining_hours_available" column_invisible="True"/>
                <field name="remaining_hours_so" optional="hide" widget="timesheet_uom" column_invisible="not parent.allow_timesheets"/>
            </xpath>
            <xpath expr="//field[@name='depend_on_ids']/list/field[@name='remaining_hours']" position="after">
                <field name="remaining_hours_available" column_invisible="True"/>
                <field name="remaining_hours_so" optional="hide" widget="timesheet_uom" column_invisible="not parent.allow_timesheets"/>
            </xpath>
            <xpath expr="//div[@id='remaining_hours_div']" position="after">
                <div class="row align-items-center mb-2" 
                    invisible="not allow_billable or not sale_order_id or not partner_id or not sale_line_id or not remaining_hours_available">
                    <field name="allow_billable" invisible="1" />
                    <field name="remaining_hours_available" invisible="1"/>
                    <field name="sale_order_id" invisible="1"/>
                    <div id="remaining_hours_so_label" class="col-8">
                        <label class="fw-bold" for="remaining_hours_so"
                            invisible="remaining_hours_so &lt; 0"/>
                        <label class="fw-bold text-danger" for="remaining_hours_so"
                            invisible="remaining_hours_so &gt;= 0"/>
                    </div>
                    <div class="col-4">
                        <field name="remaining_hours_so" nolabel="1" widget="timesheet_uom" decoration-danger="remaining_hours_so &lt; 0"/>
                    </div>
                </div>
            </xpath>
        </field>
    </record>

</odoo>
