<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="crm_phonecall_categ_action" model="ir.actions.act_window">
        <field name="name">Phonecall Categories</field>
        <field name="res_model">crm.tag</field>
        <field name="view_id" ref="sales_team.sales_team_crm_tag_view_tree" />
        <field name="domain">[]</field>
        <field eval="{'object_id': ref('model_crm_phonecall')}" name="context" />
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">Click to add a new category.</p>
            <p>
                Create specific phone call categories to better define the type of
            calls tracked in the system.
            </p>
        </field>
    </record>
    <menuitem
        id="menu_crm_config_phonecall"
        name="Phone Calls"
        parent="crm.crm_menu_config"
        sequence="19"
    />
    <menuitem
        action="crm_phonecall_categ_action"
        id="menu_crm_case_phonecall-act"
        name="Categories"
        parent="menu_crm_config_phonecall"
        sequence="0"
    />
    <record id="crm_case_phone_tree_view" model="ir.ui.view">
        <field name="name">CRM - Phone Calls Tree</field>
        <field name="model">crm.phonecall</field>
        <field name="arch" type="xml">
            <tree
                decoration-info="state in ('pending',)"
                decoration-muted="state in ('cancel','done')"
            >
                <field name="date" />
                <field name="name" />
                <field name="partner_id" />
                <button
                    icon="fa-calendar"
                    name="action_make_meeting"
                    states="open,pending"
                    string="Meeting"
                    type="object"
                />
                <button
                    attrs="{'invisible':[('opportunity_id','!=',False)]}"
                    icon="fa-hand-pointer-o"
                    name="action_button_convert2opportunity"
                    states="open,pending"
                    string="Convert to Opportunity"
                    type="object"
                />
                <field name="partner_phone" />
                <field name="user_id" />
                <field invisible="1" name="tag_ids" />
                <field invisible="1" name="create_date" />
                <field invisible="1" name="opportunity_id" />
                <field name="state" />
            </tree>
        </field>
    </record>
    <record id="crm_case_phone_form_view" model="ir.ui.view">
        <field name="name">CRM - Phone Call Form</field>
        <field name="model">crm.phonecall</field>
        <field name="arch" type="xml">
            <form string="Phone Call">
                <header>
                    <field
                        name="state"
                        nolabel="1"
                        options="{'clickable': 1}"
                        widget="statusbar"
                    />
                </header>
                <sheet string="Phone Call">
                    <div class="oe_button_box" name="button_box">
                        <button
                            attrs="{'invisible':[ '|', ('opportunity_id','!=',False), ('state', 'not in', ('open', 'done'))]}"
                            class="oe_stat_button"
                            help="Convert To Opportunity"
                            icon="fa-star"
                            name="action_button_convert2opportunity"
                            type="object"
                        >
                            <span>
                                Convert
                                <br />
                                To Opportunity
                            </span>
                        </button>
                        <button
                            class="oe_stat_button"
                            icon="fa-phone"
                            name="%(phonecall_to_phonecall_act)d"
                            type="action"
                        >
                            <span>
                                Schedule
                                <br />
                                Other Call
                            </span>
                        </button>
                        <button
                            class="oe_stat_button"
                            icon="fa-calendar fa-fw"
                            name="action_make_meeting"
                            type="object"
                        >
                            <span>
                                Schedule
                                <br />
                                A Meeting
                            </span>
                        </button>
                    </div>
                    <div class="oe_title">
                        <div class="oe_edit_only">
                            <label for="name" />
                        </div>
                        <h1>
                            <field name="name" required="1" />
                        </h1>
                        <div class="oe_edit_only">
                            <label for="partner_phone" string="Phone" />
                        </div>
                        <h2>
                            <field name="partner_phone" />
                        </h2>
                    </div>
                    <group>
                        <group>
                            <field name="date" />
                            <label for="duration" />
                            <div>
                                <field
                                    class="oe_inline"
                                    name="duration"
                                    style="vertical-align:baseline"
                                    widget="float_time"
                                />
                                <b>min(s)</b>
                            </div>
                            <field name="partner_id" />
                            <field name="partner_mobile" />
                            <field
                                context="{'opportunity_id': opportunity_id}"
                                name="opportunity_id"
                            />
                        </group>
                        <group>
                            <field
                                context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'sales_team.group_sale_salesman_all_leads']}"
                                name="user_id"
                            />
                            <field
                                colspan="1"
                                groups="sales_team.group_sale_salesman"
                                name="team_id"
                                widget="selection"
                            />
                            <field name="tag_ids" widget="many2many_tags" />
                            <field name="priority" widget="priority" />
                        </group>
                        <group
                            groups="base.group_no_one"
                            name="categorization"
                            string="Tracking"
                        >
                            <field name="campaign_id" />
                            <field name="source_id" />
                            <field name="medium_id" />
                        </group>
                        <group name="additional_info" string="Additional Info">
                            <field name="direction" widget="radio" />
                        </group>
                    </group>
                    <field name="description" placeholder="Description..." />
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" />
                    <field name="message_ids" widget="mail_thread" />
                </div>
            </form>
        </field>
    </record>
    <record id="crm_case_inbound_phone_tree_view" model="ir.ui.view">
        <field name="name">CRM - Logged Phone Calls Tree</field>
        <field name="model">crm.phonecall</field>
        <field name="arch" type="xml">
            <tree editable="top">
                <field name="date" />
                <field name="name" />
                <field name="partner_id" />
                <field invisible="1" name="partner_phone" />
                <field invisible="1" name="partner_mobile" />
                <field
                    context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'sales_team.group_sale_salesman']}"
                    name="user_id"
                />
                <field invisible="1" name="tag_ids" widget="many2many_tags" />
                <field name="direction" />
                <field name="state" />
                <field invisible="1" name="create_date" />
                <field invisible="1" name="opportunity_id" />
                <field groups="base.group_no_one" name="campaign_id" />
                <field groups="base.group_no_one" name="source_id" />
                <field groups="base.group_no_one" name="medium_id" />
                <button
                    icon="fa-phone"
                    name="%(phonecall_to_phonecall_act)d"
                    string="Schedule Other Call"
                    type="action"
                />
                <button
                    icon="fa-calendar"
                    name="action_make_meeting"
                    string="Meeting"
                    type="object"
                />
                <button
                    attrs="{'invisible':[('opportunity_id','!=',False)]}"
                    icon="fa-hand-pointer-o"
                    name="action_button_convert2opportunity"
                    states="open,pending"
                    string="Convert to Opportunity"
                    type="object"
                />
            </tree>
        </field>
    </record>
    <record id="crm_case_phone_calendar_view" model="ir.ui.view">
        <field name="name">CRM - Phone Calls Calendar</field>
        <field name="model">crm.phonecall</field>
        <field eval="2" name="priority" />
        <field name="arch" type="xml">
            <calendar
                color="user_id"
                date_delay="duration"
                date_start="date"
                string="Phone Calls"
            >
                <field name="name" />
                <field name="partner_id" />
            </calendar>
        </field>
    </record>
    <record id="view_crm_case_phonecalls_filter" model="ir.ui.view">
        <field name="name">CRM - Phone Calls Search</field>
        <field name="model">crm.phonecall</field>
        <field name="arch" type="xml">
            <search string="Search Phonecalls">
                <field name="name" string="Phonecalls" />
                <field name="date" />
                <field name="state" />
                <filter
                    domain="[('user_id', '=', uid)]"
                    name="my_phonecalls"
                    string="My Phonecalls"
                />
                <filter
                    domain="[('team_id.user_id', '=', uid)]"
                    name="my_team"
                    string="My Team"
                />
                <filter
                    domain="[('user_id','=',False)]"
                    name="unassigned"
                    string="Unassigned"
                />
                <separator />
                <filter
                    domain="[('state','in',('open','pending'))]"
                    name="current"
                    string="To Do"
                />
                <separator />
                <filter
                    domain="[('direction','=','in')]"
                    name="in_calls"
                    string="Incoming Calls"
                />
                <filter
                    domain="[('direction','=','out')]"
                    name="out_calls"
                    string="Outgoing Calls"
                />
                <separator />
                <filter date="date" name="date" string="Date" />
                <separator />
                <field name="partner_id" operator="child_of" />
                <field name="user_id" />
                <field name="opportunity_id" />
                <field
                    groups="sales_team.group_sale_manager"
                    name="team_id"
                    string="Sales Team"
                />
                <group expand="0" string="Group By">
                    <filter
                        context="{'group_by':'partner_id'}"
                        name="groupby_partner"
                        string="Partner"
                    />
                    <filter
                        context="{'group_by':'user_id'}"
                        name="groupby_responsible"
                        string="Responsible"
                    />
                    <filter
                        context="{'group_by':'create_date'}"
                        help="Creation Date"
                        name="groupby_creation"
                        string="Creation"
                    />
                    <filter
                        context="{'group_by':'date'}"
                        help="Calls Date by Month"
                        name="groupby_month"
                        string="Month"
                    />
                    <filter
                        context="{'group_by':'state'}"
                        help="Calls by status"
                        name="groupby_state"
                        string="State"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="crm_case_categ_phone0" model="ir.actions.act_window">
        <field name="name">Phone Calls</field>
        <field name="res_model">crm.phonecall</field>
        <field name="view_mode">tree,form,calendar</field>
        <field name="view_id" ref="crm_case_phone_tree_view" />
        <field name="context">{&quot;search_default_user_id&quot;:uid}</field>
        <field name="search_view_id" ref="view_crm_case_phonecalls_filter" />
    </record>
    <record id="action_crm_tag_tree_phone0" model="ir.actions.act_window.view">
        <field eval="1" name="sequence" />
        <field name="view_mode">tree</field>
        <field name="view_id" ref="crm_case_phone_tree_view" />
        <field name="act_window_id" ref="crm_case_categ_phone0" />
    </record>
    <record id="action_crm_tag_calendar_phone0" model="ir.actions.act_window.view">
        <field eval="2" name="sequence" />
        <field name="view_mode">calendar</field>
        <field name="view_id" ref="crm_case_phone_calendar_view" />
        <field name="act_window_id" ref="crm_case_categ_phone0" />
    </record>
    <record id="action_crm_tag_form_phone0" model="ir.actions.act_window.view">
        <field eval="3" name="sequence" />
        <field name="view_mode">form</field>
        <field name="view_id" ref="crm_case_phone_form_view" />
        <field name="act_window_id" ref="crm_case_categ_phone0" />
    </record>
    <menuitem
        groups="sales_team.group_sale_salesman"
        id="menu_crm_case_phone"
        name="Phone Calls"
        parent="crm.crm_menu_root"
        sequence="6"
    />
    <record id="crm_case_categ_phone_incoming0" model="ir.actions.act_window">
        <field name="name">Logged Calls</field>
        <field name="res_model">crm.phonecall</field>
        <field name="view_mode">tree,calendar</field>
        <field name="view_id" ref="crm_case_inbound_phone_tree_view" />
        <field name="domain">[]</field>
        <field name="context">
            {'search_default_state': 'done', 'default_state': 'done'}
        </field>
        <field name="search_view_id" ref="view_crm_case_phonecalls_filter" />
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to log the summary of a phone call.
            </p>
            <p>
                Odoo allows you to log inbound calls on the fly to track the
            history of the communication with a customer or to inform another
            team member.
            </p>
            <p>
                In order to follow up on the call, you can trigger a request for
            another call, a meeting or an opportunity.
            </p>
        </field>
    </record>
    <record id="action_crm_tag_tree_phone_incoming0" model="ir.actions.act_window.view">
        <field eval="1" name="sequence" />
        <field name="view_mode">tree</field>
        <field name="view_id" ref="crm_case_inbound_phone_tree_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_incoming0" />
    </record>
    <record
        id="action_crm_tag_calendar_phone_incoming0"
        model="ir.actions.act_window.view"
    >
        <field eval="2" name="sequence" />
        <field name="view_mode">calendar</field>
        <field name="view_id" ref="crm_case_phone_calendar_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_incoming0" />
    </record>
    <record id="action_crm_tag_form_phone_incoming0" model="ir.actions.act_window.view">
        <field eval="3" name="sequence" />
        <field name="view_mode">form</field>
        <field name="view_id" ref="crm_case_phone_form_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_incoming0" />
    </record>
    <menuitem
        action="crm_case_categ_phone_incoming0"
        id="menu_crm_case_phone_inbound"
        name="Logged Calls"
        parent="menu_crm_case_phone"
    />
    <record id="crm_case_categ_phone_outgoing0" model="ir.actions.act_window">
        <field name="name">Scheduled Calls</field>
        <field name="res_model">crm.phonecall</field>
        <field name="view_mode">tree,form,calendar</field>
        <field name="view_id" ref="crm_case_phone_tree_view" />
        <field name="domain">[('state','!=','done')]</field>
        <field name="search_view_id" ref="view_crm_case_phonecalls_filter" />
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">Click to schedule a call</p>
            <p>
                Odoo allows you to easily define all the calls to be done
            by your sales team and follow up based on their summary.
            </p>
            <p>
                You can use the import feature to massively import a new list of
            prospects to qualify.
            </p>
        </field>
    </record>
    <record id="action_crm_tag_tree_phone_outgoing0" model="ir.actions.act_window.view">
        <field eval="1" name="sequence" />
        <field name="view_mode">tree</field>
        <field name="view_id" ref="crm_case_phone_tree_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_outgoing0" />
    </record>
    <record
        id="action_crm_tag_calendar_phone_outgoing0"
        model="ir.actions.act_window.view"
    >
        <field eval="2" name="sequence" />
        <field name="view_mode">calendar</field>
        <field name="view_id" ref="crm_case_phone_calendar_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_outgoing0" />
    </record>
    <record id="action_crm_tag_form_phone_outgoing0" model="ir.actions.act_window.view">
        <field eval="3" name="sequence" />
        <field name="view_mode">form</field>
        <field name="view_id" ref="crm_case_phone_form_view" />
        <field name="act_window_id" ref="crm_case_categ_phone_outgoing0" />
    </record>
    <menuitem
        action="crm_case_categ_phone_outgoing0"
        groups="crm_phonecall.group_scheduled_calls"
        id="menu_crm_case_phone_outbound"
        name="Scheduled Calls"
        parent="menu_crm_case_phone"
    />
</odoo>
