<?xml version="1.0"?>
<openerp>
<data>

<!-- Add plan_id after user_id in account.journal many2one with account.analytic.plan -->

    <record model="ir.ui.view" id="view_account_journal_form_inherit">
        <field name="name">account.journal.form.inherit</field>
        <field name="model">account.journal</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="account.view_account_journal_form"/>
        <field name="arch" type="xml">
            <field name="centralisation" position="before">
                <field name="plan_id" />
            </field>
        </field>
    </record>


    <record model="ir.ui.view" id="view_account_move_form_inherit">
        <field name="name">account.move.form.inherit</field>
        <field name="model">account.move</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="arch" type="xml">
            <field name="analytic_account_id" position="replace">
                <field name="analytics_id" />
            </field>
        </field>
    </record>

    <record id="account.journal_col11" model="account.journal.column">
        <field eval="&quot;&quot;&quot;Analytic Distribution&quot;&quot;&quot;" name="name"/>
        <field eval="11" name="sequence"/>
        <field name="view_id" ref="account.account_journal_view"/>
        <field eval="0" name="required"/>
        <field eval="&quot;&quot;&quot;analytics_id&quot;&quot;&quot;" name="field"/>
        <field eval="0" name="readonly"/>
    </record>

    <record model="ir.ui.view" id="view_move_line_form_inherit">
        <field name="name">account.move.line.form.inherit</field>
        <field name="model">account.move.line</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="account.view_move_line_form"/>
        <field name="arch" type="xml">
            <field name="move_id" position="after">
                <field name="analytics_id" />
            </field>
        </field>
    </record>


<!-- Replace analytic_id with analytics_id in account.invoice.line -->

    <record model="ir.ui.view" id="view_invoice_line_form_inherit">
        <field name="name">account.invoice.line.form.inherit</field>
        <field name="model">account.invoice.line</field>
        <field name="inherit_id" ref="account.view_invoice_line_form"/>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <field name="account_analytic_id" position="replace">
                <field name="analytics_id" context="{'journal_id':parent.journal_id}" domain="[('plan_id','&lt;&gt;',False)]"/>
            </field>
        </field>
    </record>

    <record model="ir.ui.view" id="invoice_supplier_form_inherit">
        <field name="name">account.invoice.supplier.form.inherit</field>
        <field name="model">account.invoice</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="account.invoice_supplier_form"/>
        <field name="priority">2</field>
        <field name="arch" type="xml">
            <field name="account_analytic_id" position="replace">
                <field name="analytics_id" domain="[('plan_id','&lt;&gt;',False)]" context="{'journal_id':parent.journal_id}" />
            </field>
        </field>
    </record>

    <!-- views for account.analytic.plan.instance -->
    <record model="ir.ui.view" id="account_analytic_plan_instance_form">
        <field name="name">account.analytic.plan.instance.form</field>
        <field name="model">account.analytic.plan.instance</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Analytic Distribution">
                <field name="name" select="1"/>
                <field name="code" select="1"/>
                <field name="plan_id" select="2" required="True"/>
                <field name="journal_id" select="2"/>
                <field name="account_ids" string="Analytic Distribution" colspan="4">
                    <tree string="Analytic Distribution" editable="bottom">
                        <field name="rate"/>
                        <field name="analytic_account_id"/>
                    </tree>
                </field>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="account_analytic_plan_instance_tree">
        <field name="name">account.analytic.plan.instance.tree</field>
        <field name="model">account.analytic.plan.instance</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Analytic Distribution">
                <field name="name" select="1"/>
                <field name="code" select="1"/>
                <field name="plan_id" select="2"/>
                <field name="journal_id" select="2"/>
            </tree>
        </field>
    </record>

    <record model="ir.actions.act_window" id="account_analytic_plan_instance_action">
        <field name="name">Analytic Distribution's Models</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">account.analytic.plan.instance</field>
        <field name="domain">[('plan_id','&lt;&gt;',False)]</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <act_window name="Distribution Models"
        domain="[('plan_id', '=', active_id),('plan_id','&lt;&gt;',False)]"
        context="{'plan_id': active_id}"
        res_model="account.analytic.plan.instance"
        src_model="account.analytic.plan"
        id="account_analytic_instance_model_open"/>

    <menuitem
        name="Analytic Distribution's models" parent="account.account_def_analytic_journal"
        id="menu_account_analytic_plan_instance_action"
        action="account_analytic_plan_instance_action"/>

    <record model="ir.ui.view" id="account_analytic_plan_instance_line_form">
        <field name="name">account.analytic.plan.instance.line.form</field>
        <field name="model">account.analytic.plan.instance.line</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Analytic Distribution Line">
                <field name="plan_id"/>
                <field name="analytic_account_id"/>
                <field name="rate"/>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="account_analytic_plan_instance_line_tree">
        <field name="name">account.analytic.plan.instance.line.tree</field>
        <field name="model">account.analytic.plan.instance.line</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Analytic Distribution Lines">
                <field name="plan_id" select="1"/>
                <field name="analytic_account_id" select="1"/>
                <field name="rate"/>
            </tree>
        </field>
    </record>

    <record model="ir.ui.view" id="account_analytic_plan_form">
        <field name="name">account.analytic.plan.form</field>
        <field name="model">account.analytic.plan</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Analytic Plan">
                <field name="name" select="1"/>
                <field name="default_instance_id"/>
                <field name="plan_ids" colspan="4"/>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="account_analytic_plan_tree">
        <field name="name">account.analytic.plan.tree</field>
        <field name="model">account.analytic.plan</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Analytic Plans">
                <field name="name"/>
            </tree>
        </field>
    </record>


    <record model="ir.actions.act_window" id="account_analytic_plan_form_action">
        <field name="name">Analytic Plan</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">account.analytic.plan</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem
        parent="account.account_analytic_def_account"
        id="menu_account_analytic_plan_action"
        action="account_analytic_plan_form_action"/>

    <record model="ir.ui.view" id="account_analytic_plan_line_form">
        <field name="name">account.analytic.plan.line.form</field>
        <field name="model">account.analytic.plan.line</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Analytic Plan Line">
                <field name="name"/>
                <field name="sequence"/>
                <field name="root_analytic_id"/>
                <newline/>
                <field name="min_required"/>
                <field name="max_required"/>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="account_analytic_plan_line_tree">
        <field name="name">account.analytic.plan.line.tree</field>
        <field name="model">account.analytic.plan.line</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Analytic Plan Lines">
                <field name="name" select="1"/>
                <field name="sequence"/>
                <field name="root_analytic_id" select="2"/>
                <field name="min_required"/>
                <field name="max_required"/>
            </tree>
        </field>
    </record>

    <!-- add property field on product -->

        <record model="ir.ui.view" id="view_default_inherit_form">
            <field name="name">account.analytic.default.form.plans</field>
            <field name="type">form</field>
            <field name="model">account.analytic.default</field>
            <field name="inherit_id" ref="account_analytic_default.view_account_analytic_default_form"/>
            <field name="arch" type="xml">
                <field name="analytic_id" select="1" required="1" position="replace">
                    <field name="analytics_id" select="1" required="1"/>
                </field>
            </field>
        </record>
         <record model="ir.ui.view" id="view_default_inherit_tree">
            <field name="name">account.analytic.default.tree.plans</field>
            <field name="type">tree</field>
            <field name="model">account.analytic.default</field>
            <field name="inherit_id" ref="account_analytic_default.view_account_analytic_default_tree"/>
            <field name="arch" type="xml">
                <field name="analytic_id" select="1" required="1" position="replace">
                    <field name="analytics_id" select="1" required="1"/>
                </field>
            </field>
        </record>

</data>
</openerp>
