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


        <!--
            CRM CASE STAGE
        -->

        <!-- 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="arch" type="xml">
                <search string="Stage Search">
                    <field name="name" string="Stage Name"/>
                    <field name="state"/>
                    <field name="type"/>
                </search>
            </field>
        </record>

        <!-- 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" type="html">
              <p class="oe_view_nocontent_create">
                Click to set a new stage in your lead/opportunity pipeline.
              </p><p>
                Stages will allow salespersons to easily track how a specific
                lead or opportunity is positioned in the sales cycle.
              </p>
            </field>
        </record>

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

        <!--
            LEADS/OPPORTUNITIES CATEGORIES
        -->

        <!-- Categories Form View -->
        <record id="crm_lead_categ_action" model="ir.actions.act_window">
            <field name="name">Sales Tags</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" eval="{'object_id': ref('model_crm_lead')}"/>
            <field name="domain">[('object_id.model', '=', 'crm.lead')]</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to define a new sales tag.
              </p><p>
                Create specific tags 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.
              </p>
            </field>
        </record>

        <menuitem action="crm_lead_categ_action"
            id="menu_crm_lead_categ" name="Sales Tags"
            parent="base.menu_crm_config_lead" sequence="1" groups="base.group_no_one"/>

        <!--
            LEADS
        -->
        <act_window
                id="act_crm_opportunity_crm_phonecall_new"
                name="Phone calls"
                groups="base.group_sale_salesman"
                res_model="crm.phonecall"
                view_mode="tree,calendar,form"
                context="{'default_duration': 1.0 ,'default_opportunity_id': active_id}"
                view_type="form"/>

        <act_window
                id="act_crm_opportunity_crm_meeting_new"
                name="Meetings"
                res_model="crm.meeting"
                view_mode="tree,form,calendar"
                context="{'default_duration': 4.0, 'default_opportunity_id': active_id}"
                view_type="form"/>


        <!-- 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="arch" type="xml">
            <form string="Leads Form" version="7.0">
                <header>
                    <button name="%(crm.action_crm_lead2opportunity_partner)d" string="Convert to Opportunity" type="action"
                            states="draft,open,pending" help="Convert to Opportunity" class="oe_highlight"/>
                    <button name="case_reset" string="Reset" type="object"
                            states="cancel"/>
                    <button name="case_cancel" string="Cancel" type="object"
                            states="draft,open,pending"/>
                    <field name="stage_id" widget="statusbar" clickable="True"
                            on_change="onchange_stage_id(stage_id)"/>
                </header>
                <sheet>
                    <div class="oe_right oe_button_box" name="buttons">
                        <button type="action"
                            name="%(act_crm_opportunity_crm_phonecall_new)d"
                            string="Phone Calls"/>
                    </div>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only" string="Lead Description"/>
                        <h1><field name="name" placeholder="Describe the lead..."/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="partner_name" string="Company Name"/>
                            <!-- Preload all the partner's information -->
                            <field name="partner_id" string="Customer"
                                on_change="on_change_partner(partner_id)"
                                options='{"create_name_field": "name"}'
                                context="{'default_name': contact_name, 'default_street': street, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_function': function, 'default_phone': phone, 'default_mobile': mobile, 'default_fax': fax, 'default_email': email_from, 'default_user_id': user_id, 'default_section_id': section_id}"/>
                            <label for="street" string="Address"/>
                            <div>
                                <field name="street" placeholder="Street..."/>
                                <field name="street2"/>
                                <div class="address_format">
                                    <field name="city" placeholder="City" style="width: 40%%"/>
                                    <field name="state_id" on_change="onchange_state(state_id)" options='{"no_open": True}' placeholder="State" style="width: 24%%"/>
                                    <field name="zip" placeholder="ZIP" style="width: 34%%"/>
                                </div>
                                <field name="country_id" placeholder="Country" options='{"no_open": True}'/>
                            </div>
                        </group>
                        <group>
                            <label for="contact_name"/>
                            <div>
                                <field name="contact_name" class="oe_inline"/><span attrs="{'invisible': [('title', '=', '')]}">, </span>
                                <field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" class="oe_inline" options='{"no_open": True}'/>
                            </div>
                            <field name="email_from" widget="email"/>
                            <field name="function"/>
                            <field name="phone"/>
                            <field name="mobile"/>
                            <field name="fax"/>
                            <!--
                            This should be integrated in Open Chatter
                            <button string="Mail"
                                name="%(mail.action_email_compose_message_wizard)d"
                                icon="terp-mail-message-new" type="action" colspan="1"/>
                            -->
                        </group>
                        <group>
                            <field name="user_id"/>
                            <label for="section_id"/>
                            <div>
                                <field name="section_id"/>
                                <button name="case_escalate" string="Escalate" type="object" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
                            </div>
                            <field name="type" invisible="1"/>
                        </group>
                        <group>
                            <field name="priority"/>
                            <field name="categ_ids"
                                widget="many2many_tags"
                                domain="[('object_id.model','=','crm.lead')]"/>
                        </group>
                    </group>
                    <notebook colspan="4">
                    <page string="Notes">
                        <field name="description"/>
                    </page>
                    <page string="Extra Info">
                        <group>
                            <group string="Categorization" groups="base.group_multi_company,base.group_no_one" name="categorization">
                                <field name="company_id"
                                    groups="base.group_multi_company"
                                    widget="selection" colspan="2"/>
                                <field name="state" groups="base.group_no_one"/>
                            </group>
                            <group string="Mailings">
                                <field name="opt_out"/>
                            </group>
                            <group string="Misc">
                                <field name="active"/>
                                <field name="referred"/>
                            </group>
                        </group>
                    </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
        </record>

        <!-- CRM Lead Graph View -->
        <record model="ir.ui.view" id="crm_case_graph_view_leads">
            <field name="name">Opportunities</field>
            <field name="model">crm.lead</field>
            <field name="arch" type="xml">
                <graph string="Opportunities" type="bar">
                    <field name="stage_id"/>
                    <field name="planned_revenue" operator="+"/>
                </graph>
            </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="arch" type="xml">
                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:state in ('cancel', 'done')">
                    <field name="date_deadline" invisible="1"/>
                    <field name="create_date" groups="base.group_no_one"/>
                    <field name="name"/>
                    <field name="contact_name"/>
                    <field name="country_id" invisible="context.get('invisible_country', True)"/>
                    <field name="email_from"/>
                    <field name="phone"/>
                    <field name="stage_id"/>
                    <field name="user_id" invisible="1"/>
                    <field name="section_id" invisible="context.get('invisible_section', True)"/>
                    <field name="state" invisible="1"/>
                    <field name="type_id" invisible="1"/>
                    <field name="referred" invisible="1"/>
                    <field name="channel_id" invisible="1"/>
                    <field name="message_unread" invisible="1"/>
                </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="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Leads Generation"
                    date_start="date_action" color="user_id">
                    <field name="name"/>
                    <field name="partner_name"/>
                </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="arch" type="xml">
                <kanban default_group_by="stage_id">
                    <field name="state" groups="base.group_no_one"/>
                    <field name="stage_id"/>
                    <field name="color"/>
                    <field name="priority"/>
                    <field name="planned_revenue" sum="Expected Revenues"/>
                    <field name="user_email"/>
                    <field name="user_id"/>
                    <field name="partner_address_email"/>
                    <field name="message_summary"/>
                    <field name="message_unread"/>
                    <templates>
                        <field name="date_deadline"/>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
                                <div class="oe_dropdown_toggle oe_dropdown_kanban">
                                    <span class="oe_e">í</span>
                                    <ul class="oe_dropdown_menu">
                                        <t t-if="widget.view.is_action_enabled('edit')"><li><a type="edit">Edit...</a></li></t>
                                        <t t-if="widget.view.is_action_enabled('delete')"><li><a type="delete">Delete</a></li></t>
                                        <li><a name="%(mail.action_email_compose_message_wizard)d" type="action">Send Email</a></li>
                                        <li><a name="%(opportunity2phonecall_act)d" type="action">Schedule/Log Call</a></li>
                                        <li><a name="action_makeMeeting" type="object">Schedule Meeting</a></li>
                                        <li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                    </ul>
                                </div>
                                <div class="oe_kanban_content">
                                    <div>
                                        <b><field name="name"/></b>
                                        <t t-if="record.planned_revenue.raw_value">
                                            - <b><t t-esc="record.planned_revenue.value"/>
                                            <field name="company_currency"/></b>
                                        </t>
                                    </div>
                                    <div>
                                        <field name="partner_id"/>
                                    </div>
                                    <div style="padding-left: 0.5em">
                                        <t t-if="record.date_deadline.raw_value and record.date_deadline.raw_value lt (new Date())" t-set="red">oe_kanban_text_red</t>
                                        <span t-attf-class="#{red || ''}"><field name="date_action"/></span>
                                        <t t-if="record.date_action.raw_value"> : </t>
                                        <field name="title_action"/>
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <a t-if="record.priority.raw_value == 1" type="object" name="set_normal_priority" class="oe_e oe_star_on">7</a>
                                        <a t-if="record.priority.raw_value != 1" type="object" name="set_high_priority" class="oe_e oe_star_off">7</a>
                                        <img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" t-att-title="record.user_id.value" width="24" height="24" class="oe_kanban_avatar" t-if="record.user_id.value"/>
                                    </div>
                                    <div class="oe_kanban_footer_left">
                                        <t t-raw="record.message_summary.raw_value"/>
                                    </div>
                                </div>
                                <div class="oe_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="arch" type="xml">
                <search string="Search Leads">
                    <field name="name" string="Lead / Customer" filter_domain="['|','|',('partner_name','ilike',self),('email_from','ilike',self),('name','ilike',self)]"/>
                    <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike',self)]"/>
                    <field name="create_date"/>
                    <filter icon="terp-mail-message-new" string="Unread Messages" help="Unread messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                    <separator/>
                    <filter icon="terp-check" string="New" name="new" help="New Leads" domain="[('state','=','draft')]"/>
                    <filter icon="terp-camera_test" string="In Progress" name="open" domain="[('state','=','open')]"/>
                    <separator/>
                    <filter string="Unassigned Leads" icon="terp-personal-" domain="[('user_id','=', False)]" help="Unassigned Leads"/>
                    <separator/>
                    <filter string="Leads Assigned to Me or My Team(s)" icon="terp-personal+" context="{'invisible_section': False}"
                            domain="['|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]"
                            help="Leads that are assigned to one of the sale teams I manage, or to me"/>
                    <field name="user_id"/>
                    <field name="section_id" context="{'invisible_section': False}"/>
                    <field name="country_id" context="{'invisible_country': False}"/>
                    <group expand="0" string="Group By...">
                        <filter string="Salesperson" 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'}"/>
                        <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="Creation" help="Create date" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}" groups="base.group_no_one"/>
                    </group>
                    <group string="Display">
                        <filter string="Show Countries" icon="terp-personal+" context="{'invisible_country': False}" help="Show Countries"/>
                        <filter string="Show Sales Team" icon="terp-personal+" context="{'invisible_section': False}" domain="[]" help="Show Sales Team"/>
                    </group>
               </search>
            </field>
        </record>


        <!--
            OPPORTUNITY
        -->

        <!-- 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="priority">20</field>
            <field name="arch" type="xml">
                <form string="Opportunities" version="7.0">
                    <header>
                        <button name="case_mark_won" string="Mark Won" type="object"
                                states="draft,open,pending" class="oe_highlight"/>
                        <button name="case_mark_lost" string="Mark Lost" type="object"
                                states="draft,open" class="oe_highlight"/>
                        <button name="new_mail_send" string="Send Mail" type="object" states="draft,open,pending"/>
                        <field name="stage_id" widget="statusbar" clickable="True"/>
                    </header>
                    <sheet>
                        <div class="oe_right oe_button_box">
                            <button string="Schedule/Log Call"
                                name="%(opportunity2phonecall_act)d"
                                type="action"/>
                            <button string="Meeting"
                                name="action_makeMeeting"
                                type="object"
                                context="{'search_default_attendee_id': active_id, 'default_attendee_id' : active_id}"
                               />
                        </div>
                        <div class="oe_title">
                            <label for="name" class="oe_edit_only"/>
                            <h1><field name="name"/></h1>
                            <label for="planned_revenue" class="oe_edit_only"/>
                            <h2>
                                <field name="company_currency" invisible="1"/>
                                <field name="planned_revenue" class="oe_inline" widget='monetary' options="{'currency_field': 'company_currency'}"/>
                                <span class="oe_grey"> at </span>
                                <field name="probability" class="oe_inline" widget="integer"/>%%
                            </h2>
                        </div>
                        <group>
                            <group>
                                <field name="partner_id"
                                    on_change="onchange_partner_id(partner_id, email_from)"
                                    string="Customer"
                                    context="{'default_name': partner_name, 'default_email': email_from, 'default_phone': phone}"/>
                                <field name="email_from" string="Email"/>
                                <field name="phone"/>
                            </group>

                            <group>
                                <label for="title_action"/>
                                <div>
                                    <field name="date_action" nolabel="1"/> <label string="-" attrs="{'invisible': ['|', ('date_action', '=', False), ('title_action', '=', False)]}"/>
                                    <field name="title_action" class="oe_inline" nolabel="1" placeholder="e.g. Call for proposal"/>
                                </div>
                                <field name="date_deadline"/>
                                <field name="priority"/>
                            </group>

                            <group>
                                <field name="user_id"/>
                                <label for="section_id"/>
                                <div>
                                    <field name="section_id" widget="selection"/>
                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
                                </div>
                            </group>
                            <group>
                                <field name="categ_ids"
                                    string="Categories" widget="many2many_tags"
                                    context = "{'object_name': 'crm.lead'}"
                                    domain="[('object_id.model', '=', 'crm.lead')]"/>

                            </group>
                        </group>

                        <notebook colspan="4">
                        <page string="Internal Notes">
                            <field name="description"/>
                        </page>
                        <page string="Lead">
                            <group>
                                <group>
                                    <field name="partner_name"/>
                                    <label for="street" string="Address"/>
                                    <div>
                                        <field name="street" placeholder="Street..."/>
                                        <field name="street2"/>
                                        <div class="address_format">
                                            <field name="city" placeholder="City" style="width: 40%%"/>
                                            <field name="state_id" options='{"no_open": True}' on_change="onchange_state(state_id)" placeholder="State" style="width: 24%%"/>
                                            <field name="zip" placeholder="ZIP" style="width: 34%%"/>
                                        </div>
                                        <field name="country_id" placeholder="Country" options='{"no_open": True}'/>
                                    </div>
                                </group>

                                <group>
                                    <label for="contact_name"/>
                                    <div>
                                        <field name="contact_name" class="oe_inline"/>
                                        <field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" options='{"no_open": True}' class="oe_inline"/>
                                    </div>
                                    <field name="function"/>
                                    <field name="mobile"/>
                                    <field name="fax"/>
                                </group>
                                <group string="Mailings" name="mailings">
                                    <field name="opt_out"/>
                                </group>
                                <group string="Misc">
                                    <field name="active"/>
                                    <field name="day_open" groups="base.group_no_one"/>
                                    <field name="day_close" groups="base.group_no_one"/>
                                    <field name="referred"/>
                                    <field name="state" invisible="1"/>
                                    <field name="type" invisible="1"/>
                                </group>
                                <group string="References">
                                    <field name="ref"/>
                                    <field name="ref2"/>
                                </group>
                            </group>
                        </page>
                        <page string="Fund Raising" groups="crm.group_fund_raising">
                            <group>
                                <field name="payment_mode" widget="selection"/>
                                <field name="planned_cost"/>
                            </group>
                        </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers"/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </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="arch" type="xml">
                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:state in ('cancel', 'done');red:date_deadline and (date_deadline &lt; current_date)">
                    <field name="date_deadline" invisible="1"/>
                    <field name="create_date" groups="base.group_no_one"/>
                    <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="stage_id"/>
                    <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="state" groups="base.group_no_one"/>
                    <field name="message_unread" invisible="1"/>
                </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="arch" type="xml">
                <search string="Search Opportunities">
                    <field name="name" string="Opportunity"
                        filter_domain="['|','|','|',('partner_id','ilike',self),('partner_name','ilike',self),('email_from','ilike',self),('name', 'ilike', self)]"/>
                    <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike', self)]"/>
                    <filter icon="terp-mail-message-new" string="Unread Messages" help="Unread messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                    <separator/>
                    <filter icon="terp-check" string="New" help="New Opportunities" name="new" domain="[('state','=','draft')]"/>
                    <filter icon="terp-camera_test" string="In Progress" help="Open Opportunities" name="open" domain="[('state','=','open')]"/>
                    <separator/>
                    <filter string="Unassigned Opportunities" icon="terp-personal-" domain="[('user_id','=', False)]" help="Unassigned Opportunities"/>
                    <separator/>
                    <filter string="Opportunities Assigned to Me or My Team(s)"  icon="terp-personal+"
                            domain="['|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]" context="{'invisible_section': False}"
                            help="Opportunities that are assigned to either me or one of the sale teams I manage"/>
                    <field name="user_id"/>
                    <field name="section_id" context="{'invisible_section': False, 'default_section_id': self}"/><commit_msg>[IMP] crm: cosmetic modification<commit_after><?xml version="1.0"?>
<openerp>
    <data>


        <!--
            CRM CASE STAGE
        -->

        <!-- 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="arch" type="xml">
                <search string="Stage Search">
                    <field name="name" string="Stage Name"/>
                    <field name="state"/>
                    <field name="type"/>
                </search>
            </field>
        </record>

        <!-- 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" type="html">
              <p class="oe_view_nocontent_create">
                Click to set a new stage in your lead/opportunity pipeline.
              </p><p>
                Stages will allow salespersons to easily track how a specific
                lead or opportunity is positioned in the sales cycle.
              </p>
            </field>
        </record>

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

        <!--
            LEADS/OPPORTUNITIES CATEGORIES
        -->

        <!-- Categories Form View -->
        <record id="crm_lead_categ_action" model="ir.actions.act_window">
            <field name="name">Sales Tags</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" eval="{'object_id': ref('model_crm_lead')}"/>
            <field name="domain">[('object_id.model', '=', 'crm.lead')]</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to define a new sales tag.
              </p><p>
                Create specific tags 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.
              </p>
            </field>
        </record>

        <menuitem action="crm_lead_categ_action"
            id="menu_crm_lead_categ" name="Sales Tags"
            parent="base.menu_crm_config_lead" sequence="1" groups="base.group_no_one"/>

        <!--
            LEADS
        -->
        <act_window
                id="act_crm_opportunity_crm_phonecall_new"
                name="Phone calls"
                groups="base.group_sale_salesman"
                res_model="crm.phonecall"
                view_mode="tree,calendar,form"
                context="{'default_duration': 1.0 ,'default_opportunity_id': active_id}"
                view_type="form"/>

        <act_window
                id="act_crm_opportunity_crm_meeting_new"
                name="Meetings"
                res_model="crm.meeting"
                view_mode="tree,form,calendar"
                context="{'default_duration': 4.0, 'default_opportunity_id': active_id}"
                view_type="form"/>


        <!-- 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="arch" type="xml">
            <form string="Leads Form" version="7.0">
                <header>
                    <button name="%(crm.action_crm_lead2opportunity_partner)d" string="Convert to Opportunity" type="action"
                            states="draft,open,pending" help="Convert to Opportunity" class="oe_highlight"/>
                    <button name="case_reset" string="Reset" type="object"
                            states="cancel"/>
                    <button name="case_cancel" string="Cancel" type="object"
                            states="draft,open,pending"/>
                    <field name="stage_id" widget="statusbar" clickable="True"
                            on_change="onchange_stage_id(stage_id)"/>
                </header>
                <sheet>
                    <div class="oe_right oe_button_box" name="buttons">
                        <button type="action"
                            name="%(act_crm_opportunity_crm_phonecall_new)d"
                            string="Phone Calls"/>
                    </div>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only" string="Lead Description"/>
                        <h1><field name="name" placeholder="Describe the lead..."/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="partner_name" string="Company Name"/>
                            <!-- Preload all the partner's information -->
                            <field name="partner_id" string="Customer"
                                on_change="on_change_partner(partner_id)"
                                options='{"create_name_field": "name"}'
                                context="{'default_name': contact_name, 'default_street': street, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_function': function, 'default_phone': phone, 'default_mobile': mobile, 'default_fax': fax, 'default_email': email_from, 'default_user_id': user_id, 'default_section_id': section_id}"/>
                            <label for="street" string="Address"/>
                            <div>
                                <field name="street" placeholder="Street..."/>
                                <field name="street2"/>
                                <div class="address_format">
                                    <field name="city" placeholder="City" style="width: 40%%"/>
                                    <field name="state_id" on_change="onchange_state(state_id)" options='{"no_open": True}' placeholder="State" style="width: 24%%"/>
                                    <field name="zip" placeholder="ZIP" style="width: 34%%"/>
                                </div>
                                <field name="country_id" placeholder="Country" options='{"no_open": True}'/>
                            </div>
                        </group>
                        <group>
                            <label for="contact_name"/>
                            <div>
                                <field name="contact_name" class="oe_inline"/><span attrs="{'invisible': [('title', '=', '')]}">, </span>
                                <field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" class="oe_inline" options='{"no_open": True}'/>
                            </div>
                            <field name="email_from" widget="email"/>
                            <field name="function"/>
                            <field name="phone"/>
                            <field name="mobile"/>
                            <field name="fax"/>
                            <!--
                            This should be integrated in Open Chatter
                            <button string="Mail"
                                name="%(mail.action_email_compose_message_wizard)d"
                                icon="terp-mail-message-new" type="action" colspan="1"/>
                            -->
                        </group>
                        <group>
                            <field name="user_id"/>
                            <label for="section_id"/>
                            <div>
                                <field name="section_id"/>
                                <button name="case_escalate" string="Escalate" type="object" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
                            </div>
                            <field name="type" invisible="1"/>
                        </group>
                        <group>
                            <field name="priority"/>
                            <field name="categ_ids"
                                widget="many2many_tags"
                                domain="[('object_id.model','=','crm.lead')]"/>
                        </group>
                    </group>
                    <notebook colspan="4">
                    <page string="Notes">
                        <field name="description"/>
                    </page>
                    <page string="Extra Info">
                        <group>
                            <group string="Categorization" groups="base.group_multi_company,base.group_no_one" name="categorization">
                                <field name="company_id"
                                    groups="base.group_multi_company"
                                    widget="selection" colspan="2"/>
                                <field name="state" groups="base.group_no_one"/>
                            </group>
                            <group string="Mailings">
                                <field name="opt_out"/>
                            </group>
                            <group string="Misc">
                                <field name="active"/>
                                <field name="referred"/>
                            </group>
                        </group>
                    </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
        </record>

        <!-- CRM Lead Graph View -->
        <record model="ir.ui.view" id="crm_case_graph_view_leads">
            <field name="name">Opportunities</field>
            <field name="model">crm.lead</field>
            <field name="arch" type="xml">
                <graph string="Opportunities" type="bar">
                    <field name="stage_id"/>
                    <field name="planned_revenue" operator="+"/>
                </graph>
            </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="arch" type="xml">
                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:state in ('cancel', 'done')">
                    <field name="date_deadline" invisible="1"/>
                    <field name="create_date" groups="base.group_no_one"/>
                    <field name="name"/>
                    <field name="contact_name"/>
                    <field name="country_id" invisible="context.get('invisible_country', True)"/>
                    <field name="email_from"/>
                    <field name="phone"/>
                    <field name="stage_id"/>
                    <field name="user_id" invisible="1"/>
                    <field name="section_id" invisible="context.get('invisible_section', True)"/>
                    <field name="state" invisible="1"/>
                    <field name="type_id" invisible="1"/>
                    <field name="referred" invisible="1"/>
                    <field name="channel_id" invisible="1"/>
                    <field name="message_unread" invisible="1"/>
                </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="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Leads Generation"
                    date_start="date_action" color="user_id">
                    <field name="name"/>
                    <field name="partner_name"/>
                </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="arch" type="xml">
                <kanban default_group_by="stage_id">
                    <field name="state" groups="base.group_no_one"/>
                    <field name="stage_id"/>
                    <field name="color"/>
                    <field name="priority"/>
                    <field name="planned_revenue" sum="Expected Revenues"/>
                    <field name="user_email"/>
                    <field name="user_id"/>
                    <field name="partner_address_email"/>
                    <field name="message_summary"/>
                    <field name="message_unread"/>
                    <templates>
                        <field name="date_deadline"/>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
                                <div class="oe_dropdown_toggle oe_dropdown_kanban">
                                    <span class="oe_e">í</span>
                                    <ul class="oe_dropdown_menu">
                                        <t t-if="widget.view.is_action_enabled('edit')"><li><a type="edit">Edit...</a></li></t>
                                        <t t-if="widget.view.is_action_enabled('delete')"><li><a type="delete">Delete</a></li></t>
                                        <li><a name="%(mail.action_email_compose_message_wizard)d" type="action">Send Email</a></li>
                                        <li><a name="%(opportunity2phonecall_act)d" type="action">Schedule/Log Call</a></li>
                                        <li><a name="action_makeMeeting" type="object">Schedule Meeting</a></li>
                                        <li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                    </ul>
                                </div>
                                <div class="oe_kanban_content">
                                    <div>
                                        <b><field name="name"/></b>
                                        <t t-if="record.planned_revenue.raw_value">
                                            - <b><t t-esc="record.planned_revenue.value"/>
                                            <field name="company_currency"/></b>
                                        </t>
                                    </div>
                                    <div>
                                        <field name="partner_id"/>
                                    </div>
                                    <div style="padding-left: 0.5em">
                                        <t t-if="record.date_deadline.raw_value and record.date_deadline.raw_value lt (new Date())" t-set="red">oe_kanban_text_red</t>
                                        <span t-attf-class="#{red || ''}"><field name="date_action"/></span>
                                        <t t-if="record.date_action.raw_value"> : </t>
                                        <field name="title_action"/>
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <a t-if="record.priority.raw_value == 1" type="object" name="set_normal_priority" class="oe_e oe_star_on">7</a>
                                        <a t-if="record.priority.raw_value != 1" type="object" name="set_high_priority" class="oe_e oe_star_off">7</a>
                                        <img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" t-att-title="record.user_id.value" width="24" height="24" class="oe_kanban_avatar" t-if="record.user_id.value"/>
                                    </div>
                                    <div class="oe_kanban_footer_left">
                                        <t t-raw="record.message_summary.raw_value"/>
                                    </div>
                                </div>
                                <div class="oe_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="arch" type="xml">
                <search string="Search Leads">
                    <field name="name" string="Lead / Customer" filter_domain="['|','|',('partner_name','ilike',self),('email_from','ilike',self),('name','ilike',self)]"/>
                    <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike',self)]"/>
                    <field name="create_date"/>
                    <filter icon="terp-mail-message-new" string="Unread Messages" help="Unread messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                    <separator/>
                    <filter icon="terp-check" string="New" name="new" help="New Leads" domain="[('state','=','draft')]"/>
                    <filter icon="terp-camera_test" string="In Progress" name="open" domain="[('state','=','open')]"/>
                    <separator/>
                    <filter string="Unassigned Leads" icon="terp-personal-" domain="[('user_id','=', False)]" help="Unassigned Leads"/>
                    <separator/>
                    <filter string="Leads Assigned to Me or My Team(s)" icon="terp-personal+" context="{'invisible_section': False}"
                            domain="['|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]"
                            help="Leads that are assigned to one of the sale teams I manage, or to me"/>
                    <field name="user_id"/>
                    <field name="section_id" context="{'invisible_section': False}"/>
                    <field name="country_id" context="{'invisible_country': False}"/>
                    <group expand="0" string="Group By...">
                        <filter string="Salesperson" 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'}"/>
                        <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="Creation" help="Create date" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}" groups="base.group_no_one"/>
                    </group>
                    <group string="Display">
                        <filter string="Show Countries" icon="terp-personal+" context="{'invisible_country': False}" help="Show Countries"/>
                        <filter string="Show Sales Team" icon="terp-personal+" context="{'invisible_section': False}" domain="[]" help="Show Sales Team"/>
                    </group>
               </search>
            </field>
        </record>


        <!--
            OPPORTUNITY
        -->

        <!-- 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="priority">20</field>
            <field name="arch" type="xml">
                <form string="Opportunities" version="7.0">
                    <header>
                        <button name="case_mark_won" string="Mark Won" type="object"
                                states="draft,open,pending" class="oe_highlight"/>
                        <button name="case_mark_lost" string="Mark Lost" type="object"
                                states="draft,open" class="oe_highlight"/>
                        <button name="new_mail_send" string="Send Mail" type="object" states="draft,open,pending"/>
                        <field name="stage_id" widget="statusbar" clickable="True"/>
                    </header>
                    <sheet>
                        <div class="oe_right oe_button_box">
                            <button string="Schedule/Log Call"
                                name="%(opportunity2phonecall_act)d"
                                type="action"/>
                            <button string="Meeting"
                                name="action_makeMeeting"
                                type="object"
                                context="{'search_default_attendee_id': active_id, 'default_attendee_id' : active_id}"
                               />
                        </div>
                        <div class="oe_title">
                            <label for="name" class="oe_edit_only"/>
                            <h1><field name="name"/></h1>
                            <label for="planned_revenue" class="oe_edit_only"/>
                            <h2>
                                <field name="company_currency" invisible="1"/>
                                <field name="planned_revenue" class="oe_inline" widget='monetary' options="{'currency_field': 'company_currency'}"/>
                                <span class="oe_grey"> at </span>
                                <field name="probability" class="oe_inline" widget="integer"/>%%
                            </h2>
                        </div>
                        <group>
                            <group>
                                <field name="partner_id"
                                    on_change="onchange_partner_id(partner_id, email_from)"
                                    string="Customer"
                                    context="{'default_name': partner_name, 'default_email': email_from, 'default_phone': phone}"/>
                                <field name="email_from" string="Email"/>
                                <field name="phone"/>
                            </group>

                            <group>
                                <label for="title_action"/>
                                <div>
                                    <field name="date_action" nolabel="1"/> <label string="-" attrs="{'invisible': ['|', ('date_action', '=', False), ('title_action', '=', False)]}"/>
                                    <field name="title_action" class="oe_inline" nolabel="1" placeholder="e.g. Call for proposal"/>
                                </div>
                                <field name="date_deadline"/>
                                <field name="priority"/>
                            </group>

                            <group>
                                <field name="user_id"/>
                                <label for="section_id"/>
                                <div>
                                    <field name="section_id" widget="selection"/>
                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
                                </div>
                            </group>
                            <group>
                                <field name="categ_ids"
                                    string="Categories" widget="many2many_tags"
                                    context = "{'object_name': 'crm.lead'}"
                                    domain="[('object_id.model', '=', 'crm.lead')]"/>

                            </group>
                        </group>

                        <notebook colspan="4">
                        <page string="Internal Notes">
                            <field name="description"/>
                        </page>
                        <page string="Lead">
                            <group>
                                <group>
                                    <field name="partner_name"/>
                                    <label for="street" string="Address"/>
                                    <div>
                                        <field name="street" placeholder="Street..."/>
                                        <field name="street2"/>
                                        <div class="address_format">
                                            <field name="city" placeholder="City" style="width: 40%%"/>
                                            <field name="state_id" options='{"no_open": True}' on_change="onchange_state(state_id)" placeholder="State" style="width: 24%%"/>
                                            <field name="zip" placeholder="ZIP" style="width: 34%%"/>
                                        </div>
                                        <field name="country_id" placeholder="Country" options='{"no_open": True}'/>
                                    </div>
                                </group>

                                <group>
                                    <label for="contact_name"/>
                                    <div>
                                        <field name="contact_name" class="oe_inline"/>
                                        <field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" options='{"no_open": True}' class="oe_inline"/>
                                    </div>
                                    <field name="function"/>
                                    <field name="mobile"/>
                                    <field name="fax"/>
                                </group>
                                <group string="Mailings" name="mailings">
                                    <field name="opt_out"/>
                                </group>
                                <group string="Misc">
                                    <field name="active"/>
                                    <field name="day_open" groups="base.group_no_one"/>
                                    <field name="day_close" groups="base.group_no_one"/>
                                    <field name="referred"/>
                                    <field name="state" invisible="1"/>
                                    <field name="type" invisible="1"/>
                                </group>
                                <group string="References">
                                    <field name="ref"/>
                                    <field name="ref2"/>
                                </group>
                            </group>
                        </page>
                        <page string="Fund Raising" groups="crm.group_fund_raising">
                            <group>
                                <field name="payment_mode" widget="selection"/>
                                <field name="planned_cost"/>
                            </group>
                        </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers"/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </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="arch" type="xml">
                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:state in ('cancel', 'done');red:date_deadline and (date_deadline &lt; current_date)">
                    <field name="date_deadline" invisible="1"/>
                    <field name="create_date" groups="base.group_no_one"/>
                    <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="stage_id"/>
                    <field name="planned_revenue" sum="Expected Revenues"/>
                    <field name="probability" 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="state" groups="base.group_no_one"/>
                    <field name="message_unread" invisible="1"/>
                </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="arch" type="xml">
                <search string="Search Opportunities">
                    <field name="name" string="Opportunity"
                        filter_domain="['|','|','|',('partner_id','ilike',self),('partner_name','ilike',self),('email_from','ilike',self),('name', 'ilike', self)]"/>
                    <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike', self)]"/>
                    <filter icon="terp-mail-message-new" string="Unread Messages" help="Unread messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                    <separator/>
                    <filter icon="terp-check" string="New" help="New Opportunities" name="new" domain="[('state','=','draft')]"/>
                    <filter icon="terp-camera_test" string="In Progress" help="Open Opportunities" name="open" domain="[('state','=','open')]"/>
                    <separator/>
                    <filter string="Unassigned Opportunities" icon="terp-personal-" domain="[('user_id','=', False)]" help="Unassigned Opportunities"/>
                    <separator/>
                    <filter string="Opportunities Assigned to Me or My Team(s)"  icon="terp-personal+"
                            domain="['|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]" context="{'invisible_section': False}"
                            help="Opportunities that are assigned to either me or one of the sale teams I manage"/>
                    <field name="user_id"/>
                    <field name="section_id" context="{'invisible_section': False, 'default_section_id': self}"/>
{'fraction_non_alphanumeric': 0.13708774113254513, 'fraction_numerical': 0.0023024268823895458, 'mean_word_length': 1.2935383737110644, 'pattern_counts': {'":': 14, '<': 1049, '<?xml version=': 2, '>': 1049, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 190, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7363057', 'n_tokens_mistral': 16220, 'n_tokens_neox': 15265, 'n_words': 2851}