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

        <menuitem id="menu_config_claim" name="Claim"
            groups="base.group_extended"
            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>
            <field name="help">Create claim categories to better manage and classify your claims. Some example of claims can be: preventive action, corrective action.</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="context">{'search_default_claim':1}</field>
            <field name="help">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.</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="type">tree</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="date_action_next"/>
                    <field name="action_next"/>
                    <field name="categ_id" string="Type" select="1"/>
                    <field name="stage_id" invisible="1"/>
                    <field name="date_deadline" invisible="1"/>
                    <field name="date_closed" invisible="1"/>
                    <field name="state"/>
                    <button name="case_open" string="Open"
                        states="draft,pending" type="object"
                        icon="gtk-go-forward" />
                    <button name="case_close" string="Close"
                        states="open,draft,pending" type="object"
                        icon="gtk-close" />
                </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>
                        <field name="name" />
                        <field name="date"/>


                    </group>

                    <group colspan="4" col="6">

                        <field name="user_id"/>
                        <field name="section_id" widget="selection" />

                        <group colspan="2" col="4">
                            <field name="stage_id" domain="[('section_ids','=',section_id)]"/>
                            <button name="stage_previous" string="" type="object" icon="gtk-go-back" />
                            <button name="stage_next" string="" type="object" icon="gtk-go-forward" />
                        </group>
                        <newline />
                        <field name="priority"/>
                        <field name="date_deadline"/>
                    </group>
                    <group colspan="4" col="4">
                        <notebook>
                            <page string="Claim Description">
                                <group colspan="2" col="2">
                                    <separator colspan="2" string="Claim Reporter"/>
                                    <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="email_from"/>
                                </group>
                                <group colspan="2" col="2">
                                    <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"/>
                                <field name="description" colspan="4" nolabel="1"/>
                                <separator colspan="4" string=""/>
                                <group col="8" colspan="4">
                                    <field name="state" select="1"/>
                                    <button name="case_cancel" string="Cancel"
                                        states="draft,open,pending" type="object"
                                        icon="gtk-cancel" />
                                    <button name="case_pending" string="Pending"
                                        states="draft,open" type="object"
                                        icon="gtk-media-pause" />
                                    <button name="case_open" string="Open"
                                        states="draft,pending" type="object"
                                        icon="gtk-go-forward" />
                                    <button name="case_close" string="Done"
                                        states="open,pending" type="object"
                                        icon="gtk-jump-to" />
                                    <button name="case_reset"
                                        string="Reset to Draft" states="done,cancel"
                                        type="object" icon="gtk-convert" />
                                </group>
                            </page>
                            <page string="Follow Up">
                                <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">
                                    <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>
                            <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"
                                            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="Communication &amp; 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>
                        </notebook>
                    </group>
                </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="type">calendar</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="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" />
                    <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>
                    <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'}" />
                        <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>

        <record id="base.view_crm_partner_info_History1" model="ir.ui.view">
            <field name="name">res.partner.crm.history.inherit1</field>
            <field name="model">res.partner</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/notebook/page[@string='History']" position="attributes">
                    <attribute name="invisible">False</attribute>
                </xpath>
            </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="type">form</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="priority">20</field>
            <field name="arch" type="xml">
                <data>
                    <xpath expr="/form/notebook/page[@string='History']" position="inside">
                        <field name="claims_ids" colspan="4" nolabel="1">
                            <tree string="Partners Claim" editable="bottom">
                                <field name="name"/>
                            </tree>
                        </field>
                    </xpath>
                </data>
            </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"/>


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

     </data>
</openerp>
