<?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="phase_id" date_start="phase_id_date_start" date_stop="phase_id_date_end" string="R.A." mode="year">
               <level object="project.resource" link="resource_id" domain="[]">
                   <field name="useability"/>
                </level>
              </gantt>
            </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">
                    <field name="resource_id" select="1"/>
                    <field name="phase_id"/>
                    <field name="useability" string="Availability"/>
                </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="useability"/>
                </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="Resource Allocations">
                    <group colspan="4" col="20">
                        <field name="resource_id"/>
                        <field name="phase_id"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20">
                        <filter name="resource" string="Resource" icon="terp-folder-blue" domain="[]" context="{'group_by':'resource_id'}"/>
                        <separator orientation="vertical"/>
                        <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">Resource Allocations</field>
            <field name="res_model">project.resource.allocation</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form,gantt</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="2" col="2">
	                        <field name="name" select="1"/>
	                        <field name="date_start"/>
	                    </group>
	                    <group colspan="2" col="4">
	                       <field name="project_id" on_change="onchange_project(project_id)" colspan="4"/>
                           <newline/>
	                       <field name="duration" colspan="1"/>
                           <field name="product_uom" nolabel="1" domain="[('category_id.name', '=', 'Working Time')]"/>
	                    </group>
	                    <group colspan="2" col="2">
	                       <field name="responsible_id"/>
	                       <field name="date_end"/>
                    	</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="useability"/>
                                  </tree>
                                  <form string="Project Resource Allocation">
                                    <field name="resource_id" context="{'project_id':parent.project_id}"/>
                                    <field name="useability"/>
                                  </form>
                             </field>
                            <separator string="" colspan="4"/>
                            <group col="12" colspan="4">
                                <field name="state" select="1"/>
                                <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"/>
                                <button string="Cancel" name="set_cancel" states="draft,open,pending" icon="gtk-cancel"/>
                            </group>
                        </page>
                        <page string="Task Detail">
                            <field colspan="4" name="task_ids" context="{'default_project_id' :project_id}" nolabel="1">
                                 <tree editable="bottom" string="Project's Tasks">
                                    <field name="name"/>
                                    <field name="user_id"/>
                                    <field name="planned_hours" widget="float_time"/>
                                    <field name="project_id" invisible="1"/>
                                  </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"/>
                                            </group>
                                            <group colspan="2" col="2">
                                                  <separator string="Dates" colspan="2"/>
                                                  <field name="date_start"/>
                                                  <field name="date_deadline"/>
                                            </group>
                                            <group colspan="2" col="2">
                                                  <separator string="Planning" colspan="2"/>
                                                  <field name="planned_hours" widget="float_time"/>
                                                <field name="remaining_hours" widget="float_time" sum="Remaining Hours"/>
                                                <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="Other 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="Scheduling" colspan="2"/>
                                <field name="sequence"/>
                            </group>
                           <separator colspan="4" string="Previous Phases"/>
                           <field colspan="4" name="previous_phase_ids" nolabel="1"/>
                           <separator colspan="4" string="Next Phases"/>
                           <field colspan="4" name="next_phase_ids" nolabel="1"/>
                        </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="state"/>
                </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="responsible_id" date_start="date_start" date_stop="date_end" day_length="12" string="Phases">
                    <field name="name"/>
                    <field name="project_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="responsible_id" date_stop="date_end" date_start="date_start" string="Phases">
                    <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="Draft" domain="[('state','=','draft')]" help="Draft Phases" icon="terp-document-new" default="1"/>
                        <filter string="In Progress" name="Progress" domain="[('state','=','open')]" help="Open 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-personal"/>
                        </field>
                        <field name="responsible_id"/>
                        <field name="date_start"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20" groups="base.group_extended">
                        <filter string="User" icon="terp-personal" domain="[]" context="{'group_by':'responsible_id'}"/>
                        <separator orientation="vertical"/>
                        <filter string="Project" icon="terp-folder-blue" 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">tree,form,gantt,calendar</field>
            <field name="context">{'search_default_responsible_id':uid}</field>
            <field name="search_view_id" ref="view_project_phase_search"/>
            <field name="help">You can subdivide your larger projects into several phases. For each phase, you can define your resources allocation (humans or engine), describe de differend task and link your phase with previous and next one, add constraints date and scheduling. A gantt view of your project phase is also available from this menu. Gantt view is a graphically draw of the project plan; it includes any task dependencies by visually adjusting task durations and priorities, and by linking tasks to each other.</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_responsible_id':uid}</field>
            <field name="search_view_id" ref="view_project_phase_search"/>
        </record>


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

        <record id="view_phase_project_form1" model="ir.ui.view">
            <field name="name">phase.project.form1</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="priority" position="before">
                    <field name="resource_calendar_id"/>
                </field>

            </field>
       </record>

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

    <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]}"/>

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

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

        <menuitem action="act_project_phase"
            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"
            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_project_long_term" sequence="4" groups="project.group_project_user,project.group_project_manager,base.group_system"/>
        <menuitem action="resource.action_resource_resource_tree" id="menu_view_resource" parent="project.menu_project_management" sequence="4"/>
        <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>
