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

        <menuitem id="menu_config_claim" name="Claim"
            groups="base.group_extended,base.group_system"
            parent="base.menu_base_config" sequence="6" />

        <!-- Claims categories  -->

        <record id="crm_claim_categ_action" model="ir.actions.act_window">
            <field name="name">Claim 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.claim')]</field>
            <field name="context">{'object_id':'crm.claim'}</field>
        </record>

        <menuitem action="crm_claim_categ_action" name="Categories"
            id="menu_crm_case_claim-act" parent="menu_config_claim" />


        <!-- Claim Stages -->

        <record id="crm_claim_stage_act" model="ir.actions.act_window">
            <field name="name">Claim 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="domain">[('object_id.model', '=', 'crm.claim')]</field>
            <field name="context">{'object_id':'crm.claim'}</field>
        </record>

         <menuitem action="crm_claim_stage_act" name="Stages"
                id="menu_crm_claim_stage_act" parent="menu_config_claim" />

        <!-- Claims    -->

        <record model="ir.ui.view" id="crm_case_claims_tree_view">
            <field name="name">CRM - Claims Tree</field>
            <field name="model">crm.claim</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Claims" colors="blue:state=='pending';black:state=='open';gray:state in ('close', 'cancel');red:date_deadline and (date_deadline &lt; current_date)">
                    <field name="name"/>
                    <field name="partner_id"/>
                    <field name="user_id" />
                    <field name="section_id"/>
                    <field name="date" string="Claim Date"/>
                    <field name="date_deadline" string="Deadline"/>
                    <field name="date_closed" string="Closure Date"/>
                    <field name="categ_id" string="Type" select="1"/>
                    <field name="stage_id" invisible="1"/>
                    <field name="state"/>
                    <button name="case_open" string="Open"
                        states="draft,pending" type="object"
                        icon="gtk-go-forward" />
                    <button name="case_pending" string="Pending"
                        states="draft,open" type="object"
                        icon="gtk-media-pause" />
                    <button name="case_close" string="Close"
                        states="open,draft,pending" type="object"
                        icon="gtk-close" />
                    <button name="case_cancel" string="Cancel"
                        states="draft,open,pending" type="object"
                        icon="gtk-cancel" />
                    <button name="case_reset" string="Reset to Draft"
                        states="done,cancel" type="object" icon="gtk-convert" />
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="crm_case_claims_form_view">
            <field name="name">CRM - Claims Form</field>
            <field name="model">crm.claim</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Claims">

                    <group colspan="4" col="4">
                        <group colspan="1" col="2">
                            <field name="name" />
                        </group>
                        <group colspan="1" col="2">
                            <field name="date" string="Date of Claim"/>
                        </group>
                        <group colspan="1" col="2">
                            <field name="date_deadline" string="Deadline"/><newline/>
                        </group>
                    </group>
                    <group colspan="4" col="4">

                        <notebook>
                            <page string="Claim Info">
                                <separator colspan="4" string="Communication"/>
                                <group colspan="4" col="4">
                                    <field name="partner_id" string="Partner"
                                    on_change="onchange_partner_id(partner_id)" />
                                    <field name="partner_address_id" string="Contact"
                                    on_change="onchange_partner_address_id(partner_address_id, email_from)" />
                                    <field name="partner_phone"/>
                                    <field name="partner_mobile"/>
                                    <field name="email_from"/>
                                </group>
                                <separator colspan="4" string="Status and Categorization"/>
                                <group colspan="4" col="6">
                                    <field name="user_id" string="Responsible"/>
                                    <field name="section_id" widget="selection"/>
                                    <label string="Stage: " align="1.0"/>
                                    <group colspan="1" col="3">
                                        <field name="stage_id" nolabel="1"
                                            on_change="onchange_stage_id(stage_id)"
                                            domain="[('section_id','=',section_id), ('object_id.model', '=', 'crm.claim')]" />
                                        <button name="stage_previous" string="" type="object" icon="gtk-go-back" />
                                        <button icon="gtk-go-forward" string="" name="stage_next" type="object"/>
                                    </group>
                                    <field name="categ_id" select="1" widget="selection"
                                    domain="[('object_id.model', '=', 'crm.claim')]" />
                                    <field name="type_id" string="Type of Action" select="1"
                                    domain="[('object_id.model', '=', 'crm.claim')]" />
                                    <field name="priority"/>
                                </group>
                                <separator colspan="4" string="References"/>
                                <group colspan="4" col="4">
                                    <field name="ref"/>
                                    <field name="ref2"/>
                                </group>
                                <separator colspan="4" string="Claim/Action Description"/>
                                <field name="description" colspan="4" nolabel="1"/>
                                <separator colspan="4" string=""/>
                                <group col="8" colspan="4">
                                    <field name="state" select="1"/>
                                    <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_close" string="Done"
                                    states="open,draft,pending" type="object"
                                    icon="gtk-jump-to" />
                                    <button name="case_cancel" string="Cancel"
                                    states="draft,open,pending" type="object"
                                    icon="gtk-cancel" />
                                    <button name="case_reset"
                                    string="Reset to Draft" states="done,cancel"
                                    type="object" icon="gtk-convert" />
                                </group>
                            </page>
                            <page string="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">
                                    <tree string="History">
                                        <field name="display_text" string="History Information"/>
                                        <button
                                            string="Reply"
                                            name="%(crm.action_crm_send_mail)d"
                                            context="{'mail':'reply', 'model': 'crm.claim', 'include_original' : True}"
                                            icon="terp-mail-replied" type="action" attrs="{'invisible': [('history', '!=', True)]}" />
                                    </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.claim', '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.claim'}"
                                    icon="terp-mail-message-new" type="action" />
                            </page>
                            <page string="Extra Info" groups="base.group_extended">
                                <field name="id" select="1"/>
                                <field name="active"/>
                                <field name="canal_id"/>
                                <separator colspan="4" string="Dates"/>
                                <field name="create_date"/>
                                <field name="date_closed"/>
                            </page>
                        </notebook>
                    </group>
                </form>
            </field>
        </record>

        <!-- Claim Calendar view -->

        <record model="ir.ui.view" id="crm_case_claims_calendar_view">
            <field name="name">CRM - Claims Calendar</field>
            <field name="model">crm.claim</field>
            <field name="type">calendar</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Claims" date_start="date" color="user_id">
                    <field name="name"/>
                    <field name="partner_name"/>
                    <field name="categ_id"/>
                </calendar>
            </field>
        </record>

        <!-- Claim Graph view -->

        <record model="ir.ui.view" id="crm_case_graph_view_stage_cost">
            <field name="name">CRM -Graph</field>
            <field name="model">crm.claim</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Cases By Stage and Estimates" type="bar" orientation="vertical">
                    <field name="stage_id"/>
                    <field name="planned_cost" operator="+"/>
                    <field name="planned_revenue" operator="+"/>
                </graph>
            </field>
        </record>

        <!-- Crm claim Search view -->

        <record id="view_crm_case_claims_filter" model="ir.ui.view">
            <field name="name">CRM - Claims Search</field>
            <field name="model">crm.claim</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Claims">
                   <filter icon="terp-check" string="Current" name="current"
                       domain="[('state','in',('draft', 'open'))]"
                       separator="1" help="Draft and Open Claims" default="1"
                   />
                   <filter icon="terp-camera_test"
                       string="In Progress"
                       domain="[('state','=','open')]"
                       separator="1" help="In Progress Claims"
                   />
                   <filter icon="terp-gtk-media-pause"
                       string="Pending"
                       domain="[('state','=','pending')]"
                       separator="1" help="All pending Claims"
                   />
                   <separator orientation="vertical"/>
                   <field name="name" select='1'/>
                   <field name="partner_id" select="1"/>
                   <field name="user_id" select="1" widget="selection">
                           <filter icon="terp-personal-"
                               domain="[('user_id','=', False)]"
                               help="Unassigned Claims" />
                   </field>
                   <field name="section_id" select="1"
                       widget="selection"/>
                   <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="Stage" icon="terp-stage"
                            domain="[]" context="{'group_by':'stage_id'}" />
                        <filter string="Type" icon="terp-stock_symbol-selection"
                            domain="[]" context="{'group_by':'categ_id'}" />
                       <filter string="State"
                            icon="terp-stock_effects-object-colorize"
                            domain="[]" context="{'group_by':'state'}" />
                        <separator orientation="vertical"/>
                        <filter string="Claim Date" icon="terp-go-month"
                           domain="[]" help="Claim Date"
                           context="{'group_by':'date'}" />
                       <filter string="Deadline" icon="terp-go-month"
                           domain="[]"
                           context="{'group_by':'date_deadline'}" />
                       <filter string="Closure" icon="terp-go-month"
                           domain="[]" help="Date Closed"
                           context="{'group_by':'date_closed'}" />
                   </group>
               </search>
           </field>
        </record>

        <act_window
            domain="[('partner_id', '=', active_id)]"
            context="{'default_partner_id': active_id}"
            id="act_claim_partner"
            name="Report a Claim"
            view_mode="form,tree"
            res_model="crm.claim"
            src_model="res.partner"/>


        <act_window
            domain="[('partner_address_id', '=', active_id)]"
            context="{'default_partner_address_id': active_id}"
            id="act_claim_partner_address"
            name="Report a Claim"
            view_mode="form,tree"
            res_model="crm.claim"
            src_model="res.partner.address"/>

     </data>
</openerp>
