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

    <menuitem id="base.menu_project_long_term" name="Long Term Planning" parent="base.menu_main_pm" sequence="1"/>

    # ------------------------------------------------------
    # Project Resource Allocation
    # ------------------------------------------------------

        <record id="view_project_resource_allocation_gantt" model="ir.ui.view">
            <field name="name">project.resource.allocation.gantt</field>
            <field name="model">project.resource.allocation</field>
            <field name="type">gantt</field>
            <field name="arch" type="xml">
              <gantt color="project_id" date_start="date_start" date_stop="date_end" mode="year">
               <level object="res.users" link="user_id" domain="[]">
                    <field name="name"/>
                </level>
              </gantt>
            </field>
        </record>

        <record id="view_project_resource_allocation_calendar" model="ir.ui.view">
            <field name="name">project.resource.allocation.calendar</field>
            <field name="model">project.resource.allocation</field>
            <field name="type">calendar</field>
            <field eval="2" name="priority"/>
            <field name="arch" type="xml">
                <calendar color="resource_id" date_start="date_start" date_stop="date_end" day_length="12" string="Resources">
                    <field name="phase_id"/>
                    <field name="project_id"/>
                </calendar>
            </field>
        </record>


        <record id="view_project_resource_allocation_form" model="ir.ui.view">
            <field name="name">project.resource.allocation.form</field>
            <field name="model">project.resource.allocation</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Project Resource Allocation">
                    <group colspan="4" col="6">
                        <field name="resource_id"/>
                        <field name="phase_id"/>
                        <field name="project_id"/>
                        <field name="date_start"/>
                        <field name="date_end"/>
                        <field name="useability" string="Availability"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="view_project_resource_allocation_list" model="ir.ui.view">
            <field name="name">project.resource.allocation.list</field>
            <field name="model">project.resource.allocation</field>
            <field name="type">tree</field>
            <field name="priority" eval="5"/>
            <field name="arch" type="xml">
                <tree editable="bottom" string="Project Resource Allocation">
                    <field name="resource_id"/>
                    <field name="phase_id"/>
                    <field name="project_id"/>
                    <field name="useability" string="Availability"/>
                </tree>
            </field>
        </record>

       <record id="view_project_resource_allocation_search" model="ir.ui.view">
            <field name="name">project.resource.allocation.search</field>
            <field name="model">project.resource.allocation</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Resources Allocation">
                    <group colspan="4" col="20">
                        <field name="resource_id"/>
                        <field name="phase_id"/>
                        <field name="project_id"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20">
                        <filter name="resource" string="Resource" icon="terp-personal" domain="[]" context="{'group_by':'resource_id'}"/>
                        <separator orientation="vertical"/>
                        <filter string="Project" icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}"/>
                        <filter string="Phase" icon="terp-project" domain="[]" context="{'group_by':'phase_id'}"/>
                    </group>
                </search>
            </field>
        </record>
       <record id="act_resouce_allocation" model="ir.actions.act_window">
            <field name="name">Resources Allocation</field>
            <field name="res_model">project.resource.allocation</field>
            <field name="view_type">form</field>
            <field name="view_mode">gantt,tree,form,calendar</field>
             <field name="context">{}</field>
            <field name="search_view_id" ref="view_project_resource_allocation_search"/>
        </record>


    # ------------------------------------------------------
    # Project Phase
    # ------------------------------------------------------

        <record id="view_project_phase_form" model="ir.ui.view">
            <field name="name">project.phase.form</field>
            <field name="model">project.phase</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Project Phase">
                    <group colspan="6" col="6">
                        <group colspan="6" col="6" >
                            <field name="name" select="1"/>
                            <field name="project_id" on_change="onchange_project(project_id)"/>
                            <field name="responsible_id"/>
                        </group>
                        <group colspan="6" col="6">
                            <field name="date_start" readonly="1"/>
                            <field name="duration"/>
                            <field name="product_uom" nolabel="1" domain="[('category_id.name', '=', 'Working Time')]"/>
                            <field name="date_end" readonly="1"/>
                        </group>
                    </group>
                    <notebook colspan="4">
                        <page string="Resource Allocation">
                            <field colspan="4" name="resource_ids" nolabel="1">
                                 <tree editable="bottom" string="Project Resource Allocation">
                                    <field name="resource_id" context="{'project_id':parent.project_id}"/>
                                    <field name="date_start"/>
                                    <field name="date_end"/>
                                    <field name="useability" string="Availability"/>
                                  </tree>
                                  <form string="Project Resource Allocation">
                                    <field name="resource_id" context="{'project_id':parent.project_id}"/>
                                    <field name="date_start" /> 
                                    <field name="date_end"/>
                                    <field name="useability" string="Availability"/>
                                  </form>
                             </field>
                            <separator string="" colspan="4"/>
                            <group col="12" colspan="4">
                                <field name="state" select="1"/>
                                <button string="Cancel" name="set_cancel" states="draft,open,pending" icon="gtk-cancel"/>
                                <button string="Draft" name="set_draft" states="open" icon="gtk-indent"/>
                                <button string="Pending" name="set_pending" states="open" icon="gtk-media-pause"/>
                                <button string="Done" name="set_done" states="pending,open" icon="terp-dialog-close"/>
                                <button string="Start Phase" name="set_open" states="pending,draft" icon="gtk-execute"/>
                            </group>
                        </page>
                        <page string="Tasks Details">
                            <field colspan="4" name="task_ids" readonly="1" context="{'default_project_id' :project_id}" nolabel="1">
                                 <tree string="Project's Tasks">
                                    <field name="sequence"/>
                                    <field name="name"/>
                                    <field name="user_id"/>
                                    <field name="date_start"/>
                                    <field name="date_end" />
                                    <field name="planned_hours" widget="float_time"/>
                                    <field name="project_id" invisible="1"/>
                                    <field name="total_hours" sum='Total Hours'/>
                                    <field name="remaining_hours" widget="float_time" sum="Remaining Hours"/>
                                    <field name="state"/>
                                  </tree>
                                  <form string="Project's Tasks">
                                      <notebook colspan="4">
                                          <page string="Task Detail">
                                              <group colspan="4" col="4">
                                                <field name="name"/>
                                                <field name="project_id"/>
                                                <field name="user_id"/>
                                                <field name="sequence"/>
                                            </group>
                                            <group colspan="2" col="2">
                                                  <separator string="Dates" colspan="2"/>
                                                  <field name="date_start"/>
                                                  <field name="date_end" />
                                                  <field name="date_deadline"/>
                                            </group>
                                            <group colspan="2" col="2">
                                                  <separator string="Planning" colspan="2"/>
                                                  <field name="planned_hours" widget="float_time"/>
                                                <field name="total_hours" widget="float_time"/>
                                                <field name="remaining_hours" widget="float_time"/>
                                                <field name="effective_hours" invisible="1"/>
                                            </group>
                                            <group colspan="6" col="4">
                                                <field name="state"/>
                                            </group>
                                        </page>
                                    </notebook>
                                  </form>
                             </field>
                               <button name="%(action_project_schedule_tasks)d" string="Schedule Tasks" type="action" icon="gtk-jump-to"/>
                        </page>
                        <page string="Schedule and Display info">
                           <group colspan="2" col="2">
                                <separator string="Constraints" colspan="2"/>
                                <field name="constraint_date_start"/>
                                <field name="constraint_date_end"/>
                            </group>
                            <group colspan="2" col="2">
                                <separator string="Displaying settings" colspan="2"/>
                                <field name="sequence"/>
                            </group>
                           <separator colspan="4" string="Previous Phases"/>
                           <field colspan="4" name="previous_phase_ids" nolabel="1" domain="[('id','!=',active_id)]"/>
                           <separator colspan="4" string="Next Phases"/>
                           <field colspan="4" name="next_phase_ids" nolabel="1" domain="[('id','!=',active_id)]"/>
                        </page>
                    </notebook>
                    <newline/>
                </form>
            </field>
        </record>

        <record id="view_project_phase_list" model="ir.ui.view">
            <field name="name">project.phase.list</field>
            <field name="model">project.phase</field>
            <field name="type">tree</field>
            <field name="priority" eval="5"/>
            <field name="arch" type="xml">
                <tree colors="grey:state in ('cancelled','done');blue:state in ('pending')" string="Project Phases">
                    <field name="name"/>
                    <field name="project_id" on_change="onchange_project(project_id)"/>
                    <field name="responsible_id"/>
                    <field name="date_start"/>
                    <field name="date_end"/>
                    <field name="duration"/>
                    <field name="state"/>
                     <button name="%(action_project_schedule_tasks)d" string="Schedule Tasks" type="action" icon="gtk-jump-to"/>
                </tree>
            </field>
        </record>

        <record id="view_project_phase_calendar" model="ir.ui.view">
            <field name="name">project.phase.calendar</field>
            <field name="model">project.phase</field>
            <field name="type">calendar</field>
            <field eval="2" name="priority"/>
            <field name="arch" type="xml">
                <calendar color="project_id" date_start="date_start" date_stop="date_end" day_length="12">
                    <field name="name"/>
                    <field name="responsible_id"/>
                </calendar>
            </field>
        </record>

        <record id="view_project_phase_gantt" model="ir.ui.view">
            <field name="name">project.phase.gantt</field>
            <field name="model">project.phase</field>
            <field name="type">gantt</field>
            <field eval="2" name="priority"/>
            <field name="arch" type="xml">
                <gantt color="project_id" date_stop="date_end" date_start="date_start" mode="month">
                    <level object="project.project" link="project_id" domain="[]">
                        <field name="name"/>
                    </level>
                </gantt>
            </field>
        </record>

        <record id="view_project_phase_search" model="ir.ui.view">
            <field name="name">project.phase.search</field>
            <field name="model">project.phase</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Project Phases">
                    <group colspan="4" col="20">
                        <filter string="Current" domain="[('state','in',('open','draft','pending'))]"  name="current" help="Draft, In Progress and Pending Phases" icon="terp-check"/>
                        <filter string="In Progress" name="Progress" domain="[('state','=','open')]" help="In Progress Phases" icon="terp-camera_test"/>
                        <filter string="Pending" domain="[('state','=','pending')]" help="Pending Phases" icon="terp-gtk-media-pause"/>
                        <separator orientation="vertical"/>
                        <field name="name"/>
                        <field name="project_id">
                            <filter domain="[('project_id.user_id','=',uid)]" help="My Projects" icon="terp-folder-violet"/>
                        </field>
                        <field name="responsible_id"/>
                        <field name="date_start"/>
                        <field name="date_end"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20" groups="base.group_extended">
                        <filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'responsible_id'}"/>
                        <separator orientation="vertical"/>
                        <filter string="Project" icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}" name="project"/>
                        <separator orientation="vertical"/>
                        <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                        <separator orientation="vertical"/>
                        <filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by':'date_start'}" help="Start Month"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="act_project_phase" model="ir.actions.act_window">
            <field name="name">Project Phases</field>
            <field name="res_model">project.phase</field>
            <field name="view_type">form</field>
            <field name="view_mode">gantt,tree,form,calendar</field>
            <field name="context">{"search_default_current": 1}</field>
            <field name="search_view_id" ref="view_project_phase_search"/>
            <field name="help">A project can be split into the different phases. For each phase, you can define your resources allocation, describe different tasks and link your phase to previous and next phases, add date constraints for the automated scheduling. Use the long term planning in order to planify your available human resources, convert your phases into a series of tasks when you start working on the project.</field>
        </record>

        <record id="act_project_phase_list" model="ir.actions.act_window">
            <field name="name">Project Phases</field>
            <field name="res_model">project.phase</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form,calendar</field>
             <field name="context">{"search_default_current": 1}</field>
            <field name="search_view_id" ref="view_project_phase_search"/>
        </record>


    # ------------------------------------------------------
    # Project
    # ------------------------------------------------------

        <record id="project.view_project_resource_form1" model="ir.ui.view">
            <field name="name">Project Resource Calendar View</field>
            <field name="model">project.project</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="project.edit_project"/>
            <field name="arch" type="xml">
                <field name="effective_hours" position="after">
                    <field name="resource_calendar_id"/>
                </field>

            </field>
       </record>

    # ------------------------------------------------------
    # Project Task
    # ------------------------------------------------------

        <record id="view_phase_task_form2" model="ir.ui.view">
            <field name="name">phase.task.form2</field>
            <field name="model">project.task</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="project.view_task_form2"/>
            <field name="arch" type="xml">
                <field name="sequence" position="after">
                    <field name="phase_id"/>
                </field>
            </field>
        </record>
        <record id="view_phase_task_search_form" model="ir.ui.view">
            <field name="name">phase.task.search.form</field>
            <field name="model">project.task</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="project.view_task_search_form"/>
            <field name="arch" type="xml">
                <field name="project_id" position="after">
                    <field name="phase_id" select="1"/>
                </field>
            </field>
        </record>

         <record id="view_phase_task_search_form_group" model="ir.ui.view">
            <field name="name">phase.task.search.form.group</field>
            <field name="model">project.task</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="project.view_task_search_form"/>
            <field name="arch" type="xml">
            <filter string="Project" name="group_project_id" icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}" position="after">
            <filter string="Project Phase" name="group_project_id_phase" icon="terp-folder-violet" domain="[]" context="{'group_by':'phase_id'}" groups="base.group_extended"/>
            </filter>
            </field>
        </record>

         <record id="view_phase_task_search_form_tree" model="ir.ui.view">
            <field name="name">phase.task.search.form.tree</field>
            <field name="model">project.task</field>
            <field name="type">tree</field>
            <field name="inherit_id" ref="project.view_task_tree2"/>
            <field name="arch" type="xml">
                <field name="project_id" position="after">
                    <field name="phase_id" invisible="1" groups="base.group_extended"/>
                </field>
            </field>
        </record>

    <act_window
        id="project_phase_task_list"
        name="Related Tasks"
        res_model="project.task"
        src_model="project.phase"
        view_mode="tree,form"
        context="{'search_default_phase_id': [active_id]}"
        domain="[('phase_id', '=', active_id),('project_id','=',project_id)]"
        />

    <act_window
        context="{'search_default_project_id': [active_id]}"
        id="act_project_phases"
        name="Phases"
        res_model="project.phase"
        src_model="project.project"
        domain="[('project_id', '=', active_id)]"
        view_mode="tree,form"
        view_type="form" 
        />

    <act_window
        context="{'search_default_user_id': [user_id]}"
        id="act_project_resource"
        name="Resources"
        res_model="resource.resource"
        src_model="project.project"
        domain="[('user_id', '=',user_id)]"
        view_mode="tree,form"
        view_type="form" 
        />

    # ------------------------------------------------------
    # Menu Items
    # ------------------------------------------------------

        <menuitem action="act_project_phase_list"
            groups="base.group_extended"
            id="menu_project_phase_list" parent="project.menu_project_management" sequence="2"/>

        <menuitem action="act_project_phase"
            icon="STOCK_INDENT"
            groups="base.group_extended"
            id="menu_project_phase"   parent="base.menu_project_long_term" sequence="1"/>

        <menuitem id="menu_resouce_allocation" action="act_resouce_allocation"
            icon="STOCK_INDENT"
            name="Resource Allocations" parent="base.menu_project_long_term" sequence="2"/>

        <menuitem id="menu_pm_resources_project1"
            groups="base.group_extended"
            name="Resources" parent="project.menu_definitions" sequence="3"/>

        <menuitem id="menu_phase_schedule" name="Scheduling" parent="base.menu_main_pm" sequence="4" groups="project.group_project_user,project.group_project_manager"/>
        <menuitem action="resource.action_resource_resource_tree" id="menu_view_resource" parent="menu_pm_resources_project1" sequence="2"/>
        <menuitem action="resource.action_resource_calendar_form" id="menu_view_resource_calendar" parent="menu_pm_resources_project1" sequence="1"/>
        <menuitem action="resource.action_resource_calendar_leave_tree" id="menu_view_resource_calendar_leaves" parent="menu_pm_resources_project1" sequence="1"/>

    </data>
</openerp>
