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


    <record model="ir.ui.view" id="purchase_order_form_inherit">
        <field name="name">purchase.order.form.inherit</field>
        <field name="type">form</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
            <field name="shipped" position="after">
                <field name="requisition_id" groups="base.group_extended"/>
            </field>
        </field>
    </record>

    <record model="ir.ui.view" id="purchase_order_search_inherit">
        <field name="name">purchase.order.list.select.inherit</field>
        <field name="type">form</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.view_purchase_order_filter"/>
        <field name="arch" type="xml">
            <xpath expr="/search/group/filter[@string='Not Invoiced']" position="after">
             <filter icon="terp-gtk-jump-to-rtl" string="Requisition" domain="[('requisition_id','!=',False)]" separator="1" help="Purchase Orders with requisition"/>
            </xpath>
        </field>
    </record>
    <record model="ir.ui.view" id="view_purchase_requisition_form">
        <field name="name">purchase.requisition.form</field>
        <field name="type">form</field>
        <field name="model">purchase.requisition</field>
        <field name="arch" type="xml">
            <form string="Purchase Requisition">
                <group colspan="4" col="6">
                    <field name="name"/>
                    <field name="user_id"/>
                    <field name="exclusive"/>
                    <field name="date_start"/>
                    <field name="date_end"/>
                    <field name="origin"/>
                    <field name="warehouse_id" groups="base.group_extended" widget="selection"/>
                    <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                </group>
                <notebook colspan="4">
                    <page string="Products">
                        <field name="line_ids" colspan="4" nolabel="1">
                            <tree string="Products" editable="bottom">
                                <field name="product_id" on_change="onchange_product_id(product_id,product_uom_id)"/>
                                <field name="product_qty"/>
                                <field name="product_uom_id"/>
                            </tree>
                            <form string="Products">
                                <field name="product_id" />
                                <field name="product_qty"/>
                                <field name="product_uom_id" />
                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                            </form>

                        </field>
                    <separator colspan="4"/>
                    <group col="8" colspan="4">
                        <field name="state" select="1" readonly ="1"/>
                        <button name="tender_cancel" states="draft,in_progress" string="Cancel" type="object" icon="gtk-cancel" />
                        <button name="tender_in_progress" states="draft" string="Confirm" type="object" icon="gtk-apply" />
                        <button name="tender_reset" states="done,cancel" string="Reset to Draft" type="object" icon="gtk-convert" />
                        <button name="tender_done" states="in_progress" string="Done" type="object" icon="gtk-jump-to" />
                    </group>
                    </page>
                    <page string="Quotations">
                        <field colspan="4" name="purchase_ids" nolabel="1" mode="tree,form">
                            <tree string="Purchase Order">
                                <field name="name" string="Reference"/>
                                <field name="date_order" string="Order Date"/>
                                <field name="partner_id"/>
                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                                <field name="location_id"/>
                                <field name="minimum_planned_date"/>
                                <field name="origin"/>
                                <field name="state"/>
                                <button name="purchase_cancel" states="draft,confirmed,wait_auth" string="Cancel Purchase Order" icon="gtk-cancel"/>								
								<button name="purchase_confirm" states="draft" string="Confirm Purchase Order" icon="gtk-apply"/>
                                <button name="purchase_approve" states="confirmed" string="Approved by Supplier" icon="gtk-ok"/>
                            </tree>
                         </field>
                        <separator colspan="4" string=""/>
                         <group col="8" colspan="4">
                          <label colspan="6"  string=""/>
                        <button name="%(action_purchase_requisition_partner)d" string="Request a Quotation" type="action" icon="gtk-execute"
                           attrs="{'readonly': [('state', '=', 'done')]}" />
                        </group>
                   </page>
                    <page string="Notes">
                        <field name="description" colspan="4" nolabel="1"/>
                    </page>
                </notebook>
            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="view_purchase_requisition_tree">
        <field name="name">purchase.requisition.tree</field>
        <field name="type">tree</field>
        <field name="model">purchase.requisition</field>
        <field name="arch" type="xml">
            <tree colors="grey:state in ('done');red:date_end&lt;current_date and state not in ('done','cancel');black:date_end&gt;=current_date;" string="Purchase Requisition">
                <field name="name"/>
                <field name="user_id"/>
                <field name="date_start"/>
                <field name="date_end"/>
                <field name="origin"/>
                <field name="state"/>
            </tree>
        </field>
    </record>

    <record id="view_purchase_requisition_filter" model="ir.ui.view">
            <field name="name">purchase.requisition.list.select</field>
            <field name="model">purchase.requisition</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Purchase Requisition">
                 <group col='10' colspan='4'>
                    <filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Purchase Requisition"/>
                    <filter icon="terp-camera_test" string="In Progress" domain="[('state','=','in_progress')]" help="Purchase Requisition in negociation"/>
                    <filter icon="terp-dialog-close" string="Done" domain="[('state','=','done')]" help="Current Purchase Requisition"/>
                    <separator orientation="vertical"/>
                    <filter icon="terp-personal-" string="Unassigned"  domain="[('user_id','=', False)]" help="Unassigned  Requisition"/>
                    <field name="name"/>
                    <field name="user_id" />
                    <field name="exclusive" />
                </group>
                <newline/>
                  <group expand="0" string="Group By..." colspan="4" col="10" groups="base.group_extended">
                  	<filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
					<separator orientation="vertical"/>
                    <filter string="Origin" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'origin'}"/>
                    <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                    <separator orientation="vertical"/>
                    <filter string="Start Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_start'}"/>
                    <filter string="End Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_end'}"/>
                </group>
              </search>
            </field>
        </record>


    <record model="ir.actions.act_window" id="action_purchase_requisition">
        <field name="name">Purchase Requisitions</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">purchase.requisition</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{"search_default_create_uid":uid,'search_default_draft': 1}</field>
        <field name="search_view_id" ref="view_purchase_requisition_filter"/>
        <field name="help">A purchase requisition is the step before a request for quotation. In a purchase requisition (or purchase tender), you can record the products you need to buy and trigger the creation of RfQs to suppliers. After the negotiation, once you have reviewed all the supplier's offers, you can validate some and cancel others.</field>
    </record>

    <menuitem
        id="menu_purchase_requisition_pro_mgt"
        sequence="0"
        groups="base.group_extended"
        parent="purchase.menu_procurement_management"
        action="action_purchase_requisition"/>

    <record model="ir.ui.view" id="product_normal_form_view_inherit">
        <field name="name">product.form.inherit</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="supply_method" position="after">
                <group colspan="2" col="2" attrs="{'invisible': [('supply_method','&lt;&gt;','buy')]}">
                <field name="purchase_requisition"/>
                </group>
            </field>
        </field>
    </record>

    <record model="ir.ui.view" id="procurement_normal_form_view_inherit">
        <field name="name">procurement.form.inherit</field>
        <field name="type">form</field>
        <field name="model">procurement.order</field>
        <field name="inherit_id" ref="procurement.procurement_form_view"/>
        <field name="arch" type="xml">
             <xpath expr="/form/notebook/page/field[@name='close_move']" position="after">
                <field name="requisition_id"/>
            </xpath>
        </field>
    </record>
	<act_window
            domain="[('requisition_id', '=', active_id)]"
            id="act_res_partner_2_purchase_order"
            name="Purchase orders"
            res_model="purchase.order"
            src_model="purchase.requisition"/>
    
    </data>
</openerp>
