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



        <!-- MEMBERSHIP -->

        <!-- MEMBERSHIP/MEMBERSHIP PRODUCTS -->

        <record model="ir.ui.view" id="membership_products_tree">
            <field name="name">Membership products</field>
            <field name="model">product.product</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Membership products">
                    <field name="code"/>
                    <field name="name"/>
                    <field name="membership_date_from"/>
                    <field name="membership_date_to"/>
                    <field name="list_price" string="Membership Fee"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="membership_products_form">
            <field name="name">Memberships</field>
            <field name="model">product.product</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Membership products">
                    <field name="name"/>
                    <field name="default_code"/>
                    <field name="type"/>
                    <field name="categ_id"/>
                    <field name="membership_date_from" required="1"/>
                    <field name="membership_date_to" required="1"/>
                    <field name="list_price" string="Membership Fee"/>
                    <separator colspan="4" string="Customer Taxes:"/>
                    <field name="taxes_id" colspan="4" nolabel="1"/>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="product_normal_form_view">
            <field name="name">Membership product</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <page string="Information" position="after">
                    <page string="Membership">
                        <field name="membership" readonly="0"/>
                        <newline/>
                        <field name="membership_date_from" readonly="0" attrs="{'required':[('membership','=',True)]}"/>
                        <field name="membership_date_to" readonly="0" attrs="{'required':[('membership','=',True)]}"/>
                    </page>
                </page>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_membership_products">
            <field name="name">Memberships</field>
            <field name="res_model">product.product</field>
            <field name="domain">[('membership','=',True), ('type', '=', 'service')]</field>
            <field name="context">{'membership':True, 'type':'service'}</field>
        </record>

        <record model="ir.actions.act_window.view" id="action_membership_product_view_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="membership_products_tree"/>
            <field name="act_window_id" ref="action_membership_products"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_membership_product_view_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="membership_products_form"/>
            <field name="act_window_id" ref="action_membership_products"/>
        </record>

        <menuitem name="Association" id="base.menu_association" icon="terp-calendar" sequence="9"/>
        <menuitem name="Membership" id="menu_membership" sequence="0" parent="base.menu_association"/>
        <menuitem name="Memberships" parent="menu_membership"
            id="menu_membership_products"
            action="action_membership_products" sequence="1"/>






        <!-- MEMBERSHIP/CURRENT MEMBERS -->

        <record model="ir.ui.view" id="membership_members_tree">
            <field name="name">Members</field>
            <field name="model">res.partner</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Members">
                    <field name="name"/>
                    <field name="associate_member" attrs="{'invisible':[('membership_state', '!=', 'none')]}"/>
                    <field name="membership_start"/>
                    <field name="membership_stop"/>
                    <field name="membership_state"/>
                </tree>
            </field>
        </record>

        <record id="view_res_partner_member_filter" model="ir.ui.view">
            <field name="name">res.partner.select</field>
            <field name="model">res.partner</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <field name="category_id" position="after">
                       <filter icon="terp-personal" name="old" domain="[('membership_state', '=', 'old')]" string="Old Members" />
                       <filter icon="terp-personal" name = "invoiced" domain="[('membership_state', '=', 'invoiced')]" string="Invoiced Members"/>
                       <filter icon="terp-personal" domain="[('membership_state', '=', 'paid')]" string="Paid Members" />
                       <filter icon="terp-personal" domain="[('membership_state', '=', 'waiting')]" string="Future Members" />
                       <separator orientation="vertical"/>
                       <field name="membership_state"/>
                       <field name="membership_start"/>
                       <newline/>
               </field>
            </field>
        </record>

        <record id="view_res_partner_member_filter2" model="ir.ui.view">
            <field name="name">res.partner.select2</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="view_res_partner_member_filter"/>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <field name="membership_start" position="after">
                <newline/>
	            <group expand="0" string="Group By" colspan="10" col="8">
	                <filter string="Associate Member" name = "associate" icon="terp-personal" domain="[]" context="{'group_by':'associate_member'}"/>
                    <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'membership_state'}"/>
                    <separator orientation="vertical"/>
	                <filter string="Start Date" icon="terp-go-month" domain="[]" context="{'group_by':'membership_start'}"/>
	                <filter string="End Date" icon="terp-go-month" domain="[]" context="{'group_by':'membership_stop'}"/>
                </group>
                </field>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_membership_members">
            <field name="name">Members</field>
            <field name="res_model">res.partner</field>
            <field name="search_view_id" ref="view_res_partner_member_filter"/>
            <field name="context">{"search_default_old": 1}</field>
        </record>

        <record model="ir.actions.act_window.view" id="action_membership_members_view_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="membership_members_tree"/>
            <field name="act_window_id" ref="action_membership_members"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_membership_members_view_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="act_window_id" ref="action_membership_members"/>
        </record>

        <menuitem name="Members" parent="menu_membership" id="menu_members" sequence="2" action="action_membership_members"/>

        <!-- PARTNERS -->

        <record model="ir.ui.view" id="view_partner_tree">
            <field name="name">res.partner.tree.form.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_tree"/>
            <field name="arch" type="xml">
                <tree string="Partners">
                    <field name="category_id" position="after"/>
                    <field name="membership_state"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_partner_form">
            <field name="name">res.partner.form.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Membership">
                        <group colspan="2" col="2">
                            <group colspan="4" col="3">
                            <field name="free_member"/>
                            <button name="%(action_membership_invoice_view)d" type="action" string="Join Membership" icon="gtk-apply"/>
                            <field colspan="4" name="associate_member" attrs="{'invisible':[('membership_state', '!=', 'none')], 'readonly':[('free_member','=',True)]}"/>
                            <field colspan="4" name="membership_state"/>
                            </group>
                        </group>
                        <group colspan="2" col="2">
                            <field name="membership_start"/>
                            <field name="membership_stop"/>
                            <field name="membership_cancel"/>
                        </group>
                        <field name="member_lines" nolabel="1" colspan="4" readonly="1">
                            <tree string="Memberships">
                                <field name="date"/>
                                <field name="membership_id"/>
                                <field name="member_price"/>
                                <field name="account_invoice_id"/>
                                <field name="state"/>
                            </tree>
                            <form string="Memberships">
                                <field name="date"/>
                                <field name="member_price"/>
                                <field name="membership_id"/>
                                <field name="account_invoice_id"/>
                                <field name="state" colspan="4"/>
                            </form>
                        </field>

                    </page>
                </notebook>
            </field>
        </record>

        <!-- MEMBERSHIP/REPORTING -->
        <menuitem name="Reporting" id="base.menu_report_association" parent="base.menu_association" sequence="20"/>

<!-- View for product.product object inherited from product module................ -->
        <record model="ir.ui.view" id="view_product_form_inherit1">
            <field name="name">product.normal.form</field>
            <field name="type">form</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <field name="list_price" position="after">
                    <field name="member_price"/>
                </field>
            </field>
        </record>

    </data>
</openerp>
