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

        <!-- Planning -->
        <record id="account_analytic_planning_view_tree" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.tree</field>
            <field name="model">report_account_analytic.planning</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Planning">
                    <field name="name" />
                    <field name="user_id" />
                    <field name="date_from" />
                    <field name="date_to" />
                    <field name="business_days" />
                    <field name="total_planned" />
                    <field name="total_free" />
                    <field name="state" />
                </tree>
            </field>
        </record>

        <record id="account_analytic_planning_view_form" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.form</field>
            <field name="model">report_account_analytic.planning</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Planning by Account">
                    <group col="6" colspan="4">
                        <field name="name" select="1" />
                        <field name="code" select="1" />
                        <field name="user_id" select="1" />
                        <field name="business_days" />
                        <field name="date_from" />
                        <field name="date_to" />
                    </group>
                    <notebook colspan="4">
                        <page string="Planning by User">
                        <field colspan="4" name="planning_user_ids"
                                nolabel="1" widget="one2many_list" readonly="1">
                            <tree string="Planning By User (in Days)">
                                <field name="user_id"/>
                                <field name="tasks" sum="Total Remaining Tasks"/>
                                <field name="plan_tasks" sum="Total Time Allocation of Tasks"/>
                                <field name="plan_open" sum="Total Time Allocation without Tasks"/>
                                <field name="holiday" />
                                <field name="free" sum="Total Unallocated Time"/>
                                <field name="timesheet"/>
                            </tree>
                        </field>
                        </page>
                        <page string="Planning by Account">
                        <field colspan="4" name="planning_account"
                                nolabel="1" widget="one2many_list" readonly="1">
                            <tree string="Planning By Account (in Days)">
                                <field name="account_id" groups="base.group_extended"/>
                                <field name="tasks" sum="Total Remaining Tasks"/>
                                <field name="plan_tasks" sum="Total Time Allocation of Tasks"/>
                                <field name="plan_open" sum="Total Time Allocation without Tasks"/>
                                <field name="timesheet" />
                            </tree>
                        </field>
                        </page>
                        <page string="Time Encoding">
                            <field colspan="4" name="line_ids"
                                nolabel="1">
                                <tree editable="bottom"
                                    string="Planning Lines">
                                    <field name="user_id"/>
                                    <field name="account_id" groups="base.group_extended"/>
                                    <field name="amount" />
                                    <field name="amount_unit" />
                                    <field name="task_ids" />
                                    <field name="note" />
                                    <field name="amount_in_base_uom" invisible="1" sum="Total Planned (in Days)"/>

                                </tree>
                                <form string="Planning Lines">
                                    <field name="user_id" domain="[('id','child_of',[parent.user_id])]"/>
                                    <field name="account_id" groups="base.group_extended"/>
                                    <field name="amount" />
                                    <field name="amount_unit" />
                                       <field name="task_ids" colspan="4" nolabel="1" mode="tree,form">
                                        <form string="Tasks">
                                            <group colspan="4" col="2">
                                                <field name="name" select="1"/>
                                                <field name="project_id" required="1" select="1" domain="[('analytic_account_id','=',parent.account_id)]"/>
                                            </group>
                                            <group colspan="4" col="4">
                                                <field name="date_deadline"/>
                                                <field name="user_id" select="1"  domain="[('id','=',parent.user_id)]"/>
                                            </group>
                                            <notebook colspan="4">
                                                <page string="Information">
                                                    <group col="3" colspan="4">
                                                        <field name="effective_hours" widget="float_time" invisible="True" />
                                                        <field name="planned_hours"
                                                            widget="float_time"
                                                            attrs="{'readonly':[('state','!=','draft')]}"
                                                            on_change="onchange_planned(planned_hours,effective_hours)"/>
                                                        <field name="remaining_hours" widget="float_time" attrs="{'readonly':[('state','!=','draft')]}"/>
                                                    </group>
                                                    <field colspan="4" name="description" nolabel="1"  attrs="{'readonly':[('state','=','done')]}" widget="text_wiki"/>
                                                    <group col="11" colspan="4">
                                                        <field name="state" select="1"/>
                                                        <button name="do_draft" states="open" string="Draft" type="object" icon="gtk-indent"/>
                                                        <button name="do_open" states="pending,draft" string="Start Task" type="object" icon="gtk-execute"/>
                                                        <button name="do_reopen" states="done,cancelled" string="Reactivate" type="object" icon="gtk-convert"/>
                                                        <button name="do_pending" states="open" string="Pending" type="object" icon="gtk-media-pause"/>
                                                        <button groups="base.group_extended" name="%(project.action_project_task_delegate)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
                                                        <button name="%(project.action_project_task_close)d" states="pending,open" string="Done" type="action" icon="gtk-jump-to"/>
                                                        <button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel"/>

                                                    </group>
                                                 </page>
                                                <page groups="base.group_extended" string="Extra Info" attrs="{'readonly':[('state','=','done')]}">
                                                    <group colspan="2" col="2">
                                                        <field name="priority"/>
                                                        <field name="sequence"/>
                                                    </group>
                                                <separator string="Miscelleanous" colspan="4"/>
                                                    <field name="type_id"/>
                                                    <field name="active"/>
                                                    <field name="partner_id"/>
                                                    <separator colspan="4" string="Notes"/>
                                                    <field colspan="4" name="notes" nolabel="1"/>
                                                </page>
                                            </notebook>
                                        </form>
                                    </field>
                                    <separator string="Notes" colspan="4" />
                                    <field name="note" colspan="4"
                                        nolabel="1" />
                                </form>
                            </field>
                        </page>
                    </notebook>
                    <group col="6" colspan="4">
                        <field name="state" select="1"
                            readonly="1" />
                        <button name="action_open" states="draft"
                            string="Open" type="object" icon="gtk-yes" />
                        <button name="action_done" states="open"
                            string="Done" type="object" icon="gtk-jump-to" />
                        <button name="action_cancel" states="draft,open"
                            string="Cancel" type="object" icon="gtk-cancel" />
                        <button name="action_draft" states="done,cancel"
                            string="Reset to Draft" type="object" icon="gtk-convert" />
                    </group>
                </form>
            </field>
        </record>

        <record id="account_analytic_planning_view_search" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.search</field>
            <field name="model">report_account_analytic.planning</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Planning by Account">
                    <group col="8" colspan="4">
                        <filter icon="terp-check" string="Current Plannings" domain="[('date_from','&lt;=',time.strftime('%%Y-%%m-%%d')),('date_to','&gt;=',time.strftime('%%Y-%%m-%%d'))]" help="Current Plannings"/>
                        <separator orientation="vertical"/>
                        <field name="name"/>
                        <field name="code"/>
                        <field name="user_id"/>
                        <field name="state"/>
                    </group>
                </search>
            </field>
        </record>

        <!-- Planning Line -->

        <record id="account_analytic_planning_line_view_tree" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.line.tree</field>
            <field name="model">report_account_analytic.planning.line</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Planning Line">
                    <field name="planning_id"/>
                    <field name="user_id"/>
                    <field name="account_id" groups="base.group_extended"/>
                    <field name="amount" />
                    <field name="amount_unit" />
                    <field name="note" select="1"/>
                    <field name="amount_in_base_uom" invisible="1" sum="Total Planned (in Days)"/>
                </tree>
            </field>
        </record>

        <record id="account_analytic_planning_line_view_form" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.line.form</field>
            <field name="model">report_account_analytic.planning.line</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Planning Line">
                    <field name="planning_id" select="1"/>
                    <field name="user_id" select="1"/>
                    <field name="account_id" select="1" groups="base.group_extended"/>
                    <field name="amount" />
                    <field name="amount_unit" />
                    <separator string="Notes" colspan="4" />
                    <field name="note" colspan="4" nolabel="1" />
                </form>
            </field>
        </record>

        <record id="action_account_analytic_planning_form" model="ir.actions.act_window">
            <field name="name">Plannings</field>
            <field name="res_model">report_account_analytic.planning</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{"search_default_user_id":uid}</field>
            <field name="search_view_id" ref="account_analytic_planning_view_search"/>
            <field name="help">With its commun system for scheduling all resources of a company (people and materials), OpenERP allows you to encode then compute automatically tasks and phases scheduling, track resources allocation and availibility.</field>
        </record>
<!--        <menuitem id="base.menu_pm_planning" name="Planning" parent="base.menu_main_pm" sequence="5"/>-->
        <menuitem id="base.menu_project_long_term" name="Long Term Planning"
            parent="base.menu_main_pm" />

        <menuitem action="action_account_analytic_planning_form"
            id="menu_report_account_analytic_planning" parent="base.menu_project_long_term" sequence="3" groups="project.group_project_user,project.group_project_manager,base.group_system"/>

        <!--
            Planning statistics
        -->
        <record id="account_analytic_planning_stat_view_form" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.stat.form</field>
            <field name="model">report_account_analytic.planning.stat</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Planning statistics">
                    <field name="planning_id" select="1" />
                    <field name="user_id" select="1" />
                    <field name="account_id" select="1" groups="base.group_extended"/>
                </form>
            </field>
        </record>


        <record id="account_analytic_planning_stat_view_tree" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.stat.tree</field>
            <field name="model">report_account_analytic.planning.stat</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Planning statistics">
                    <field name="planning_id" />
                    <field name="user_id" />
                    <field name="manager_id" />
                    <field name="account_id" groups="base.group_extended"/>
                    <field name="sum_amount" />
                    <field name="sum_amount_real" />
                    <field name="sum_amount_tasks" />
                </tree>
            </field>
        </record>

        <record id="account_analytic_planning_stat_view_graph" model="ir.ui.view">
            <field name="name">report.account.analytic.planning.stat.graph</field>
            <field name="model">report_account_analytic.planning.stat</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Planning statistics" type="bar">
                    <field name="account_id"/>
                    <field name="sum_amount" operator="+" />
                    <field name="sum_amount_real" operator="+" />
                    <field name="sum_amount_tasks" operator="+" />
                </graph>
            </field>
        </record>

        <record id="account_analytic_planning_stat_view_search" model="ir.ui.view">
            <field name="name">report_account_analytic.planning.stat.search</field>
            <field name="model">report_account_analytic.planning.stat</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Planning statistics">
                    <group col="10" colspan="4">
                        <filter icon="gtk-execute" string="My" domain="[('user_id','=',uid),('planning_id.state','&lt;&gt;','cancel')]" help="My Plannings Statistics"/>
                        <filter icon="gtk-execute" string="My Project" domain="[('manager_id','=',uid),('planning_id.state','&lt;&gt;','cancel')]" help="Planning Statistics of My Projects"/>
                        <separator orientation="vertical"/>
                        <field name="planning_id" select="1"/>
                        <field name="user_id" select="1"/>
                        <field name="account_id" select="1" groups="base.group_extended"/>
                    </group>
                </search>
            </field>
        </record>


        <record id="action_account_analytic_planning_stat_form" model="ir.actions.act_window">
            <field name="name">Planning Statistics</field>
            <field name="res_model">report_account_analytic.planning.stat</field>
            <field name="view_type">form</field>
            <field name="view_mode">graph,tree</field>
            <field name="search_view_id" ref="account_analytic_planning_stat_view_search"/>
        </record>
        <menuitem id="next_id_85" name="Planning"
            parent="hr.menu_hr_reporting" />
        <menuitem action="action_account_analytic_planning_stat_form"
            id="menu_report_account_analytic_planning_stat" parent="next_id_85" />

<!--        Analytic account Form -->

        <record id="view_project_planning_form" model="ir.ui.view">
            <field name="name">planning.account.analytic.account.form</field>
            <field name="model">account.analytic.account</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="account.view_account_analytic_account_form"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Planning" >
                        <separator string="Planning lines"/>
                        <field name="planning_ids" colspan="4" nolabel="1">
                            <form string="Planning Lines">
                                <field name="planning_id" select="1"/>
                                <field name="user_id"/>
                                <field name="amount" />
                                <field name="amount_unit" />
                                <separator string="Notes" colspan="4" />
                                <field name="note" colspan="4" nolabel="1" />
                            </form>
                            <tree editable="bottom"
                                    string="Planning Lines">
                                    <field name="user_id"/>
                                    <field name="account_id" groups="base.group_extended"/>
                                    <field name="amount" />
                                    <field name="amount_unit" />
                                    <field name="task_ids" />
                                    <field name="note" />
                                    <field name="amount_in_base_uom" invisible="1" sum="Total Planned (in Days)"/>
                                </tree>
                        </field>
                    </page>
                </notebook>
            </field>
        </record>


<!--        Task Form -->

        <record id="view_task_planning_form" model="ir.ui.view">
            <field name="name">planning.task.form</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="priority" position="before">
                    <field name="planning_line_id" domain="['|', ('user_id','=',user_id), ('user_id','=', False)]"/>
                </field>
            </field>
        </record>

<!--Added link to open the list of all tasks planned on all lines of this planning.-->
        <act_window context="{'planning': active_id}"
            id="act_task_of_lines" name="Tasks" res_model="project.task"
            src_model="report_account_analytic.planning"
        />

        <!-- company form -->
        <record id="planning_company" model="ir.ui.view">
            <field name="name">res.company.planning.config</field>
            <field name="model">res.company</field>
            <field name="type">form</field>
            <field name="priority">25</field>
            <field name="inherit_id" ref="base.view_company_form"/>
            <field name="arch" type="xml">
                <field name="project_time_mode_id" position="after">
                <field name="planning_time_mode_id"/>
            </field>
            </field>
        </record>

    </data>
</openerp>
