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

    <!--<record id="view_account_analytic_line_inherit_percentage" model="ir.ui.view">
        <field name="name">Percentage Analytic</field>
        <field name="model">account.analytic.line</field>
        <field name="inherit_id" ref="analytic.view_account_analytic_line_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='currency_id']" position="after">
                 <separator string="Percentage"/>
                    <field name="ispercentage"/>
                    <field name="percentage_rate" attrs="{'invisible':[('ispercentage','=',False)]}"/>
                    <field name="per_from_amt" attrs="{'invisible':[('ispercentage','=',False)]}"/>
            </xpath>
        </field>
    </record>-->

    <record id="view_hr_task_timesheet_inherit_time" model="ir.ui.view">
        <field name="name">Start and End time task timesheets</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="hr_timesheet.view_task_form2_inherited"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='timesheet_ids']//tree//field[@name='name']" position="after">
                <field name="start_datetime" string="Start date"/>
                <field name="end_datetime" string="End date"/>
            </xpath>
            <!--<xpath expr="//field[@name='timesheet_ids']//tree//field[@name='unit_amount']" position="after">
                <field name="parent_project"/>
            </xpath>-->
        </field>
    </record>

    <record id="view_account_analytic_line_inherit1" model="ir.ui.view">
        <field name="name">Analytic line</field>
        <field name="model">account.analytic.line</field>
        <field name="inherit_id" ref="analytic.view_account_analytic_line_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="replace">
                <field name="unit_amount" string="Quantity"/>
            </xpath>
        </field>
    </record>

    <!--<record id="hr_timesheet_line_tree_inherit1" model="ir.ui.view">
        <field name="name">account.analytic.line.tree.hr_timesheet_inherit1</field>
        <field name="model">account.analytic.line</field>
        <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='name']" position="after">
                <field name="start_time" widget="float_time" invisible="1"/>
                <field name="end_time" widget="float_time" invisible="1"/>
                <field name="start_datetime" string="Start date"/>
                <field name="end_datetime" string="End date"/>
            </xpath>
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="parent_project"/>
            </xpath>
        </field>
    </record>-->

    <record id="hr_timesheet.hr_timesheet_line_tree" model="ir.ui.view">
        <field name="name">account.analytic.line.tree.hr_timesheet</field>
        <field name="model">account.analytic.line</field>
        <field name="arch" type="xml">
            <tree editable="top" string="Timesheet Activities" sample="1">
                <field name="date" readonly="1" invisible="1"/>
                <field name="employee_id" invisible="1"/>
                <!--<field name="project_ids" widget="many2many_tags"/>-->
                <field name="project_id" required="1" options="{'no_create_edit': True}"
                       context="{'form_view_ref': 'project.project_project_view_form_simplified',}"
                       />
                <field name="sub_project" options="{'no_open': True, 'no_create': True, 'no_create_edit': True}"/>
                <field name="task_id" optional="show" options="{'no_create_edit': True, 'no_open': True}"
                       widget="task_with_hours" context="{'default_project_id': project_id}"
                       domain="[('project_id', '=', project_id)]"/>
                <field name="name" optional="show" required="0"/>
                <field name="start_datetime" string="Start Time"/><!--custom-->
                <field name="end_datetime" string="End Time"/><!--custom-->
                <field name="unit_amount" optional="show" widget="timesheet_uom" sum="Total"
                       decoration-danger="unit_amount &gt; 24"/>
                <!--<field name="parent_project" options="{'no_open': True, 'no_create': True, 'no_create_edit': True}"/>--><!--custom-->
                <field name="company_id" invisible="1"/>
                <field name="user_id" invisible="1"/>
            </tree>
        </field>
    </record>

    <!-- Overide all timesheet action -->
    <record id="hr_timesheet.timesheet_action_all" model="ir.actions.act_window">
        <field name="name">All Timesheets</field>
        <field name="res_model">account.analytic.line</field>
        <field name="view_mode">tree,form,pivot,kanban,calendar</field>
        <field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_search"/>
        <field name="domain">[('project_id', '!=', False)]</field>
        <field name="context">{
            'search_default_week':1,
            }
        </field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No activities found. Let's start a new one!
            </p>
            <p>
                Track your working hours by projects every day and invoice this time to your customers.
            </p>
        </field>
    </record>

    <record id="view_hr_timesheet_line_calendar" model="ir.ui.view">
        <field name="name">account.analytic.line.calendar</field>
        <field name="model">account.analytic.line</field>
        <field name="arch" type="xml">
            <calendar string="Timesheet" date_start="start_datetime" date_stop="end_datetime" date_delay="unit_amount"
                      color="project_id"
                      form_view_id="%(hr_timesheet.hr_timesheet_line_form)d" event_open_popup="true" quick_add="False">
                <!--<field name="project_ids" widget="many2many_tags"/>-->
                <field name="project_id"/>
                <field name="name"/>
            </calendar>
        </field>
    </record>

    <record id="timesheet_action_view_all_calendar" model="ir.actions.act_window.view">
        <field name="sequence" eval="4"/>
        <field name="view_mode">calendar</field>
        <field name="view_id" ref="view_hr_timesheet_line_calendar"/>
        <field name="act_window_id" ref="hr_timesheet.timesheet_action_all"/>
    </record>

    <!-- Overide my timesheet action -->

    <record id="hr_timesheet.act_hr_timesheet_line" model="ir.actions.act_window">
        <field name="name">My Timesheets</field>
        <field name="res_model">account.analytic.line</field>
        <field name="view_mode">calendar,tree,form,kanban</field>
        <field name="domain">[('project_id', '!=', False), ('user_id', '=', uid)]</field>
        <field name="context">{
            "search_default_week":1,
            }
        </field>
        <field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_my_timesheet_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No activities found. Let's start a new one!
            </p>
            <p>
                Track your working hours by projects every day and invoice this time to your customers.
            </p>
        </field>
    </record>

    <record id="hr_timesheet.hr_timesheet_line_form" model="ir.ui.view">
        <field name="name">account.analytic.line.form</field>
        <field name="model">account.analytic.line</field>
        <field name="priority">1</field>
        <field name="inherit_id" eval="False"/>
        <field name="arch" type="xml">
            <form string="Analytic Entry">
                <sheet string="Analytic Entry">
                    <group>
                        <field name="name" required="0"/>
                        <field name="employee_id" invisible="1"/>
                    </group>
                    <group>
                        <group>
                            <field name="project_id" required="1"
                                   context="{'form_view_ref': 'project.project_project_view_form_simplified',}"/>
                            <field name="sub_project"
                                   options="{'no_open': True, 'no_create': True, 'no_create_edit': True}"/>
                            <field name="task_id" widget="task_with_hours" context="{'default_project_id': project_id}"
                                   domain="[('project_id', '=', project_id)]"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                            <field name="date" readonly="1"/>
                        </group>
                        <group>
                            <!--<field name="amount"/>-->
                            <field name="amount" invisible="1"/>
                            <field name="start_datetime" string="Start Time"/><!--custom-->
                            <field name="end_datetime" string="End Time"/><!--custom-->
                            <field name="unit_amount" widget="timesheet_uom" decoration-danger="unit_amount &gt; 24"/>
                            <field name="currency_id" invisible="1"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="timesheet_view_inherit1_search" model="ir.ui.view">
        <field name="name">account.analytic.line.search</field>
        <field name="model">account.analytic.line</field>
        <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_search"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='date']" position="replace">
                <!-- <field name="start_datetime"/> -->
            </xpath>
            <xpath expr="//filter[@name='month']" position="replace">
                <filter name="month" string="Start Time" date="start_datetime"/>
            </xpath>
            <xpath expr="//filter[@name='groupby_date']" position="replace">
                <filter string="Start Time" name="groupby_startdate" domain="[]"
                        context="{'group_by': 'start_datetime'}" help="Timesheet by Start Date"/>
            </xpath>
        </field>
    </record>

    <!--<record id="view_account_analytic_line_inherit1_filter" model="ir.ui.view">
        <field name="name">account.analytic.line.search2</field>
        <field name="model">account.analytic.line</field>
        <field name="inherit_id" ref="analytic.view_account_analytic_line_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='date']" position="replace">
                <field name="start_datetime"/>
            </xpath>
            <xpath expr="//filter[@name='date']" position="replace">
                <filter string="Start Time" name="start_datetime" date="date"/>
            </xpath>
            <xpath expr="//group[@name='groupby']//filter[@name='group_date']" position="replace">
                <filter string="Start Time" name="group_startdate" context="{'group_by': 'start_datetime'}"/>
            </xpath>
        </field>
    </record>-->


    <record id="view_hr_my_timesheet_line_calendar" model="ir.ui.view">
        <field name="name">account.analytic.line.calendar</field>
        <field name="model">account.analytic.line</field>
        <field name="arch" type="xml">
            <calendar string="Timesheet" date_start="start_datetime" date_stop="end_datetime" date_delay="unit_amount"
                      color="project_id"
                      form_view_id="%(hr_timesheet.hr_timesheet_line_form)d" event_open_popup="true" quick_add="False">
                <field name="project_id"/>
                <field name="name"/>
                <field name="start_datetime" string="Start date"/>
                <field name="end_datetime" string="End date"/>
            </calendar>
        </field>
    </record>

    <record id="timesheet_action_view_my_calendar" model="ir.actions.act_window.view">
        <field name="sequence" eval="3"/>
        <field name="view_mode">calendar</field>
        <field name="view_id" ref="view_hr_my_timesheet_line_calendar"/>
        <field name="act_window_id" ref="hr_timesheet.act_hr_timesheet_line"/>
    </record>

</odoo>
