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

    <!-- Stage Search view -->
    <record id="crm_lead_stage_search" model="ir.ui.view">
        <field name="name">Stage - Search</field>
        <field name="model">crm.case.stage</field>
        <field name="type">search</field>
        <field name="arch" type="xml">
            <search string="Stage Search">
                <field name="name"/>
            </search>
        </field>
    </record>

    <!--Lead Stage Form view -->
    <record id="crm_lead_stage_act" model="ir.actions.act_window">
        <field name="name">Stages</field>
        <field name="res_model">crm.case.stage</field>
        <field name="view_type">form</field>
        <field name="view_id" ref="crm.crm_case_stage_tree"/>
        <field name="help">Add specific stages to leads and opportunities allowing your sales to better organise their sales pipeline. Stages will allow them to easily track how a specific lead or opportunity is positioned in the sales cycle.</field>
    </record>

     <menuitem action="crm_lead_stage_act" id="menu_crm_lead_stage_act" name="Stages"
        groups="base.group_extended" sequence="0"
        parent="base.menu_crm_config_lead" />


        <!-- Lead/Opportunity Categories Action -->

        <record id="crm_lead_categ_action" model="ir.actions.act_window">
            <field name="name">Categories</field>
            <field name="res_model">crm.case.categ</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="crm_case_categ_tree-view"/>
            <field name="context">{'object_id': 'crm.lead'}</field>
            <field name="domain">[('object_id.model', '=', 'crm.lead')]</field>
            <field name="help">Create specific categories that fit your company's activities to better classify and analyse your leads and opportunities. Such categories could for instance reflect your product structure or the different types of sales you do.</field>
        </record>

        <menuitem action="crm_lead_categ_action"
            id="menu_crm_lead_categ" name="Categories"
            parent="base.menu_crm_config_lead" sequence="1"/>


        <!-- CRM Lead Form View  -->
        <record model="ir.ui.view" id="crm_case_form_view_leads">
        <field name="name">CRM - Leads Form</field>
        <field name="model">crm.lead</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Leads Form">
                <group colspan="4" col="7">
                    <field name="name" required="1" string="Subject"/>
                    <field name="priority"/>
                    <field name="categ_id"
                        widget="selection"
                        domain="[('object_id.model','=','crm.lead')]"/>
                    <button
                         name="convert_opportunity"
                         string="Convert to Opportunity"
                         help="Convert to Opportunity" icon="gtk-go-forward"
                         type="object"/>
                    <newline />
                    <field name="user_id" />
                    <field name="section_id" widget="selection" />
                    <field name="stage_id" domain="[('section_ids', '=', section_id)]" />
                    <group col="2" colspan="1">
                        <button name="stage_previous" string=""
                            states="open,pending,draft" type="object"
                            icon="gtk-go-back" context="{'stage_type': 'lead'}" />
                        <button name="stage_next" string=""
                            states="open,pending,draft" type="object"
                            icon="gtk-go-forward" context="{'stage_type': 'lead'}" />
                    </group>
                    <field name="type" invisible="1"/>
                </group>
                <notebook colspan="4">
                <page string="Lead">
                    <group colspan="4" col="2">
                        <field name="partner_name" string="Partner Name" />
                    </group>
                    <group colspan="2" col="4">
                        <separator string="Contact" colspan="4" col="4"/>
                        <field name="contact_name" colspan="4"/>
                        <newline/>
                        <field domain="[('domain', '=', 'contact')]" name="title" widget="selection"/>
                        <field name="function" />
                        <field name="street" colspan="4"/>
                        <field name="street2" colspan="4"/>
                        <field name="zip"/>
                        <field name="city"/>
                        <field name="country_id"/>
                        <field name="state_id"/>
                    </group>
                    <group colspan="2" col="3">
                        <separator string="Communication" colspan="4" col="3"/>
                        <field name="email_from" widget="email"/><button string="Mail"
                        name="%(crm.action_crm_send_mail)d"
                        context="{'mail':'new', 'model': 'crm.lead'}"
                        icon="terp-mail-message-new" type="action" colspan="1"/>
                        <newline/>
                        <field name="phone"/>
                        <newline/>
                        <field name="fax"/>
                        <newline/>
                        <field name="mobile"/>
                        <newline/>
                        <separator string="Links" colspan="4" col="3"/>
                        <field name="partner_id" string="Customer"/>
                        <button
                            name="%(action_crm_lead2partner)d"
                            icon="terp-partner" type="action"
                            string="Create"
                            attrs="{'invisible':[('partner_id','!=',False)]}"/>
                    </group>
                    <separator colspan="4" string="Notes"/>
                    <field name="description" nolabel="1" colspan="4"/>
                    <separator colspan="4"/>
                    <group col="8" colspan="4">
                        <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_mark_lost" string="Close"
                            states="open,pending" type="object"
                            icon="gtk-close" />
                        <button name="case_pending" string="Pending"
                            states="open" type="object"
                            icon="gtk-media-pause" />
                        <button name="case_escalate" string="Escalate"
                            states="open,pending" type="object"
                            groups="base.group_extended"
                            icon="gtk-go-up" />
                        <button name="case_reset"
                            string="Reset to Draft" states="done,cancel"
                            type="object" icon="gtk-convert" />
                    </group>
                 </page>
                 <page string="Extra Info" groups="base.group_extended">
                    <group colspan="2" col="2">
                        <separator string="Categorization" colspan="2" col="2"/>
                        <field name="company_id"
                            groups="base.group_multi_company"
                            widget="selection" colspan="2" />
                        <field name="type_id" select="1" widget="selection"/>
                        <field name="channel_id" select="1" widget="selection"/>
                        <field name="referred"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Dates" colspan="2" col="2"/>
                        <field name="create_date"/>
                        <field name="write_date"/>
                        <field name="date_open"/>
                        <field name="date_closed"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Mailings" colspan="2" col="2"/>
                        <field name="optin" on_change="on_change_optin(optin)"/>
                        <field name="optout" on_change="on_change_optout(optout)"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Statistics" colspan="2" col="2"/>
                        <field name="day_open"/>
                        <field name="day_close"/>
                    </group>
                 </page>
                 <page string="Communication &amp; History" groups="base.group_extended">
                   <group colspan="4">
                       <field colspan="4" name="email_cc" widget="char" size="512"/>
                   </group>
                    <field name="message_ids" colspan="4" nolabel="1" mode="tree,form">
                        <tree string="History">
                            <field name="display_text" string="History Information"/>
                            <field name="history" invisible="1"/>
                            <button
                                string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
                                name="%(crm.action_crm_send_mail)d"
                                context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
                                icon="terp-mail-replied" type="action" />
                        </tree>
                            <form string="History">
                                <group col="4" colspan="4">
                                    <field name="email_from"/>
                                    <field name="date"/>
                                    <field name="email_to" size="512"/>
                                    <field name="email_cc" size="512"/>
                                    <field name="name" colspan="4" widget="char" attrs="{'invisible': [('history', '=', False)]}" size="512"/>
                                    <field name="display_text" colspan="4"   attrs="{'invisible': [('history', '=', True)]}"/>
                                    <field name="history" invisible="1"/>
                                </group>
                                <notebook colspan="4">
                                    <page string="Details">
                                        <field name="description" colspan="4" nolabel="1"/>
                                        <group attrs="{'invisible': [('history', '!=', True)]}">
                                            <button colspan="4"
                                                    string="Reply"
                                                    name="%(crm.action_crm_send_mail)d"
                                                    context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
                                                    icon="terp-mail-replied" type="action" />
                                            </group>

                                    </page>
                                    <page string="Attachments">
                                        <field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
                                    </page>
                                    </notebook>
                                </form>
                    </field>
                    <button string="Add Internal Note"
                        name="%(crm.action_crm_add_note)d"
                        context="{'model': 'crm.lead' }"
                        icon="terp-document-new" type="action" />
                    <button string="Send New Email"
                        name="%(crm.action_crm_send_mail)d"
                        context="{'mail':'new', 'model': 'crm.lead'}"
                        icon="terp-mail-message-new" type="action" />
                 </page>
                </notebook>
            </form>
        </field>
    </record>

    <!-- CRM Lead Tree View -->

    <record model="ir.ui.view" id="crm_case_tree_view_leads">
        <field name="name">Leads</field>
        <field name="model">crm.lead</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Leads"  colors="blue:state=='pending';grey:state in ('cancel', 'done')">
                <field name="date_deadline" invisible="1"/>
                <field name="create_date"/>
                <field name="name" string="Subject"/>
                <field name="contact_name"/>
                <field name="country_id" invisible="context.get('invisible_country', True)" />
                <field name="email_from"/>
                <field name="phone"/>

                <field name="categ_id" invisible="1"/>
                <field name="type_id" invisible="1"/>
                <field name="referred" invisible="1"/>
                <field name="channel_id" invisible="1"/>
                <field name="subjects" invisible="1"/>

                <field name="stage_id"/>
                <button name="stage_previous" string="Previous Stage"
                    states="open,pending" type="object" icon="gtk-go-back" />
                <button name="stage_next" string="Next Stage"
                    states="open,pending" type="object"
                    icon="gtk-go-forward" />
                <field name="section_id" invisible="context.get('invisible_section', True)" />
                <field name="user_id" />
                <field name="state" />
                <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-go-forward"
                    type="object" />
                <button name="case_escalate" string="Escalate"
                    states="open,draft,pending" type="object"
                    icon="gtk-go-up" />
            </tree>
        </field>
    </record>

    <!-- CRM Lead Calendar View -->

    <record model="ir.ui.view" id="crm_case_calendar_view_leads">
        <field name="name">CRM - Leads Calendar</field>
        <field name="model">crm.lead</field>
        <field name="type">calendar</field>
        <field name="priority" eval="2"/>
        <field name="arch" type="xml">
            <calendar string="Leads Generation"
                date_start="create_date" color="user_id">
                <field name="name" />
                <field name="partner_name" />
                <field name="partner_address_id" />
            </calendar>
        </field>
    </record>

    <!-- CRM Lead Kanban View  -->
    <record model="ir.ui.view" id="crm_case_kanban_view_leads">
        <field name="name">CRM - Leads Kanban</field>
        <field name="model">crm.lead</field>
        <field name="type">kanban</field>
        <field name="arch" type="xml">
            <kanban>
                <field name="state"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_box oe_kanban_color_border #{__kanban_color(state.raw_value)}">
                            <div class="oe_kanban_box_header oe_kanban_color_bgdark oe_kanban_color_border oe_kanban_draghandle">
                                <h6 class="oe_kanban_left"><field name="name"/></h6>
                                <h5 class="oe_kanban_right" style="vertical-align: top">
                                    <field name="planned_revenue"/>
                                    <img src="http://www.gravatar.com/avatar/2eb60ad22dadcf4dc456b28390a80268.png" style="border-radius: 2px" width="20" height="20"/>
                                </h5>
                                <br class="oe_kanban_clear"/>
                            </div>

                            <div class="oe_kanban_box_content oe_kanban_color_bglight">
                                <div class="oe_kanban_right oe_kanban_small">
                                    <field name="user_id"/>
                                </div>
                                <br class="oe_kanban_clear"/>

                                <b><field name="partner_address_id"/></b><br/>
                                <field name="description"/><br/>
                                <field name="date_action"/><t t-if="date_action.raw_value">: </t><field name="title_action"/>
                            </div>

                            <div class="oe_kanban_buttons_set oe_kanban_color_border oe_kanban_color_bglight oe_kanban_box_show_onclick">
                                <div class="oe_kanban_left">
                                    <a string="Send New Email" class="oe_kanban_color_border"
                                       name="%(crm.action_crm_send_mail)d"
                                       context="{'mail':'new', 'model': 'crm.lead'}"
                                       icon="terp-mail-message-new" type="action"/>

                                    <a string="Schedule/Log Call" class="oe_kanban_color_border"
                                       name="%(opportunity2phonecall_act)d"
                                       icon="terp-call-start" type="action"/>

                                    <a string="Add Internal Note" class="oe_kanban_color_border"
                                       name="%(crm.action_crm_add_note)d"
                                       context="{'model': 'crm.lead' }"
                                       icon="terp-document-new" type="action"/>

                                    <a name="action_makeMeeting" type="object" class="oe_kanban_color_border"
                                            string="Schedule Meeting" icon="gtk-redo" />
                                </div>
                                <div class="oe_kanban_right">
                                    <a name="case_cancel" string="Cancel" states="draft" type="object" icon="gtk-cancel" />
                                    <a name="case_mark_lost" string="Mark Lost" states="open,pending" type="object" icon="gtk-cancel" />
                                    <a name="case_reset" string="Reset to Draft" states="done,cancel" type="object" icon="gtk-convert" />
                                    <a name="case_open" string="Open" states="draft,pending" type="object" icon="gtk-go-forward" />
                                    <a name="case_pending" string="Pending" states="draft,open" type="object" icon="gtk-media-pause" />
                                    <a name="case_escalate" string="Escalate" states="open,pending" type="object" icon="gtk-go-up" />
                                    <a name="case_mark_won" string="Mark Won" states="open,pending" type="object" icon="gtk-apply" />
                                </div>
                                <br class="oe_kanban_clear"/>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- CRM Lead Search View -->

    <record id="view_crm_case_leads_filter" model="ir.ui.view">
        <field name="name">CRM - Leads Search</field>
        <field name="model">crm.lead</field>
        <field name="type">search</field>
        <field name="arch" type="xml">
            <search string="Search Leads">
                <filter icon="terp-check"
                    string="Current"
                    name="current" help="Draft, Open and Pending Leads"
                    domain="[('state','in',('draft','open','pending'))]"/>
                <filter icon="terp-camera_test"
                    string="Open"
                    domain="[('state','=','open')]"/>
                <filter icon="terp-gtk-media-pause"
                    string="Pending"
                    domain="[('state','=','pending')]"/>

                <separator orientation="vertical"/>
                <filter icon="terp-go-today" string="Today"
                    domain="[('create_date','&lt;', time.strftime('%%Y-%%m-%%d 23:59:59')), ('create_date','&gt;=', time.strftime('%%Y-%%m-%%d 00:00:00'))]"
                    help="Todays' Leads" />
                <filter icon="terp-go-week" string="7 Days"
                    help="Leads creating during last 7 days"
                    domain="[('create_date','&lt;', time.strftime('%%Y-%%m-%%d 23:59:59')),('create_date','&gt;=',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d 00:00:00'))]"
                />
                <separator orientation="vertical"/>
                <field name="name" string="Lead / Customer"
                    filter_domain="['|','|',('partner_name','ilike',self),('email_from','ilike',self),('name','ilike',self)]"/>
                <field name="user_id">
                    <filter icon="terp-personal-"
                        domain="[('user_id','=', False)]"
                        help="Unassigned Leads" />
                </field>
                <field name="subjects" groups="base.group_extended"/>
                <field name="section_id" widget="selection"
                    context="{'invisible_section': False}">
                    <filter icon="terp-personal+" groups="base.group_extended"
                        context="{'invisible_section': False}"
                        domain="['|', ('section_id', '=', context.get('section_id')), '|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]"
                        help="My Sales Team(s)"/>
                    <filter icon="terp-personal+" groups="base.group_extended"
                        context="{'invisible_section': False}"
                        domain="[]"
                        help="Show Sales Team"/>
                </field>
                <separator orientation="vertical"/>
                <field name="country_id" context="{'invisible_country': False}">
                	<filter icon="terp-personal+" context="{'invisible_country': False}" help="Show countries"/>
                </field>
                <newline/>
                <group expand="0" string="Group By...">
                    <filter string="Salesman" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
                    <filter string="Team" icon="terp-personal+" domain="[]" context="{'group_by':'section_id'}"/>
                    <filter string="Referrer" icon="terp-personal" domain="[]" context="{'group_by':'referred'}"/>
                    <separator orientation="vertical"/>
                    <filter string="Category" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'categ_id'}"/>
                    <filter string="Campaign" icon="terp-gtk-jump-to-rtl"
                        domain="[]" context="{'group_by':'type_id'}" />
                    <filter string="Channel" icon="terp-call-start"
                        domain="[]" context="{'group_by':'channel_id'}" />
                    <separator orientation="vertical"/>
                    <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
                    <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                    <separator orientation="vertical"/>
                    <filter string="Creation" help="Create date" icon="terp-go-month"
                        domain="[]" context="{'group_by':'create_date'}" />
                </group>
           </search>
        </field>
    </record>


    <!-- Opportunities Form View -->
    <record model="ir.ui.view" id="crm_case_form_view_oppor">
        <field name="name">Opportunities</field>
        <field name="model">crm.lead</field>
        <field name="type">form</field>
        <field name="priority">10</field>
        <field name="arch" type="xml">
            <form string="Opportunities">
                <group colspan="4" col="7">
                    <field name="name"  required="1" string="Opportunity"/>
                    <label string="Stage:" align="1.0"/>
                    <group colspan="1" col="4">
                        <field name="stage_id" nolabel="1"
                            on_change="onchange_stage_id(stage_id)"
                            domain="[('section_ids', '=', section_id)]"/>
                        <button name="stage_previous"
                            states="draft,open,pending" type="object"
                            icon="gtk-go-back" string="" context="{'stage_type': 'opportunity'}"/>
                        <button name="stage_next" states="draft,open,pending"
                            type="object" icon="gtk-go-forward" string="" context="{'stage_type': 'opportunity'}"/>
                    </group>
                    <field name="user_id"/>

                    <button string="Schedule/Log Call"
                    name="%(opportunity2phonecall_act)d" icon="terp-call-start" type="action" groups="base.group_extended"/>

                    <field name="planned_revenue"/>
                    <field name="probability"/>
                    <field name="date_deadline"/>

                    <button name="action_makeMeeting" type="object"
                    string="Schedule Meeting" icon="gtk-redo" />
                    <newline/>
                    <field name="date_action"/>
                    <field name="title_action"/>
                    <field name="priority" string="Priority"/>
                    <newline/>
                    <field name="type" invisible="1"/>
                </group>
                <notebook colspan="4">
                <page string="Opportunity">
                    <group col="4" colspan="2">
                        <separator colspan="4" string="Contacts"/>
                        <group colspan="2">
                            <field name="partner_id" select="1"
                                on_change="onchange_partner_id(partner_id, email_from)" string="Customer"
                                colspan="2" />
                            <button name="%(action_crm_lead2partner)d"
                                icon="terp-partner" type="action"
                                string="Create"
                                attrs="{'invisible':[('partner_id','!=',False)]}"/>
                        </group>
                        <field name="partner_address_id"
                            string="Contact"
                            on_change="onchange_partner_address_id(partner_address_id, email_from)"
                            colspan="1" />
                        <group col="3" colspan="2">
                            <field name="email_from" string="Email" />
                            <button string="Mail"
                            name="%(crm.action_crm_send_mail)d"
                            context="{'mail':'new', 'model': 'crm.lead'}"
                            icon="terp-mail-message-new" type="action" />
                        </group>
                            <field name="phone"/>

                    </group>
                    <group col="2" colspan="2">
                        <separator colspan="2" string="Categorization"/>
                        <field name="section_id" colspan="1" widget="selection"/>
                        <field name="categ_id" select="1"
                        string="Category" widget="selection"
                        domain="[('object_id.model', '=', 'crm.lead')]" />
                    </group>

                    <separator colspan="4" string="Details"/>
                    <field name="description" nolabel="1" colspan="4"/>

                    <separator colspan="4"/>
                    <group col="10" colspan="4">
                        <field name="state"/>
                        <button name="case_cancel" string="Cancel" states="draft" type="object" icon="gtk-cancel" />
                        <button name="case_mark_lost" string="Mark Lost" states="open,pending" type="object" icon="gtk-cancel" />
                        <button name="case_reset" string="Reset to Draft" states="done,cancel" type="object" icon="gtk-convert" />
                        <button name="case_open" string="Open" states="draft,pending" type="object" icon="gtk-go-forward" />
                        <button name="case_pending" string="Pending" states="draft,open" type="object" icon="gtk-media-pause" />
                        <button name="case_escalate" string="Escalate" states="open,pending" type="object" groups="base.group_extended" icon="gtk-go-up" />
                        <button name="case_mark_won" string="Mark Won" states="open,pending" type="object" icon="gtk-apply" />
                    </group>
                </page>
                <page string="Lead">
                    <group colspan="2" col="4">
                        <separator string="Contact" colspan="4" col="4"/>
                        <field name="partner_name" string="Customer Name" colspan="4"/>
                        <newline/>
                        <field domain="[('domain', '=', 'contact')]" name="title" widget="selection"/>
                        <field name="function" />
                        <field name="street" colspan="4"/>
                        <field name="street2" colspan="4"/>
                        <field name="zip"/>
                        <field name="city"/>
                        <field name="country_id"/>
                        <field name="state_id"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Communication" colspan="2"/>
                        <field name="fax"/>
                        <field name="mobile"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Categorization" colspan="2"/>
                        <field name="type_id" widget="selection" groups="base.group_extended"/>
                        <field name="channel_id" widget="selection"/>
                    </group>
                    <group colspan="2" col="2">
                        <separator string="Mailings" colspan="2"/>
                        <field name="optin" on_change="on_change_optin(optin)"/>
                        <field name="optout" on_change="on_change_optout(optout)"/>
                    </group>
                </page>

                <page string="Communication &amp; History" groups="base.group_extended">
                    <group colspan="4">
                        <field colspan="4" name="email_cc" string="Global CC" widget="char" size="512"/>
                    </group>
                    <field name="message_ids" colspan="4" nolabel="1" mode="tree,form">
                        <tree string="History">
                            <field name="display_text" string="History Information"/>
                            <field name="history" invisible="1"/>
                            <button
                                string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
                                name="%(crm.action_crm_send_mail)d"
                                context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
                                icon="terp-mail-replied" type="action" />
                        </tree>
                        <form string="History">
                            <group col="4" colspan="4">
                                <field name="email_from"/>
                                <field name="date"/>
                                <field name="email_to" size="512"/>
                                <field name="email_cc" size="512"/>
                                <field name="name" colspan="4" widget="char" attrs="{'invisible': [('history', '=', False)]}" size="512"/>
                                <field name="display_text" colspan="4"   attrs="{'invisible': [('history', '=', True)]}"/>
                                <field name="history" invisible="1"/>
                            </group>
                            <notebook colspan="4">
                                <page string="Details">

                                        <field name="description" colspan="4" nolabel="1"/>
                                     <group attrs="{'invisible': [('history', '!=', True)]}">
                                        <button colspan="4"
                                            string="Reply"
                                            name="%(crm.action_crm_send_mail)d"
                                            context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
                                            icon="terp-mail-replied" type="action" />
                                    </group>

                                </page>
                                <page string="Attachments">
                                    <field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
                                </page>
                            </notebook>
                        </form>
                    </field>
                    <button string="Add Internal Note"
                        name="%(crm.action_crm_add_note)d"
                        context="{'model': 'crm.lead' }"
                        icon="terp-document-new" type="action" />
                    <button string="Send New Email"
                        name="%(crm.action_crm_send_mail)d"
                        context="{'mail':'new', 'model': 'crm.lead'}"
                        icon="terp-mail-message-new" type="action" />
                </page>
                <page string="Extra Info" groups="base.group_extended">
                    <group col="2" colspan="2">
                        <separator string="Dates" colspan="2"/>
                        <field name="create_date"/>
                        <field name="write_date"/>
                        <field name="date_closed"/>
                        <field name="date_open"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Misc" colspan="2"/>
                        <field name="active"/>
                        <field name="day_open"/>
                        <field name="day_close"/>
                        <field name="referred"/>
                    </group>
                    <separator colspan="4" string="References"/>
                    <field name="ref"/>
                    <field name="ref2"/>
                </page>
                </notebook>
            </form>
        </field>
    </record>

    <!-- Opportunities Tree View -->
    <record model="ir.ui.view" id="crm_case_tree_view_oppor">
        <field name="name">Opportunities Tree</field>
        <field name="model">crm.lead</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Opportunities" colors="blue:state=='pending' and not(date_deadline and (date_deadline &lt; current_date));gray:state in ('cancel', 'done');red:date_deadline and (date_deadline &lt; current_date)">
                <field name="date_deadline" invisible="1"/>
                <field name="create_date"/>
                <field name="name" string="Opportunity"/>
                <field name="partner_id" string="Customer"/>
                <field name="country_id" invisible="context.get('invisible_country', True)" />
                <field name="date_action"/>
                <field name="title_action" />
                <field name="channel_id" invisible="1"/>
                <field name="type_id" invisible="1"/>
                <field name="subjects" invisible="1"/>
                <field name="stage_id"/>
                <button name="stage_previous" string="Previous Stage" states="open,pending" type="object" icon="gtk-go-back" />
                <button name="stage_next" string="Next Stage" states="open,pending" type="object" icon="gtk-go-forward" />
                <field name="planned_revenue" sum="Expected Revenues"/>
                <field name="probability" widget="progressbar" avg="Avg. of Probability"/>
                <field name="section_id" invisible="context.get('invisible_section', True)" />
                <field name="user_id"/>
                <field name="priority" invisible="1"/>
                <field name="categ_id" invisible="1"/>
                <field name="state"/>
                <button name="case_open" string="Open" states="draft,pending" type="object" icon="gtk-go-forward" />
                <button name="case_pending" string="Pending" states="open,draft" type="object" icon="gtk-media-pause" />
                <button name="case_mark_lost" string="Lost" states="open,pending" type="object" icon="gtk-cancel" />
                <button name="case_mark_won" string="Won" states="open,pending" type="object" icon="gtk-apply" />
            </tree>
        </field>
    </record>


    <!-- Opportunities Search View -->
    <record id="view_crm_case_opportunities_filter" model="ir.ui.view">
        <field name="name">CRM - Opportunities Search</field>
        <field name="model">crm.lead</field>
        <field name="type">search</field>
        <field name="arch" type="xml">
            <search string="Search Opportunities">
                <filter icon="terp-check"
                    string="Current"  help="Draft, Open and Pending Opportunities"
                    name="current"
                    domain="[('state','in',('draft','open','pending'))]"/>
                <filter icon="terp-camera_test"
                    string="Open"  help="Open Opportunities"
                    domain="[('state','=','open')]"/>
                <filter icon="terp-gtk-media-pause"
                    string="Pending"  help="Pending Opportunities"
                    domain="[('state','=','pending')]"/>
                <separator orientation="vertical"/>
                <field name="name" string="Opportunity"/>
                <field name="partner_id" string="Customer / Email" filter_domain="['|','|',('partner_id','ilike',self),('partner_name','ilike',self),('email_from','ilike',self)]"/>
                <field name="user_id">
                    <filter icon="terp-personal-"
                        domain="[('user_id','=', False)]"
                        help="Unassigned Opportunities" />
                </field>
                <field name="section_id"
                    context="{'invisible_section': False}"
                    widget="selection">
                    <filter icon="terp-personal+" groups="base.group_extended"
                        domain="['|', ('section_id', '=', context.get('section_id')), '|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]"
                        context="{'invisible_section': False}"
                        help="My Sales Team(s)" />
                    <filter icon="terp-personal+" groups="base.group_extended"
                        context="{'invisible_section': False}"
                        domain="[]"
                        help="Show Sales Team"/>
                </field>

                <newline/>
                <group expand="0" string="Group By..." colspan="16">
                    <filter string="Salesman" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}" />
                    <filter string="Team" help="Sales Team" icon="terp-personal+" domain="[]" context="{'group_by':'section_id'}"/>
                    <filter string="Customer" help="Partner" icon="terp-personal+" domain="[]" context="{'group_by':'partner_id'}"/>
                    <separator orientation="vertical" />
                    <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}" />
                    <filter string="Priority" icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}" />
                    <filter string="Category" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'categ_id'}" />
                    <filter string="Campaign" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'type_id'}" groups="base.group_extended"/>
                    <filter string="Channel" icon="terp-call-start" domain="[]" context="{'group_by':'channel_id'}" />
                    <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                    <separator orientation="vertical" />
                    <filter string="Creation" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}" />
                    <filter string="Exp.Closing" icon="terp-go-month" help="Expected Closing" domain="[]" context="{'group_by':'date_deadline'}" />
                </group>
            </search>
        </field>
    </record>

    <!-- crm.lead Opportunities Graph View -->
    <record model="ir.ui.view" id="crm_case_graph_view_opportunity">
        <field name="name">CRM - Opportunity Graph</field>
        <field name="model">crm.lead</field>
        <field name="type">graph</field>
        <field name="arch" type="xml">
            <graph string="Opportunity by Categories" type="bar" orientation="horizontal">
                <field name="categ_id"/>
                <field name="planned_revenue" operator="+"/>
                <field name="state" group="True"/>
            </graph>
        </field>
    </record>

</data>
</openerp>
