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

        <!-- Add section_id (Sales Team) to res.partner -->
        <record id="view_partners_form_crm1" model="ir.ui.view">
                <field name="name">view.res.partner.form.crm.inherited1</field>
                <field name="model">res.partner</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="base.view_partner_form"/>
                <field eval="18" name="priority"/>
                <field name="arch" type="xml">
                    <field name="user_id" position="after">
                        <field name="section_id" completion="1" widget="selection"
                            groups="base.group_extended"/>
                    </field>
                </field>
        </record>

        <record id="view_partners_tree_crm2" model="ir.ui.view">
                <field name="name">view.res.partner.tree.crm.inherited2</field>
                <field name="model">res.partner</field>
                <field name="type">tree</field>
                <field name="inherit_id" ref="base.view_partner_tree"/>
                <field eval="18" name="priority"/>
                <field name="arch" type="xml">
                    <field name="country" position="after">
                        <field name="section_id" completion="1" widget="selection"
                            groups="base.group_extended"/>
                    </field>
                </field>
        </record>

        <record id="view_partners_form_crm3" model="ir.ui.view">
                <field name="name">view.res.partner.search.crm.inherited3</field>
                <field name="model">res.partner</field>
                <field name="type">search</field>
                <field name="inherit_id" ref="base.view_res_partner_filter"/>
                <field eval="18" name="priority"/>
                <field name="arch" type="xml">
                    <field name="category_id" position="after">
                        <field name="section_id" completion="1" widget="selection"
                            groups="base.group_extended"/>
                    </field>
                </field>
        </record>

        <!-- Add History tabs to res.partner form -->
        <record id="view_crm_partner_info_form1" model="ir.ui.view">
            <field name="name">res.partner.crm.info.inherit1</field>
            <field name="model">res.partner</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <page string="History" position="inside">
                    <field name="opportunity_ids" colspan="4" nolabel="1" context="{'default_partner_id': active_id}">
                         <tree string="Leads and Opportunities"  colors="blue:state=='pending';gray:state=='cancel'">
                             <field name="create_date"/>
                             <field name="name"/>
                             <field name="type"/>
                             <field name="stage_id"/>
                             <button name="stage_previous" string="Previous"
                                 states="open,pending" type="object" icon="gtk-go-back" />
                             <button name="stage_next" string="Next"
                                 states="open,pending" type="object"
                                 icon="gtk-go-forward" />
                             <field name="user_id" />
                             <field name="state" />
                             <button name="case_cancel" string="Cancel"
                                 states="draft,open,pending" type="object"
                                 icon="gtk-cancel" />
                             <button name="case_open" string="Open"
                                 states="draft,pending" type="object"
                                 icon="gtk-go-forward" />
                             <button name="case_close" string="Close"
                                 states="open,draft,pending" type="object"
                                 icon="gtk-close" />
                             <button string="Convert to Opportunity"
                                 name="convert_opportunity"
                                 states="draft,open,pending" icon="gtk-index"
                                 type="object" attrs="{'invisible':[('type','=','opportunity')]}" />
                             <button name="case_escalate" string="Escalate"
                                 states="open,draft,pending" type="object"
                                 icon="gtk-go-up" />
                         </tree>
                    </field>
                    <field name="meeting_ids" colspan="4" nolabel="1"  context="{'default_partner_id': active_id}">
                        <tree string="Meetings" colors="gray:state in ('draft', 'cancel','done','pending')">
                            <field name="user_id" string="Responsible"/>
                            <field name="name" string="Subject" />
                            <field name="date" string="Start Date" />
                            <field name="date_deadline" string="End Date"/>
                        </tree>
                    </field>
                    <field name="phonecall_ids" colspan="4" nolabel="1" context="{'default_partner_id': active_id}">
                        <tree string="Phone Calls" colors="gray:state in ('draft', 'cancel','done','pending')">
                            <field name="date" string="Date"/>
                            <field name="name" string="Call Summary"/>
                            <field name="categ_id" widget="selection"/>
                            <field name="user_id"/>
                            <field name="state"/>
                            <button name="case_cancel" string="Cancel" states="draft,open,pending" type="object" icon="gtk-cancel"/>
                            <button name="case_open" string="Todo" states="draft,pending" type="object" icon="gtk-go-forward"/>
                            <button name="case_close" string="Held" states="open,draft,pending" type="object" icon="gtk-jump-to"/>
                            <button name="case_pending" string="Not Held" states="open" type="object" icon="gtk-media-pause"/>
                        </tree>
                    </field>
                </page>
            </field>
        </record>



    </data>
</openerp>

