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

    <record id="view_order_form_inherit_sale_project" model="ir.ui.view">
        <field name="name">sale.order.form.sale.project</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="priority">10</field>
        <field name="arch" type="xml">
            <button id="create_invoice_percentage" position="after">
                <button id="create_project" name="action_create_project" string="Create Project"
                    type="object" data-hotkey="q"
                    invisible="not show_create_project_button"
                    groups="project.group_project_manager"/>
            </button>
            <xpath expr="//button[@name='action_view_invoice']" position="before">
                <field name="show_task_button" invisible="1"/>
                <field name="show_project_button" invisible="1"/>
                <field name="show_create_project_button" invisible="1"/>
                <field name="project_ids" invisible="1"/>
                <field name="is_product_milestone" invisible="1"/>
                <button type="object" name="action_view_project_ids" class="oe_stat_button" icon="fa-puzzle-piece" invisible="not show_project_button" groups="project.group_project_user">
                    <field name="project_count" widget="statinfo" string="Projects"/>
                </button>
                <button class="oe_stat_button" name="action_view_milestone" type="object" icon="fa-check-square-o" invisible="not is_product_milestone or not project_ids or state == 'draft'" groups="project.group_project_milestone">
                    <field name="milestone_count" widget="statinfo" string="Milestones"/>
                </button>
                <button type="object" name="action_view_task" class="oe_stat_button" icon="fa-tasks" invisible="not show_task_button" groups="project.group_project_user">
                    <field name="tasks_count" widget="statinfo" string="Tasks"/>
                </button>
            </xpath>
            <xpath expr="//field[@name='analytic_account_id']" position="after">
                <field name="visible_project" invisible="1"/>
                <field name="project_id" options="{'no_create': True}" invisible="not visible_project" readonly="state not in ['draft', 'sent']"/>
            </xpath>
        </field>
    </record>

</odoo>
