<?xml version="1.0" ?>
<openerp>
    <data>
    <!-- budget form and tree view from account module *********************************** -->
        <record id="action_account_budget_post_tree" model="ir.actions.act_window">
            <field name="name">Budgets</field>
            <field name="res_model">account.budget.post</field>
            <field name="view_type">tree</field>
        </record>
        <menuitem action="action_account_budget_post_tree" id="menu_action_account_budget_post_tree" parent="account.menu_finance_generic_reporting" sequence="6"/>

        <!--
    Budgets
    -->
        <record id="view_budget_post_search" model="ir.ui.view">
            <field name="name">account.budget.post.search</field>
            <field name="model">account.budget.post</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Budgetary Position">
                    <field name="code"/>
                    <field name="name"/>
                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                </search>
            </field>
        </record>

        <record id="view_budget_post_tree" model="ir.ui.view">
            <field name="name">account.budget.post.tree</field>
            <field name="model">account.budget.post</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Budgetary Position">
                    <field name="code"/>
                    <field name="name"/>
                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                </tree>
            </field>
        </record>

        <record id="open_budget_post_form" model="ir.actions.act_window">
            <field name="name">Budgetary Positions</field>
            <field name="res_model">account.budget.post</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="view_budget_post_tree"/>
            <field name="search_view_id" ref="view_budget_post_search"/>
        </record>
        <menuitem id="next_id_31" name="Budgets" parent="account.menu_finance" sequence="6"/>
        <menuitem id="next_id_pos" name="Budgets" parent="account.menu_finance_configuration" sequence="20"/>
        <menuitem action="open_budget_post_form" id="menu_budget_post_form" parent="next_id_pos" sequence="20"/>


        <record model="ir.ui.view" id="view_budget_post_form">
            <field name="name">account.budget.post.form.inherit</field>
            <field name="model">account.budget.post</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Budgetary Position">
                    <field name="name" select="1"/>
                    <field name="code" select="1"/>
                    <field name="company_id"  groups="base.group_multi_company" widget="selection"/>
                    <notebook colspan="4">
                        <page string="Accounts">
                            <field name="account_ids" colspan="4" nolabel="1"/>
                        </page>
                        <page string="Budget Lines">
                            <field name="crossovered_budget_line" widget="one2many_list" colspan="4" nolabel="1" mode="graph,tree">
                                <graph type="bar" string="Lines">
                                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
                                    <field name="planned_amount" operator="+"/>
                                    <field group="True" name="general_budget_id"/>
                                </graph>
                                <tree string="Budget Lines"  editable="top">
                                    <field name="crossovered_budget_id"/>
                                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting" domain="[('parent_id','!=',False)]"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date"/>
                                    <field name="planned_amount" sum="Planned Amount"/>
                                    <field name="practical_amount" select="1" sum="Practical Amount" />
                                    <field name="theoritical_amount" sum="Theoretical Amount"/>
                                    <field name="percentage"/>
                                </tree>
                                <form string="Budget Lines">
                                    <field name="crossovered_budget_id"/>
                                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting" domain="[('parent_id','!=',False)]" />
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date"/>
                                    <field name="planned_amount"/>
                                    <field name="practical_amount" select="1"/>
                                    <field name="theoritical_amount"/>
                                    <field name="percentage"/>
                                </form>
                            </field>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="crossovered_budget_view_form">
            <field name="name">crossovered.budget.view.form</field>
            <field name="model">crossovered.budget</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Budget">
                            <field name="name" colspan="1" select="1" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="code" colspan="1" select="1" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="creating_user_id" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="validating_user_id" readonly="True" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="date_from" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="date_to" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                            <field name="crossovered_budget_line" colspan="4" nolabel="1" attrs="{'readonly':[('state','!=','draft')]}">
                                <tree string="Budget Lines">
                                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
                                    <field name="general_budget_id"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date"/>
                                    <field name="planned_amount" sum="Planned Amount"/>
                                    <field name="practical_amount" sum="Practical Amount"/>
                                    <field name="theoritical_amount" sum="Theoretical Amount"/>
                                    <field name="percentage"/>
                                </tree>
                                <form string="Budget Lines">
                                    <field name="analytic_account_id" select="1" groups="analytic.group_analytic_accounting"/>
                                    <field name="general_budget_id" select="1"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date" select="1"/>
                                    <field name="planned_amount" select="1"/>
                                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                                </form>
                            </field>
                            <field name="state" select="1"/>
                            <group col="4" colspan="2">
                                <button string="Cancel" name="cancel" states="confirm,validate" type="workflow" icon="gtk-cancel"/>
                                <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-apply" />
                                <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-ok"/>
                                <button string="Done" name="done" states="validate" type="workflow"   icon="gtk-jump-to" />
                                <button name="draft" states="cancel" string="Reset to Draft" type="workflow" icon="terp-stock_effects-object-colorize"/>
                            </group>

                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="crossovered_budget_view_tree">
            <field name="name">crossovered.budget.view.tree</field>
            <field name="model">crossovered.budget</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
               <tree colors="blue:state in ('draft');gray:state in ('done','cancel');black:state in ('confirm','validate')" string="Budget">
                    <field name="name" colspan="1"/>
                    <field name="code" colspan="1"/>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                    <field name="creating_user_id"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

        <record id="view_crossovered_budget_search" model="ir.ui.view">
           <field name="name">crossovered.budget.search</field>
           <field name="model">crossovered.budget</field>
           <field name="type">search</field>
           <field name="arch" type="xml">
               <search string="Budget">
                   <group col="20" colspan="4">
                       <filter string="Draft" icon="terp-document-new" domain="[('state','=','draft')]" help="Draft Budgets"/>
                       <filter string="To Approve" icon="terp-camera_test" domain="[('state','=','confirm')]" help="To Approve Budgets" />
                       <separator orientation="vertical"/>
                       <field name="name" select="1"/>
                       <field name="code" select="1" />
                       <field name="state"/>
                       <field name="date_from"/>
                       <field name="date_to"/>
                   </group>
               </search>
           </field>
        </record>

        <record model="ir.actions.act_window" id="act_crossovered_budget_view">
            <field name="name">Budgets</field>
            <field name="res_model">crossovered.budget</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="crossovered_budget_view_tree"/>
            <field name="search_view_id" ref="view_crossovered_budget_search"/>
            <field name="help">A budget is a forecast of your company's income and expenses expected for a period in the future. With a budget, a company is able to carefully look at how much money they are taking in during a given period, and figure out the best way to divide it among various categories. By keeping track of where your money goes, you may be less likely to overspend, and more likely to meet your financial goals. Forecast a budget by detailing the expected revenue per analytic account and monitor its evolution based on the actuals realised during that period.</field>
        </record>
        <menuitem parent="next_id_31"
            id="menu_act_crossovered_budget_view"
            action="act_crossovered_budget_view" sequence="1" />

        <record model="ir.ui.view" id="view_crossovered_budget_line_tree">
            <field name="name">crossovered.budget.line.tree</field>
            <field name="model">crossovered.budget.lines</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Budget Lines">
                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
                    <field name="general_budget_id"/>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="paid_date"/>
                    <field name="planned_amount"/>
                    <field name="practical_amount" select="1"/>
                    <field name="theoritical_amount"/>
                    <field name="percentage"/>
                </tree>
            </field>
        </record>
        <record model="ir.ui.view" id="view_crossovered_budget_line_form">
            <field name="name">crossovered.budget.line.form</field>
            <field name="model">crossovered.budget.lines</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Budget Lines">
                    <field name="crossovered_budget_id"/>
                    <field name="analytic_account_id" select="1" groups="analytic.group_analytic_accounting"/>
                    <field name="general_budget_id" select="1"/>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="paid_date" select="1"/>
                    <field name="planned_amount" select="1"/>
                    <field name="practical_amount" select="1"/>
                    <field name="theoritical_amount"/>
                    <field name="percentage"/>
                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="act_crossovered_budget_lines_view">
            <field name="name">Budget Lines</field>
            <field name="res_model">crossovered.budget.lines</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="view_crossovered_budget_line_tree"/>
        </record>

        <menuitem parent="menu_action_account_budget_post_tree"
            id="menu_act_crossovered_budget_lines_view"
            action="act_crossovered_budget_lines_view" />

        <!--  Shortcuts -->
        <act_window name="Budget Lines"
            context="{'search_default_analytic_account_id': [active_id], 'default_analytic_account_id': active_id}"
            res_model="crossovered.budget.lines"
            src_model="account.analytic.account"
            id="act_account_analytic_account_cb_lines"/>


        <record model="ir.ui.view" id="view_account_analytic_account_form_inherit_budget">
            <field name="name">account.analytic.account.form.inherot.budget</field>
            <field name="type">form</field>
            <field name="model">account.analytic.account</field>
            <field name="inherit_id" ref="account.view_account_analytic_account_form"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Budget Lines">
                            <field name="crossovered_budget_line" widget="one2many_list" colspan="4" nolabel="1" mode="tree,graph">
                                <tree string="Budget Lines" editable="top">
                                    <field name="crossovered_budget_id"/>
                                    <field name="general_budget_id"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date"/>
                                    <field name="planned_amount"/>
                                    <field name="practical_amount" sum="Practical Amount"/>
                                    <field name="theoritical_amount" sum="Theoritical Amount"/>
                                    <field name="percentage"/>
                                </tree>
                                <form string="Budget Lines">
                                    <field name="crossovered_budget_id"/>
                                    <field name="general_budget_id"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="paid_date"/>
                                    <field name="planned_amount"/>
                                </form>
                                <graph type="bar" string="Lines">
                                    <field name="general_budget_id" />
                                    <field name="planned_amount" operator="+"/>
                                    <field group="True" name="analytic_account_id"/>
                                </graph>
                            </field>
                    </page>
                </notebook>
            </field>
        </record>

    </data>
</openerp>


