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

    <record id="project_project_analytic_view_form" model="ir.ui.view">
        <field name="name">Project Analytic</field>
        <field name="model">project.project</field>
        <field name="inherit_id" ref="project.edit_project"/>
        <field name="arch" type="xml">
            <!--<div name="button_box" position="inside">
                <button class="oe_stat_button" type="object" name="action_view_account_analytic_line" icon="fa-usd"
                        attrs="{'invisible': [('allow_billable','=',False)]}" string="Cost/Revenue" widget="statinfo">
                </button>
            </div>-->
            <xpath expr="//field[@name='user_id']" position="replace">
                <field name="user_id" string="Project Manager" widget="many2one_avatar_user" required="0"
                       attrs="{'readonly':[('active','=',False)]}" domain="[('share', '=', False)]"/>
            </xpath>
            <xpath expr="//field[@name='partner_id']" position="replace">
                <field name="partner_id" string="Client" required="0"/>
                <field name="date_start"/>
                <field name="date"/>
            </xpath>
            <xpath expr="//page[@name='settings']" position="after">
                <page string="Consultant Allocation"
                      attrs="{'invisible':['|',('pricing_type','!=','employee_rate'),('project_type','!=','hours_in_consultant')]}">
                    <field name="project_cons_hrs">
                        <tree editable="top">
                            <field name="project_id" invisible="1"/>
                            <field name="employee_id" options="{'no_create_edit': True, 'no_quick_create': True}"/>
                            <field name="start_date"/>
                            <field name="end_date"/>
                            <field name="percentage"/>
                            <field name="budgeted_hours"/>
                            <field name="actual_percentage"/>
                            <field name="actual_hours"/>
                        </tree>
                    </field>
                </page>
            </xpath>
            <xpath expr="//field[@name='privacy_visibility']" position="before">
                <field name="tag_ids" widget="many2many_tags"/>
            </xpath>
        </field>
    </record>


    <record id="inherit_project_project_view_form" model="ir.ui.view">
        <field name="name">project.project.form.inherit</field>
        <field name="model">project.project</field>
        <field name="inherit_id" ref="sale_timesheet.project_project_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//button[@name='action_view_timesheet']" position="replace">
                <button string="Project Overview" class="oe_stat_button" type="object" name="action_view_timesheet"
                        icon="fa-puzzle-piece" attrs="{'invisible': [('allow_billable', '=', False)]}" invisible="1"/>
            </xpath>
            <xpath expr="//page[@name='billing_employee_rate']" position="replace">
                <page name="billing_employee_rate" string="Invoicing"
                      attrs="{'invisible': [('allow_billable', '=', False)]}">
                    <group>
                        <field name="display_create_order" invisible="1"/>
                        <!--<field name="project_type" widget="radio"/>-->
                        <field name="bill_type" widget="radio" invisible="1"/>
                        <field name="pricing_type"
                               attrs="{'invisible': ['|', ('allow_billable', '=', False), ('bill_type', '!=', 'customer_project')], 'required': ['&amp;', ('allow_billable', '=', True), ('allow_timesheets', '=', True)]}"
                               widget="radio"/>
                        <field name="project_type" attrs="{'invisible': [('pricing_type', '=', 'fixed_rate')]}"
                               widget="radio"/>
                        <field name="budgeted_revenue"
                               attrs="{'invisible': [('pricing_type', '=', 'fixed_rate')], 'required': [('pricing_type','!=','fixed_rate')]}"/>
                        <field name="comment"/>
                        <!-- attrs="{'invisible': [('pricing_type','=','fixed_rate')], 'required': [('pricing_type','!=','fixed_rate')]}"-->

                        <field name="hour_distribution" widget="radio"
                               attrs="{'invisible': ['|',('project_type','!=','hours_in_consultant'),('pricing_type','=','fixed_rate')]}"/>
                        <field name="manager_per" attrs="{'invisible': [('hour_distribution','!=','Percentage')]}"/>
                        <field name="employee_per" attrs="{'invisible': [('hour_distribution','!=','Percentage')]}"/>
                        <field name="expenses_per" attrs="{'invisible': [('pricing_type','=','fixed_rate')]}"/>
                        <field name="expenses_amt" attrs="{'invisible': [('pricing_type','=','fixed_rate')]}"/>
                        <div class="o_td_label"
                             attrs="{'invisible': ['|', '|', ('allow_timesheets', '=', False), ('sale_order_id', '!=', False), '&amp;', ('pricing_type', '!=', 'fixed_rate'), ('bill_type', '!=', 'customer_task')]}">
                            <!--<label for="timesheet_product_id" string="Default Service"
                                   attrs="{'invisible': [('bill_type', '!=', 'customer_task')]}"/>
                            <label for="timesheet_product_id" string="Service"
                                   attrs="{'invisible': [('bill_type', '=', 'customer_task')]}"/>-->
                        </div>
                        <!--<field name="timesheet_product_id" nolabel="1"
                               attrs="{'invisible': ['|', '|', ('allow_timesheets', '=', False), ('sale_order_id', '!=', False), '&amp;', ('pricing_type', '!=', 'fixed_rate'), ('bill_type', '!=', 'customer_task')], 'required': ['&amp;', ('allow_billable', '=', True), ('allow_timesheets', '=', True)]}"
                               context="{'default_type': 'service', 'default_service_policy': 'delivered_timesheet', 'default_service_type': 'timesheet'}"/>-->
                        <field name="timesheet_product_id" nolabel="1"
                               invisible="1"
                               context="{'default_type': 'service', 'default_service_policy': 'delivered_timesheet', 'default_service_type': 'timesheet'}"/>
                        <field name="sale_order_id" invisible="1"/>
                        <!--<field name="sale_line_id" string="Default Sales Order Item"
                               attrs="{'invisible': ['|', '|', ('sale_order_id', '=', False), ('bill_type', '!=', 'customer_project'), ('pricing_type', '!=', 'fixed_rate')], 'readonly': [('sale_order_id', '=', False)]}"
                               options="{'no_create': True, 'no_edit': True, 'delete': False}"/>-->
                        <field name="sale_line_id" string="Default Sales Order Item"
                               invisible="1"
                               options="{'no_create': True, 'no_edit': True, 'delete': False}"/>
                    </group>
                    <field name="sale_line_employee_ids"
                           attrs="{'invisible': ['|', ('bill_type', '!=', 'customer_project'), ('pricing_type', '!=', 'employee_rate')]}">
                        <tree editable="top">
                            <field name="company_id" invisible="1"/>
                            <field name="project_id" invisible="1"/>
                            <field name="hour_distribution" invisible="1"/>
                            <field name="employee_id" options="{'no_create': True}" string="Consultant Name"/>
                            <field name="role"
                                   attrs="{'required': [('hour_distribution','=','Percentage')]}"/>
                            <field name="distribution_per"
                                   attrs="{'invisible': [('hour_distribution','!=','Percentage')], 'required': [('hour_distribution','=','Percentage')]}"/>
                            <!--<field name="sale_line_id" options="{'no_create': True}"
                                   attrs="{'column_invisible': [('parent.sale_order_id', '=', False)]}"
                                   domain="[('order_id','=',parent.sale_order_id), ('is_service', '=', True)]"/>
                            <field name="price_unit" widget="monetary" options="{'currency_field': 'currency_id'}"
                                   attrs="{'readonly': [('parent.sale_order_id', '!=', False)]}"/>-->
                            <field name="price_unit"
                                   attrs="{'readonly': [('parent.project_type', '=', 'hours_no_limit')]}"/>
                            <field name="currency_id" invisible="1"/>
                            <field name="budgeted_qty"
                                   attrs="{'readonly': [('parent.project_type', '=', 'hours_no_limit')]}"/>
                            <field name="cost"/>
                            <!--<field name="timesheet_product_id"
                                   attrs="{'column_invisible': [('parent.sale_order_id', '!=', False)]}"/>-->
                            <!--<field name="budgeted_uom"
                                   attrs="{'column_invisible': [('parent.sale_order_id', '=', False)]}"/>-->
                            <!--<field name="budgeted_qty"
                                   attrs="{'column_invisible': [('parent.sale_order_id', '=', False)]}"/>-->
                            <field name="employee_price"/>
                            <field name="timesheet_hour"/>
                            <field name="consultant_cost"/>
                            <field name="actual_revenue"/>
                            <field name="budgeted_hour_week" invisible="1"/>
                        </tree>
                    </field>
                    <!--<field name="consultant_timesheet_hrs" readonly="1" attrs="{'invisible': [('pricing_type','!=','fixed_rate')]}">-->
                    <field name="consultant_timesheet_hrs" readonly="1" invisible="1">
                        <tree editable="top">
                            <field name="project_id" invisible="1"/>
                            <field name="employee_id" invisible="0"/>
                            <field name="timesheet_hour" invisible="0"/>
                            <field name="employee_price" invisible="0"/>
                            <field name="consultant_cost" invisible="0"/>
                        </tree>
                    </field>
                    <group>
                        <group attrs="{'invisible': [('pricing_type','=','fixed_rate')]}">
                            <!--<field name="cost"/>-->
                            <field name="actual_revenue"/>
                            <field name="consultant_cost"/>
                            <field name="other_expenses" readonly="1"/>
                            <field name="total_expenses"/>
                            <field name="profit_amt"/>
                            <field name="profit_per"/>
                        </group>
                        <group attrs="{'invisible': [('pricing_type','=','fixed_rate')]}">
                            <field name="budgeted_hours"
                                   attrs="{'invisible': [('project_type','!=','hours_in_consultant')]}"/>
                            <field name="budgeted_hours2" attrs="{'invisible': [('project_type','!=','hours_no_limit')],
                            'required': [('project_type','=','hours_no_limit')]}"/>
                            <field name="timesheet_hour"/>
                            <field name="hourly_rate" attrs="{'readonly': [('project_type','!=','hours_no_limit')]}"/>
                            <field name="budgeted_hour_week" invisible="1"/>
                        </group>

                    </group>
                </page>
            </xpath>

        </field>
    </record>


    <record id="inherit_view_project_tree" model="ir.ui.view">
        <field name="name">project.project.tree.inherit</field>
        <field name="model">project.project</field>
        <field name="inherit_id" ref="project.view_project"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']" position="after">
                <field name="sub_project" widget="many2many_tags"/>
            </xpath>
        </field>
    </record>


    <record id="project.open_view_project_all" model="ir.actions.act_window">
        <field name="name">Projects</field>
        <field name="res_model">project.project</field>
        <field name="domain">[]</field>
        <field name="view_mode">tree,kanban,form</field>
        <field name="view_id" ref="project.view_project"/>
        <field name="search_view_id" ref="project.view_project_project_filter"/>
        <field name="target">main</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No projects found. Let's create one!
            </p>
            <p>
                Projects regroup tasks on the same topic and each have their own dashboard.
            </p>
        </field>
    </record>


    <record id="inherit_view_task_form2" model="ir.ui.view">
        <field name="name">project.task.form.inherit</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="project.view_task_form2"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']" position="replace">
                <field name="partner_id" class="o_task_customer_field" string="Client"/>
            </xpath>
            <xpath expr="//field[@name='date_deadline']" position="before">
                <field name="start_date"/>
            </xpath>
        </field>
    </record>

    <record id="inherit_view_task_tree2" model="ir.ui.view">
        <field name="name">project.task.tree.inherit</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="project.view_task_tree2"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='date_deadline']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <field name="date_deadline" optional="hide" widget="remaining_days"
                   attrs="{'invisible': [('is_closed', '=', True)]}"/>
            <xpath expr="//field[@name='name']" position="before">
                <field name="date_deadline"/>
            </xpath>
            <xpath expr="//field[@name='effective_hours']" position="before">
                <field name="start_date"/>
            </xpath>
        </field>
    </record>

    <!-- Done Task action -->
    <record id="project_task_server_action_batch_done" model="ir.actions.server">
        <field name="name">Done</field>
        <field name="model_id" ref="project.model_project_task"/>
        <field name="binding_model_id" ref="project.model_project_task"/>
        <field name="state">code</field>
        <field name="code">
                if records:
                    action = records.action_done_task()
            </field>
    </record>

    <!-- Tags -->
    <record model="ir.ui.view" id="custom_project_tags_search_view">
        <field name="name">Tags</field>
        <field name="model">custom.project.tags</field>
        <field name="arch" type="xml">
            <search string="Tags">
                <field name="name"/>
            </search>
        </field>
    </record>

    <record model="ir.ui.view" id="custom_project_tags_form_view">
        <field name="name">Tags</field>
        <field name="model">custom.project.tags</field>
        <field name="arch" type="xml">
            <form string="Tags">
                <sheet>
                    <group>
                        <field name="name"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="custom_project_tags_tree_view">
        <field name="name">Tags</field>
        <field name="model">custom.project.tags</field>
        <field name="arch" type="xml">
            <tree string="Tags" editable="bottom" sample="1">
                <field name="name"/>
            </tree>
        </field>
    </record>

    <record id="custom_project_tags_action" model="ir.actions.act_window">
        <field name="name">Project Tags</field>
        <field name="res_model">custom.project.tags</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No tags found. Let's create one!
            </p>
            <p>
                Tags are perfect to categorize your tasks.
            </p>
        </field>
    </record>
    <menuitem action="custom_project_tags_action" id="menu_custom_project_tags_act"
              parent="project.menu_project_config" sequence="9"/>

    <menuitem name="Tasks" id="menu_main_cor_tasks"
              action="project.action_view_all_task" sequence="52"
              groups="base.group_no_one,project.group_project_user"/>
</odoo>
