<?xml version="1.0"?>
<openerp>
    <data>
           <!-- Fund Raising Configuration Menu -->
        <menuitem id="menu_config_fundrising" name="Fund Raising"
            groups="base.group_extended"
            parent="base.menu_base_config" sequence="8" />

        <!-- Fund Raising Categories Form View -->

        <record id="crm_fund_categ_action" model="ir.actions.act_window">
            <field name="name">Fundraising 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.fundraising')]</field>
            <field name="context">{'object_id':'crm.fundraising'}</field>
            <field name="help">Manage and define the fund raising categories you want to be maintained in the system.</field>
        </record>

        <menuitem action="crm_fund_categ_action" name="Categories"
            id="menu_crm_case_fundraising-act" groups="base.group_extended"
            parent="menu_config_fundrising" />

        <!-- Fund Stage Form View -->

        <record id="crm_fundraising_stage_act" model="ir.actions.act_window">
            <field name="name">Fundraising 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_fundraising':1}</field>
            <field name="help">Create and manage fund raising activity categories you want to be maintained in the system.</field>
        </record>

        <!-- Fund Raising Tree View -->

        <record model="ir.ui.view" id="crm_case_tree_view_fund">
            <field name="name">CRM - Funds Tree</field>
            <field name="model">crm.fundraising</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Funds Tree"
                    colors="blue:state=='pending';grey:state in ('cancel', 'done')">
                    <field name="name" string="Fund Description" />
                    <field name="categ_id" />
                    <field name="type_id" string="Payment Mode" />
                    <field name="planned_cost" string="Amount" />
                    <field name="probability" />
                    <field name="user_id" />
                    <field name="state" />
                    <field name="partner_id" invisible="1"/>
                    <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"
                        states="open,draft,pending" type="object"
                        groups="base.group_extended"
                        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>

        <!-- Fund Raising Form View -->

        <record model="ir.ui.view" id="crm_case_form_view_fund">
            <field name="name">CRM - Funds Form</field>
            <field name="model">crm.fundraising</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Funds Form">
                    <group colspan="4" col="6">
                        <field name="name" select="1" string="Name"/>
                        <field name="section_id" colspan="1" widget="selection"/>
                        <field name="user_id" string="Responsible"/>
                        <field name="date"/>
                        <field name="categ_id" select="1" widget="selection" domain="[('object_id.model', '=', 'crm.fundraising')]"/>
                        <field name="type_id" string="Payment Mode" select="1" widget="selection"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Funds">
                            <group colspan="2" col="2">
                                <separator colspan="4" string="Communication"/>
                                <field name="partner_id" select="1"
                                    on_change="onchange_partner_id(partner_id, email_from)"
                                    colspan="2" />
                                <field name="partner_address_id"
                                    string="Contact"
                                    on_change="onchange_partner_address_id(partner_address_id, email_from)"
                                    colspan="1" />
                                <field name="email_from" colspan="2"/>
                            </group>
                            <group colspan="2" col="2">
                                <separator colspan="4" string="Estimates"/>
                                <field name="planned_cost"/>
                                <field name="planned_revenue"/>
                                <field name="probability"/>
                            </group>
                            <separator colspan="4" string="Notes"/>
                                <field name="description" nolabel="1" colspan="4"/>
                            <separator colspan="4"/>
                            <group col="8" colspan="4">
                                <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"
                                    states="open,draft,pending" type="object"
                                    groups="base.group_extended"
                                    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" />
                            </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">
                                <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.fundraising', '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.fundraising', '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.fundraising'}"
                                icon="terp-mail-message-new" type="action" />
                        </page>
                        <page string="Extra Info" groups="base.group_extended">
                            <group col="2" colspan="2">
                                <separator colspan="4" string="Misc"/>
                                <field name="active"/>
                                <field name="id" select="1"/>
                                <field name="priority" string="Priority"/>
                            </group>
                            <group col="2" colspan="2">
                                <separator colspan="4" string="Dates"/>
                                <field name="create_date"/>
                                <field name="date_closed"/>
                                <field name="duration"/>
                            </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>

        <!-- Fund Raising Calendar View -->

        <record model="ir.ui.view" id="crm_case_calendar_view_fund">
            <field name="name">CRM - Funds Calendar</field>
            <field name="model">crm.fundraising</field>
            <field name="type">calendar</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Funds" date_start="date" color="user_id" date_delay="duration">
                    <field name="name"/>
                    <field name="partner_id"/>
                </calendar>
            </field>
        </record>

        <!-- Fund Raising Graph View -->

        <record model="ir.ui.view" id="crm_case_graph_view_fund">
            <field name="name">CRM - Funds Graph</field>
            <field name="model">crm.fundraising</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Funds by Categories" type="bar" orientation="horizontal">
                    <field name="categ_id"/>
                    <field name="planned_cost" operator="+"/>
                    <field name="state" group="True"/>
                </graph>
            </field>
        </record>

        <!-- Fund Raising Search View -->
        <record id="view_crm_case_fund_filter" model="ir.ui.view">
                <field name="name">CRM - Funds Search</field>
                <field name="model">crm.fundraising</field>
                <field name="type">search</field>
                <field name="arch" type="xml">
                    <search string="Search Funds">
                        <group>
                            <filter icon="terp-check" string="Current"
                                domain="[('state','in',('draft', 'open'))]" name="current"
                                help="Current Funds" />
                            <filter icon="terp-camera_test" string="Open"
                                domain="[('state','=','open')]"
                                help="Open Funds" />
                            <filter icon="terp-gtk-media-pause"
                                string="Pending"
                                domain="[('state','=','pending')]"
                                help="Pending Funds" />
                            <separator orientation="vertical" />
                            <field name="state" select="1" />
                            <field name="name" select='1'
                                string="Fund Description" />
                            <field name="user_id" select="1"
                                widget="selection">
                                <filter icon="terp-personal-"
                                    domain="[('user_id','=', False)]"
                                    help="Unassigned" />
                            </field>
                            <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>
                        </group>
                        <newline/>
                        <group expand="0" string="Group By...">
                            <filter string="Partner" icon="terp-partner"
                                domain="[]"
                                context="{'group_by':'partner_id'}" />
                            <filter string="Responsible" icon="terp-personal"
                                domain="[]"
                                context="{'group_by':'user_id'}" />
                            <separator orientation="vertical" />
                            <filter string="Category" help="Fund Category"
                                icon="terp-stock_symbol-selection" domain="[]"
                                context="{'group_by':'categ_id'}" />
                            <filter string="Payment Mode" help="Payment Mode"
                                icon="terp-dolar" domain="[]"
                                context="{'group_by':'type_id'}" />
                            <separator orientation="vertical" />
                            <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]"
                                context="{'group_by':'state'}" />
                        </group>
                    </search>
                </field>
            </record>
    </data>
</openerp>
