<?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"/>
                    <field name="state"/>
                </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">
                    <field name="name"/>
                    <field name="case_default"/>
                    <field name="sequence"/>
                    <field name="state"/>
                    <field name="case_refused"/>
                    <field name="fold"/>
                </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" colors="blue:state=='pending' and not(date_deadline and (date_deadline &lt; current_date));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="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"/>
                    <field name="state" groups="base.group_no_one"/>
                </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" version="7.0">
                <header>
                    <button name="case_close" string="Settle" type="object" class="oe_highlight"
                            states="draft,open,pending" groups="base.group_user"/>
                    <button name="case_cancel" string="Reject" type="object" groups="base.group_user"
                            states="draft,open,pending"/>
                    <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"/>
                        <field name="priority"/>
                        <field name="section_id"/>
                        <field name="date_deadline"/>
                        <field name="state" groups="base.group_no_one"/>
                    </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" widget="selection"
                                        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"/>
                                </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"/>
                    <filter icon="terp-check" string="New" name="current" domain="[('state','=','draft')]" help="New Claims"/>
                    <filter icon="terp-camera_test" string="In Progress" domain="[('state','=','open')]" help="In Progress Claims"/>
                    <filter icon="terp-gtk-media-pause" string="Pending" domain="[('state','=','pending')]"/>
                    <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="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}" groups="base.group_no_one"/>
                        <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'}"  groups="base.group_no_one"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="view_claim_partner_info_form1" model="ir.ui.view">
            <field name="name">res.partner.claim.info.form</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="priority">20</field>
            <field name="arch" type="xml">
                <xpath expr="//page[@name='page_history']" position="attributes">
                    <attribute name="invisible">False</attribute>
                </xpath>
                <xpath expr="//page[@name='page_history']" position="inside">
                    <group name="grp_claim" string="Claims">
                        <field name="claims_ids" colspan="4" nolabel="1">
                            <tree string="Partners Claim" editable="bottom">
                                <field name="name"/>
                            </tree>
                        </field>
                    </group>
                </xpath>
            </field>
        </record>

        <act_window
            context="{'search_default_partner_id': [active_id], 'default_partner_id': active_id}"
            id="act_claim_partner"
            name="Claims"
            view_mode="tree,form"
            res_model="crm.claim"
            src_model="res.partner"/>

     </data>
</openerp>
