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



        <!-- MEMBERSHIP -->

        <!-- MEMBERSHIP/MEMBERSHIP PRODUCTS -->

        <record model="ir.ui.view" id="membership_product_search_form_view">
            <field name="name">membership.product.search.form</field>
            <field name="model">product.product</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Membership Products">
                   <filter string="Inactive" icon="terp-gdu-smart-failing" domain="[('active','=',0)]"/>
                   <separator orientation="vertical"/>
                   <field name="code"/>
                   <field name="name"/>
                   <field name="categ_id" widget="selection" operator="child_of"/>
                   <newline/>
                   <group  expand='0' string='Group by...' groups="base.group_extended">
                       <filter string='Category' icon="terp-stock_symbol-selection" domain="[]" context="{'group_by' : 'categ_id'}" />
                       <separator orientation="vertical"/>
                       <filter string='Date From' icon="terp-go-month" domain="[]" context="{'group_by' : 'membership_date_from'}" />
                   </group>
                </search>
            </field>
        </record>

        <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"/>
                    <field name="categ_id" invisible="1"/>
                    <field name="uom_id" invisible="1"/>
                    <field name="type" invisible="1"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="membership_products_form">
            <field name="name">Membership Products</field>
            <field name="model">product.product</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Membership products">
                  <group col="6">
                      <field name="name"/>
                      <field name="default_code"/>
                      <field name="active"/>
                      <field name="membership" invisible="1"/>
                      <field name="membership_date_from" required="1"/>
                      <field name="membership_date_to" required="1"/>
                      <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                    </group>
                    <notebook colspan="4">
                      <page string="General">
                        <separator string="Accounting Info" colspan="2"/>
                        <separator string="Categorization" colspan="2"/>
                        <field name="list_price" string="Membership Fee"/>
                        <field name="type" />
                        <field name="property_account_income" domain="[('type', '!=', 'view')]"/>
                        <field name="categ_id"/>
                        <separator string="Sale Taxes" colspan="2"/>
                        <newline/>
                        <field name="taxes_id" nolabel="1" colspan="4"/>
                      </page>
                      <page string="Description">
                            <separator string="Description"/>
                            <field colspan="4" name="description" nolabel="1"/>
                            <separator string="Sale Description"/>
                            <field colspan="4" name="description_sale" nolabel="1"/>
                            <separator string="Purchase Description"/>
                            <field colspan="4" name="description_purchase" nolabel="1"/>
                      </page>
                    </notebook>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="product_normal_form_view">
            <field name="name">Membership Products</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">Membership Products</field>
            <field name="res_model">product.product</field>
            <field name="domain">[('membership','=',True), ('type', '=', 'service')]</field>
            <field name="context">{'membership':True, 'type':'service'}</field>
            <field name="search_view_id" ref="membership_product_search_form_view"/>
        </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="Membership Products"
                  parent="menu_membership"
                  id="menu_membership_products"
                  action="action_membership_products"
                  sequence="1"
                  groups="base.group_partner_manager"/>


        <!-- 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="membership_state"/>
                    <field name="associate_member" attrs="{'invisible':[('membership_state', '!=', 'none')]}"/>
                    <field name="membership_start"/>
                    <field name="membership_stop"/>
                    <field name="user_id" invisible="1"/>
                </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">
            	<search string="Membership Partners">
		          	<filter string="Customers" name="customer" icon="terp-personal" domain="[('customer','=',1)]" help="Customer Partners"/>
		            <filter string="Suppliers" name="supplier" icon="terp-personal" domain="[('supplier','=',1)]" help="Supplier Partners"/>
	          		<separator orientation="vertical"/>
		          	<filter icon="terp-personal" name="all_non_members" domain="[('membership_state', 'in', ['none','canceled','old','waiting'])]" string="All non Members" help="None/Canceled/Old/Waiting"/>
		          	<filter icon="terp-personal" name="all_members" domain="[('membership_state', 'in', ['invoiced','paid','free'])]" string="All Members" help="Invoiced/Paid/Free"/>
	          		<separator orientation="vertical"/>
	                <field name="membership_stop" string="End Membership Date"/>
	                <field name="membership_start" invisible="1"/>
	                <newline/>
	                <group expand="0" string="Group By..." colspan="10" col="8">
	                    <filter string="Salesman" icon="terp-personal" domain="[]" context="{'group_by' : 'user_id'}" />
	              	    <filter string="Associate Member" name = "associate" icon="terp-partner" domain="[]" context="{'group_by':'associate_member'}"/>
	              		<separator orientation="vertical"/>
	                	<filter string=" Membership State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'membership_state'}"/>
	                	<separator orientation="vertical"/>
	                	<filter string="Start Date" help="Starting Date Of Membership" icon="terp-go-month" domain="[]" context="{'group_by':'membership_start'}"/>
	              		<filter string="End Date" help="Ending Date Of Membership" icon="terp-go-month" domain="[]" context="{'group_by':'membership_stop'}"/>
	            	</group>
	           </search>
            </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_all_members": 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="view_id" ref="base.view_partner_form"/>
            <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" attrs="{'readonly':[('free_member','=',True)]}" icon="gtk-apply"/>
                            <field colspan="4" name="associate_member" attrs="{'readonly':[('membership_state','!=', 'none')]}"/>
                            <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>
