<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
        <menuitem name="Sales"
            id="base.menu_base_partner"
            groups="base.group_sale_salesman,base.group_sale_manager"/>
 <!-- Update user form !-->
        <record model="ir.ui.view" id="res_user_form">
            <field name="name">Users Preferences</field>
            <field name="model">res.users</field>
            <field name="inherit_id" ref="base.view_users_form"/>
            <field name="arch" type="xml">
                <data>
                    <xpath expr="//field[@name='tz']" position="after">
                        <field name="default_section_id"/>
                    </xpath>
                </data>
            </field>
        </record>

        <!-- Update Preferences form !-->
        <record id="view_users_form_preferences" model="ir.ui.view">
            <field name="name">res.users.preferences.form</field>
            <field name="model">res.users</field>
            <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
            <field name="arch" type="xml">
                <data>
                    <xpath expr="//field[@name='company_id']" position="before">
                        <field name="default_section_id" readonly="0"/>
                    </xpath>
                </data>
            </field>
        </record>

        <!-- Case Sections Salesteams kanban view -->

       <record id="crm_case_section_salesteams_view_kanban" model="ir.ui.view" >
            <field name="name">crm.case.section.kanban</field>
            <field name="model">crm.case.section</field>
            <field name="arch" type="xml">
                <kanban class="oe_background_grey">
                    <field name="name"/>
                    <field name="user_id"/>
                    <field name="member_ids"/>
                    <field name="note"/>
                    <field name="color"/>
                    <templates>
                        <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 oe_kanban_crm_salesteams">
                                <div class="oe_dropdown_toggle oe_dropdown_kanban" groups="base.group_sale_manager">
                                    <span class="oe_e">í</span>
                                    <ul class="oe_dropdown_menu">
                                        <li t-if="widget.view.is_action_enabled('edit')"><a type="edit">Sales Teams Settings</a></li>
                                        <li t-if="widget.view.is_action_enabled('delete')"><a type="delete">Delete</a></li>
                                        <li t-if="widget.view.is_action_enabled('edit')"><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                    </ul>
                                </div>
                                <div class="oe_kanban_content">
                                    <h4 class="text-center" name="name"><strong><field name="name"/></strong></h4>
                                    <div class="oe_clear"></div>
                                    <div class="oe_kanban_salesteams_avatars">
                                        <t t-foreach="record.member_ids.raw_value.slice(0,10)" t-as="member">
                                            <img t-att-src="kanban_image('res.users', 'image_small', member)" t-att-data-member_id="member"/>
                                        </t>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <!-- Case Sections Search view -->
        <record id="crm_case_section_salesteams_search" model="ir.ui.view">
            <field name="name">Case Sections - Search</field>
            <field name="model">crm.case.section</field>
            <field name="arch" type="xml">
                <search string="Salesteams Search">
                    <filter name="personal" string="My Salesteams" domain="['|', ('member_ids', '=', uid), ('user_id', '=', uid)]"/>
                    <field name="name"/>
                    <field name="parent_id"/>
                    <field name="user_id"/>
                    <field name="note"/>
                    <field name="code"/>
                    <group expand="0" string="Group By...">
                        <filter string="Team Leader" domain="[]" context="{'group_by':'user_id'}"/>
                        <filter string="Parent Sales Teams" domain="[]" context="{'group_by':'parent_id'}"/>
                    </group>
                </search>
            </field>
        </record>

        <!-- Case Sections Action -->
        <record id="crm_case_section_salesteams_act" model="ir.actions.act_window">
            <field name="name">Sales Teams</field>
            <field name="res_model">crm.case.section</field>
            <field name="view_type">form</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="context">{}</field>
            <field name="view_id" ref="crm_case_section_salesteams_search"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    Click here to define a new sales team.
                </p><p>
                    Use sales team to organize your different salespersons or
                    departments into separate teams. Each team will work in
                    its own list of opportunities.
                </p>
            </field>
        </record>

        <!-- Case Sections Form View -->

         <record id="crm_case_section_view_form" model="ir.ui.view">
            <field name="name">crm.case.section.form</field>
            <field name="model">crm.case.section</field>
            <field name="arch" type="xml">
                <form string="Sales Team">
                    <sheet>
                        <div class="oe_title">
                            <label for="name" class="oe_edit_only" string="Sales team"/>
                            <h1>
                                <field name="name" string="Salesteam"/>
                            </h1>
                            <div name="options_active"></div>
                        </div>
                        <group>
                            <group name="left">
                                <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
                                <field name="code"/>
                                <field name="parent_id"/>
                                <field name="change_responsible"/>
                                <field name="active"/>
                            </group>
                        </group>
                        <notebook colspan="4">
                            <page string="Team Members">
                                <field name="member_ids">
                                    <tree>
                                        <field name="name"/>
                                    </tree>
                                </field>
                            </page>
                            <page string="Notes">
                                <field name="note"/>
                            </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers" help="Follow this salesteam to automatically track the events associated to users of this team."/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </form>
            </field>
        </record>

        <!-- Case Sections Tree View -->
        <record id="crm_case_section_view_tree" model="ir.ui.view">
            <field name="name">crm.case.section.tree</field>
            <field name="model">crm.case.section</field>
            <field name="field_parent">child_ids</field>
            <field name="arch" type="xml">
                <tree string="Sales Team">
                    <field name="name"/>
                    <field name="code"/>
                    <field name="user_id"/>
                </tree>
            </field>
        </record>

        <record id="crm_case_section_act" model="ir.actions.act_window">
            <field name="name">Sales Teams</field>
            <field name="res_model">crm.case.section</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="crm_case_section_view_tree"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    Click here to define a new sales team.
                </p><p>
                    Use sales team to organize your different salespersons or
                    departments into separate teams. Each team will work in
                    its own list of opportunities.
                </p>
            </field>
        </record>

        <menuitem id="sales_team.menu_sales_team_act" action="crm_case_section_salesteams_act" sequence="1" parent="base.menu_sales" groups="base.group_multi_salesteams"/>

        <!-- add css / js -->
        <template id="assets_backend" name="sales_team assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/sales_team/static/src/css/sales_team.css"/>
                <script type="text/javascript" src="/sales_team/static/src/js/sales_team.js"></script>
            </xpath>
        </template>

        <menuitem id="base.next_id_64" name="Sales" parent="base.menu_reporting" sequence="1" groups="base.group_sale_manager"/>

    </data>
</openerp>
