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

        <menuitem id="menu_config_claim" name="Claim"
            groups="base.group_no_one"
            parent="base.menu_base_config" sequence="55"/>

        <!-- 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" eval="{'object_id': ref('model_crm_claim')}"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create a claim category.
              </p><p>
                Create claim categories to better manage and classify your
                claims. Some example of claims can be: preventive action,
                corrective action.
              </p>
            </field>
        </record>

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

        <!-- Claim Stages -->

        <record id="crm_claim_stage_tree" model="ir.ui.view">
            <field name="name">crm.claim.stage.tree</field>
            <field name="model">crm.claim.stage</field>
            <field name="arch" type="xml">
                <tree string="Claim Stages">
                    <field name="sequence"/>
                    <field name="name"/>
                </tree>
            </field>
        </record>

        <record id="crm_claim_stage_form" model="ir.ui.view">
            <field name="name">crm.claim.stage.form</field>
            <field name="model">crm.claim.stage</field>
            <field name="arch" type="xml">
                <form string="Claim Stage">
                    <group col="4">
                        <field name="name"/>
                        <field name="case_default"/>
                        <field name="sequence"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="crm_claim_stage_act" model="ir.actions.act_window">
            <field name="name">Claim Stages</field>
            <field name="res_model">crm.claim.stage</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="crm_claim_stage_tree"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to setup a new stage in the processing of the claims. 
              </p><p>
                You can create claim stages to categorize the status of every
                claim entered in the system. The stages define all the steps
                required for the resolution of a claim.
              </p>
            </field>
        </record>

        <!-- 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="arch" type="xml">
                <tree string="Claims">
                    <field name="name"/>
                    <field name="partner_id"/>
                    <field name="user_id"/>
                    <field name="date"/>
                    <field name="stage_id"/>
                    <field name="date_action_next"/>
                    <field name="action_next"/>
                    <field name="categ_id" string="Type"/>
                    <field name="date_deadline" invisible="1"/>
                    <field name="date_closed" invisible="1"/>
                </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="arch" type="xml">
                <form string="Claim">
                <header>
                    <field name="stage_id" widget="statusbar" clickable="True"/>
                </header>
                <sheet string="Claims">
                    <group>
                        <field name="name"/>
                        <field name="date"/>
                    </group>
                    <group colspan="4" col="4"  groups="base.group_user">
                        <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
                        <field name="priority" widget="priority"/>
                        <field name="section_id" groups="base.group_multi_salesteams"/>
                        <field name="date_deadline"/>
                    </group>
                    <group colspan="4" col="4">
                        <notebook>
                            <page string="Claim Description">
                                <group colspan="2" col="2" groups="base.group_user">
                                    <separator colspan="2" string="Claim Reporter"/>
                                    <field name="partner_id" string="Partner"
                                        on_change="onchange_partner_id(partner_id)"/>
                                    <field name="partner_phone"/>
                                    <field name="email_from" widget="email"/>
                                </group>
                                <group colspan="2" col="2" groups="base.group_user">
                                    <separator colspan="2" string="Responsibilities"/>
                                    <field name="user_fault"/>
                                    <field name="categ_id" options="{'no_create': True, 'no_open': True}"
                                        domain="[('object_id.model', '=', 'crm.claim')]"/>
                                    <field name="ref"/>
                                </group>
                                <separator colspan="4" string="Claim/Action Description" groups="base.group_user"/>
                                <field name="description" colspan="4" nolabel="1"/>
                            </page>
                            <page string="Follow Up" groups="base.group_user">
                                <group colspan="2" col="2">
                                    <separator colspan="2" string="Actions"/>
                                    <field name="date_action_next"/>
                                    <field name="action_next"/>
                                </group>
                                <group colspan="2" col="2" groups="base.group_no_one">
                                    <separator colspan="2" string="Dates"/>
                                    <field name="create_date"/>
                                    <field name="date_closed"/>
                                    <field name="write_date"/>
                                </group>

                                <group colspan="2" col="2">
                                    <separator colspan="2" string="Root Causes"/>
                                    <field name="cause" colspan="2" nolabel="1"/>
                                </group>
                                <group colspan="2" col="2">
                                    <separator colspan="2" string="Resolution Actions"/>
                                    <field name="type_action"/>
                                    <field name="resolution" colspan="2" nolabel="1" placeholder="Action Description..."/>
                                </group>
                            </page>
                        </notebook>
                    </group>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
                </form>
            </field>
        </record>

        <!-- Claim Calendar view -->

        <record model="ir.ui.view" id="crm_case_claims_calendar_view">
            <field name="name">Claims Actions</field>
            <field name="model">crm.claim</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Claims" date_start="date_action_next" color="user_id">
                    <field name="name"/>
                </calendar>
            </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="arch" type="xml">
                <search string="Search Claims">
                    <field name="name" string="Claims"/>
                    <separator/>
                    <filter string="Unassigned Claims" icon="terp-personal-" domain="[('user_id','=', False)]" help="Unassigned Claims" />
                    <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
                    <field name="user_id"/>
                    <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="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="Claim Month" icon="terp-go-month" domain="[]" help="Claim Date by Month" 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'}"  groups="base.group_no_one"/>
                    </group>
                </search>
            </field>
        </record>
     </data>
</openerp>
