<?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="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"/>
                    </field>
                </field>
        </record>

        <!-- open meetings related to given partner -->
        <record id="crm_meeting_partner" model="ir.actions.act_window">
            <field name="name">Meetings</field>
            <field name="src_model">res.partner</field>
            <field name="res_model">crm.meeting</field>
            <field name="view_mode">calendar,tree,form,gantt</field>
            <field name="context">{'default_partner_ids': [active_id]}</field>
        </record>

        <!-- open opportunities related to given partner -->
        <record model="ir.actions.act_window" id="relate_partner_opportunities">
            <field name="name">Opportunities</field>
            <field name="res_model">crm.lead</field>
            <field name="view_mode">kanban,tree,form,graph,calendar</field>
            <field name="domain">[('type','=','opportunity')]</field>
            <field name="context">{'search_default_partner_id': active_id,
                'stage_type': 'opportunity', 'default_type': 'opportunity'}</field>
            <field name="view_id" eval="False"/>
            <field name="search_view_id" ref="crm.view_crm_case_opportunities_filter"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create an opportunity related to this customer.
              </p><p>
                Use opportunities to keep track of your sales pipeline, follow
                up potential sales and better forecast your future revenues.
              </p><p>
                You will be able to plan meetings and phone calls from
                opportunities, convert them into quotations, attach related
                documents, track all discussions, and much more.
              </p>
            </field>
        </record>
        <record model="ir.actions.act_window.view" id="relate_partner_opportunities_kanban">
            <field name="sequence" eval="0"/>
            <field name="view_mode">kanban</field>
            <field name="view_id" ref="crm_case_kanban_view_leads"/>
            <field name="act_window_id" ref="relate_partner_opportunities"/>
        </record>
        <record model="ir.actions.act_window.view" id="relate_partner_opportunities_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="crm_case_tree_view_oppor"/>
            <field name="act_window_id" ref="relate_partner_opportunities"/>
        </record>
        <record model="ir.actions.act_window.view" id="relate_partner_opportunities_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="crm_case_form_view_oppor"/>
            <field name="act_window_id" ref="relate_partner_opportunities"/>
        </record>

        <!-- Partner kanban view inherte -->
        <record model="ir.ui.view" id="crm_lead_partner_kanban_view">
            <field name="name">res.partner.kanban.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.res_partner_kanban_view"/>
            <field name="priority" eval="10"/>
            <field name="arch" type="xml">
                <field name="mobile" position="after">
                    <field name="opportunity_count"/>
                    <field name="meeting_count"/>
                </field>
                <xpath expr="//div[@class='oe_kanban_partner_links']" position="inside">
                    <a name="%(relate_partner_opportunities)d" type="action" t-if="record.opportunity_count.value>0">
                        <t t-esc="record.opportunity_count.value"/> Opportunities
                    </a>
                    <a name="%(crm_meeting_partner)d" type="action" t-if="record.meeting_count.value>0">
                        <t t-esc="record.meeting_count.value"/> Meetings
                    </a>
                </xpath>
            </field>
        </record>


        <record model="ir.ui.view" id="res_partner_view_buttons">
            <field name="name">res.partner.view.buttons</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="priority" eval="10"/>
            <field name="arch" type="xml">
                <xpath expr="//div[@name='buttons']" position="inside">
                    <button type="action"
                        string="Meetings"
                        name="%(base_calendar.action_crm_meeting)d"
                        context="{'search_default_partner_ids': active_id, 'default_partner_ids' : [active_id]}"/>
                    <button type="action" string="Calls" 
                        name="%(crm.crm_case_categ_phone_incoming0)d" 
                        context="{'search_default_partner_id': active_id, 'default_duration': 1.0}" />
                    <button type="action" string="Opportunities" attrs="{'invisible': [('customer', '=', False)]}"
                        name="%(crm.crm_case_category_act_oppor11)d" context="{'search_default_partner_id': active_id}"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>

