<?xml version="1.0"?>
<openerp>
    <data>
       <!-- Helpdesk Support Categories Configuration Menu-->
       <menuitem id="menu_config_helpdesk" name="Helpdesk"
        groups="base.group_extended"
        parent="base.menu_base_config" sequence="7" />

        <!-- Helpdesk Support Categories Form View -->

        <record id="crm_helpdesk_categ_action" model="ir.actions.act_window">
            <field name="name">Helpdesk Categories</field>
            <field name="res_model">crm.case.categ</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="crm.crm_case_categ_tree-view"/>
            <field name="domain">[('object_id.model', '=', 'crm.helpdesk')]</field>
            <field name="context">{'object_id':'crm.helpdesk'}</field>
            <field name="help">Create and manage helpdesk categories to better manage and classify your support requests.</field>
        </record>

        <menuitem action="crm_helpdesk_categ_action" name="Categories"
            id="menu_crm_case_helpdesk-act" parent="menu_config_helpdesk" />

        <!--  Helpdesk Support Form View -->

        <record model="ir.ui.view" id="crm_case_form_view_helpdesk">
            <field name="name">CRM - Helpdesk Support Form</field>
            <field name="model">crm.helpdesk</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Helpdesk Support">
                    <group colspan="4" col="7">
                        <field name="name" select="1" string="Query"/>
                        <field name="section_id" widget="selection"/>
                        <field name="user_id" select="1"/>
                        <button name="remind_user"
                            states="open,pending"
                            string="Send Reminder" type="object"
                            icon="gtk-go-forward" />
                        <field name="date" select="1"/>
                        <field name="date_deadline"/>
                    </group>
                    <notebook colspan="4">
                        <page string="General">
                            <group col="3" colspan="2">
                                <separator colspan="4" string="Communication"/>
                                <field name="partner_id" colspan="2"
                                    on_change="onchange_partner_id(partner_id, email_from)"
                                    select="1" />
                                <field name="partner_address_id" colspan="2"
                                    on_change="onchange_partner_address_id(partner_address_id, email_from)"
                                />
                                <newline/>
                                <field name="email_from" colspan="2"/>
                                <button name="remind_partner"
                                    states="open,pending"
                                    string="Send Reminder" type="object"
                                    icon="gtk-go-forward" />
                            </group>

                            <group col="2" colspan="2">
                                <separator colspan="4" string="Categorization"/>
                                <field name="priority"/>
                                <field name="categ_id" context="{'object_id':'crm.helpdesk'}"/>
                                <field name="channel_id"/>
                            </group>

                            <separator colspan="4" string="Notes"/>
                            <field name="description" colspan="4" nolabel="1" />
                            <separator colspan="4"/>
                            <group col="8" colspan="4">
                                <field name="state" select="1"/>
                                <button name="case_cancel"
                                    states="draft,open,pending" string="Cancel"
                                    type="object" icon="gtk-cancel" />
                                <button name="case_open"
                                    states="draft,pending" string="Open"
                                    type="object" icon="gtk-go-forward" />
                                <button name="case_pending"
                                    states="draft,open" string="Pending"
                                    type="object" icon="gtk-media-pause" />
                                <button name="case_escalate"
                                    states="open,draft,pending"
                                    string="Escalate" type="object"
                                    icon="gtk-go-up" />
                                <button name="case_close"
                                    states="open,draft,pending" string="Close"
                                    type="object" icon="gtk-jump-to" />
                                <button name="case_reset"
                                    states="done,cancel"
                                    string="Reset to Draft" type="object"
                                    icon="gtk-convert" />
                            </group>
                        </page>
                        <page string="Communication &amp; History" groups="base.group_extended">
                            <group colspan="4">
                                <field colspan="4" name="email_cc" string="Global CC" widget="char"/>
                            </group>
                            <field name="message_ids" colspan="4" nolabel="1" mode="tree,form" readonly="1">
                                <tree string="History">
                                    <field name="display_text" string="History Information"/>
                                    <field name="history" invisible="1"/>
                                    <button
                                        string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
                                        name="%(crm.action_crm_send_mail)d"
                                        context="{'mail':'reply', 'model': 'crm.helpdesk', 'include_original' : True}"
                                        icon="terp-mail-replied" type="action" />
                                </tree>
                                <form string="History">
                                    <group col="4" colspan="4">
                                        <field name="email_from"/>
                                        <field name="date"/>
                                        <field name="email_to" widget="char" size="512"/>
                                        <field name="email_cc" widget="char" size="512"/>
                                        <field name="name" colspan="4" widget="char" size="512"/>
                                        <field name="history" invisible="1"/>
                                    </group>
                                    <notebook colspan="4">
                                        <page string="Details">
                                            <group attrs="{'invisible': [('history', '!=', True)]}">
                                                <field name="description" colspan="4" nolabel="1" height="250"/>
                                                <button colspan="4"
                                                    string="Reply"
                                                    name="%(crm.action_crm_send_mail)d"
                                                    context="{'mail':'reply', 'model': 'crm.helpdesk', 'include_original' : True}"
                                                    icon="terp-mail-replied" type="action" />
                                             </group>
                                            <group attrs="{'invisible': [('history', '=', True)]}">
                                                <field name="display_text" colspan="4" nolabel="1"  height="250"/>
                                            </group>
                                        </page>
                                        <page string="Attachments">
                                            <field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
                                        </page>
                                    </notebook>
                                </form>
                            </field>
                             <button string="Add Internal Note"
                                name="%(crm.action_crm_add_note)d"
                                context="{'model': 'crm.lead' }"
                                icon="terp-document-new" type="action" />
                            <button string="Send New Email"
                                name="%(crm.action_crm_send_mail)d"
                                context="{'mail':'new', 'model': 'crm.helpdesk'}"
                                icon="terp-mail-message-new" type="action" />
                        </page>
                        <page string="Extra Info" groups="base.group_extended">
                            <group colspan="2" col="2">
                                <separator colspan="4" string="Dates"/>
                                <field name="create_date"/>
                                <field name="write_date"/>
                                <field name="date_closed"/>
                            </group>
                            <group colspan="2" col="2">
                                <separator colspan="4" string="Misc"/>
                                <field name="id" select="1"/>
                                <field name="active"/>
                            </group>
                            <group colspan="2" col="2">
                                <separator colspan="4" string="Estimates"/>
                                <field name="planned_cost"/>
                            </group>
                            <newline/>
                            <group colspan="4" col="2">
                                <separator colspan="4" string="References"/>
                                <field colspan="4" name="ref"/>
                                <field colspan="4" name="ref2"/>
                            </group>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <!-- Helpdesk Support Tree View  -->

        <record model="ir.ui.view" id="crm_case_tree_view_helpdesk">
            <field name="name">CRM - Helpdesk Support Tree</field>
            <field name="model">crm.helpdesk</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Helpdesk Support Tree"
                    colors="black:state=='open';blue:state=='pending';gray:state in ('cancel','done')">
                    <field name="name" string="Query" />
                    <field name="partner_id" string="Partner"/>
                    <field name="date" string="Date"/>
                    <field name="date_deadline"/>
                    <field name="user_id"/>
                    <field name="section_id"/>
                    <field name="priority"/>
                    <field name="state"/>
                    <button name="case_cancel" string="Cancel"
                        states="draft,open,pending" type="object"
                        icon="gtk-cancel" />
                    <button name="case_open" string="Open"
                        states="draft,pending" type="object"
                        icon="gtk-go-forward" />
                    <button name="case_pending" string="Pending"
                        states="draft,open" type="object"
                        icon="gtk-media-pause" />
                    <button name="case_escalate" string="Escalate"
                        groups="base.group_extended"
                        states="open,draft,pending" type="object"
                        icon="gtk-go-up" />
                    <button name="case_close" string="Done"
                        states="open,draft,pending" type="object"
                        icon="gtk-close" />
                    <button name="case_reset" string="Reset to Draft"
                        states="done,cancel" type="object" icon="gtk-convert" />
                </tree>
            </field>
        </record>

        <!--  Helpdesk Support Calendar View -->

        <record model="ir.ui.view" id="crm_case_helpdesk_calendar_view">
            <field name="name">CRM - Helpdesk Support Calendar</field>
            <field name="model">crm.helpdesk</field>
            <field name="type">calendar</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Helpdesk Supports" date_start="date" color="user_id" date_delay="duration">
                    <field name="name"/>
                    <field name="partner_id"/>
                    <field name="categ_id"/>
                </calendar>
            </field>
        </record>

        <!-- Helpdesk Support Search View  -->

        <record id="view_crm_case_helpdesk_filter" model="ir.ui.view">
            <field name="name">CRM - Helpdesk Search</field>
            <field name="model">crm.helpdesk</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Helpdesk">
                    <filter icon="terp-go-today" string="Today"
                        separator="1"
                        domain="[('date::date','=',time.strftime('%%Y-%%m-%%d'))]"
                        help="Todays's Helpdesk Requests"
                        />
                    <filter icon="terp-go-week"
                        string="7 Days" separator="1"
                        help="Helpdesk requests during last 7 days"
                        domain="[('date','&lt;', time.strftime('%%Y-%%m-%%d')), ('date','&gt;=',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d'))]"
                        />
                    <separator orientation="vertical"/>
                    <field name="name" select='1' string="Query"/>
                    <field name="partner_id" />
                    <field name="user_id" select="1" widget="selection"/>
                    <field name="section_id" select="1" widget="selection" string="Sales Team">
                        <filter icon="terp-personal+" groups="base.group_extended"
                            domain="['|', ('section_id', '=', context.get('section_id')), '|', ('section_id.user_id','=',uid), ('section_id.member_ids', 'in', [uid])]"
                            help="My Sales Team(s)" />
                    </field>
                    <newline/>                         
                    <group expand="0" string="Group By...">
                        <filter string="Partner" icon="terp-partner"
                            domain="[]" help="Partner"
                            context="{'group_by':'partner_id'}" />
                        <filter string="Responsible" icon="terp-personal"
                            domain="[]" help="Responsible User"
                            context="{'group_by':'user_id'}" />
                        <filter string="Sales Team" icon="terp-personal+"
                            domain="[]" help="Sales Team"
                            context="{'group_by':'section_id'}" />
                        <separator orientation="vertical"/>
                        <filter string="Priority" icon="terp-rating-rated"
                            domain="[]" context="{'group_by':'priority'}" />
                        <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]"
                            context="{'group_by':'state'}" />
                        <separator orientation="vertical"/>
                        <filter string="Date" icon="terp-go-month"
                            domain="[]" help="Request Date"
                            context="{'group_by':'date'}" />
                        <filter string="Deadline" icon="terp-go-month"
                            domain="[]"
                            context="{'group_by':'date_deadline'}" />
                    </group>
                </search>
            </field>
        </record>

    </data>
</openerp>
