<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="view_purchase_order_graph">
            <field name="name">product.month.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Purchase Orders Statistics" type="bar">
                    <field name="product_id"/>
                    <field name="price_total" operator="+"/>
                </graph>
            </field>
        </record>

        <record id="view_purchase_order_tree" model="ir.ui.view">
            <field name="name">purchase.order.tree</field>
            <field name="model">purchase.report</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Purchase Orders Statistics">
                    <field name="date" invisible="1"/>
                    <field name="date_approve" invisible="1"/>
                    <field name="expected_date" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <field name="partner_id" invisible="1"/>
                    <field name="product_id" invisible="1"/>
                    <field name="product_uom" invisible="1"/>
                    <field name="day" invisible="1"/>
                    <field name="name" invisible="1"/>
                    <field name="month" invisible="1"/>
                    <field name="warehouse_id" invisible="1"/>
                    <field name="validator" invisible="1"/>
                    <field name="company_id" invisible="1"/>
                    <field name="state" invisible="1"/>
                    <field name="location_id" invisible="1"/>
                    <field name="nbr" sum="# of Lines"/>
                    <field name="quantity" sum="Quantity"/>
                    <field name="price_average" sum="Average Price"/>
                    <field name="price_total" sum="Total Price"/>
                    <field name="price_standard" sum="Products Value"/>
                    <field name="negociation" widget="progressbar"/>
                    <field name="delay" sum="Days to Validate"/>
                    <field name="delay_pass" sum="Days to Deliver"/>
                </tree>
            </field>
        </record>

        <record id="view_purchase_order_search" model="ir.ui.view">
        <field name="name">report.purchase.order.search</field>
        <field name="model">purchase.report</field>
        <field name="type">search</field>
        <field name="arch" type="xml">
            <search string="Purchase Orders">
            <group colspan="10" col="12">
                <filter icon="terp-go-year" string="  Year  "
                domain="[('date','&lt;=', time.strftime('%%Y-%%m-%%d')),('date','&gt;=',time.strftime('%%Y-01-01'))]"
                help="Order in current year"/>
                <filter icon="terp-go-month" string="   Month   "
                name="month"
                domain="[('date','&lt;=', time.strftime('%%Y-%%m-%%d')),('date','&gt;=',time.strftime('%%Y-%%m-01'))]"
                help="Order in  current month"/>
                <filter icon="terp-go-month"
                 string="    Month-1    "
                 separator="1"
                 domain="[('date','&lt;=', (datetime.date (int(time.strftime('%%Y')), datetime.date.today().month, 1) - datetime.timedelta (days = 1)).strftime('%%Y-%%m-%%d')),('date','&gt;',(datetime.date (int(time.strftime('%%Y')), datetime.date.today().month-1, 1)).strftime('%%Y-%%m-%%d'))]"
                 help="Order in last month"/>
                <separator orientation="vertical"/>
                <filter icon="terp-document-new"
                        string="Quotations"
                        name="quotes"
                        domain="[('state','=','draft')]"/>
                <filter icon="terp-accessories-archiver"
                        string="Orders"
                        name="orders"
                        domain="[('state','&lt;&gt;','draft'),('state','&lt;&gt;','cancel')]"/>
                <separator orientation="vertical"/>
                <field name="partner_id"/>
                <field name="product_id"/>
                </group>
                <newline/>
                <group expand="0" string="Extended filters..." colspan="10" col="12" groups="base.group_extended">
                    <field name="user_id"/>
                    <field name="validator"/>
                    <separator orientation="vertical"/>
                    <field name="location_id"/>
                    <field name="warehouse_id" widget="selection"/>
                    <separator orientation="vertical"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <newline/>
                    <field name="date"/>
                    <field name="date_approve"/>
                    <field name="expected_date"/>
                </group>
                <newline/>
                <group expand="1" string="Group By..." colspan="10" col="12">
                    <filter string="Supplier" name="group_partner_id" icon="terp-personal" context="{'group_by':'partner_id'}"/>
                    <filter string="Responsible" name="Responsible" icon="terp-personal" context="{'group_by':'user_id'}"/>
                    <filter string="Validated by" icon="terp-personal" context="{'group_by':'validator'}"/>
 					<separator orientation="vertical"/>
                    <filter string="Product" name="group_product_id" icon="terp-accessories-archiver" context="{'group_by':'product_id'}"/>
                    <filter string="Product UOM" name="group_product_uom" icon="terp-accessories-archiver" context="{'group_by':'product_uom'}"/>
                    <filter string="Warehouse" icon="terp-go-home" context="{'group_by':'warehouse_id'}" groups="base.group_extended"/>
                    <filter string="Destination" icon="terp-gtk-jump-to-ltr" context="{'group_by':'location_id'}"/>
                    <separator orientation="vertical"/>
                    <filter string="State" icon="terp-stock_effects-object-colorize" context="{'group_by':'state'}"/>
                    <separator orientation="vertical"/>
                    <filter string="Company" icon="terp-go-home" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
                    <separator orientation="vertical"/>
                    <filter string="Day" icon="terp-go-today" context="{'group_by':'day'}" help="Order of Day"/>
                    <filter string="Month" icon="terp-go-month" context="{'group_by':'month'}" help="Order of Month"/>
                    <filter string="Year" icon="terp-go-year" context="{'group_by':'name'}" help="Order of Year"/>
                </group>
            </search>
        </field>
    </record>

    <record model="ir.ui.view" id="view_purchase_order_qty_amount_graph">
            <field name="name">purchase.order.qty.amount.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Total Qty and Amount by month" type="bar">
                    <field name="month"/>
                    <field name="quantity" operator="+"/>
                    <field name="price_total" operator="+"/>
                </graph>
            </field>
        </record>

    <record model="ir.ui.view" id="view_purchase_order_by_user_graph">
            <field name="name">purchase.order.by.user.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Total Orders Lines by User per month" orientation="vertical" type="bar">
                    <field name="month" />
                    <field name="nbr" operator="+"/>
                    <field name="user_id" group="True" />
                </graph>
            </field>
        </record>


    <record id="action_purchase_order_report_all" model="ir.actions.act_window">
        <field name="name">Purchase Analysis</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,graph</field>
        <field name="view_id" ref="view_purchase_order_tree"></field>
        <field name="context">{'search_default_month':1,'search_default_group_partner_id':1,'search_default_group_product_id': 1, 'search_default_orders': 1, 'group_by_no_leaf':1,'group_by':[]}</field>
    </record>

    <record id="action_purchase_order_report_graph" model="ir.actions.act_window">
        <field name="name">Total Qty and Amount by month</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">graph,tree</field>
        <field name="view_id" ref="view_purchase_order_qty_amount_graph"></field>
    </record>

    <record id="action_purchase_order_by_user_all" model="ir.actions.act_window">
        <field name="name">Total Orders by User per month</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">graph,tree</field>
        <field name="view_id" ref="view_purchase_order_by_user_graph"></field>
    </record>


    <menuitem id="base.next_id_73" name="Reporting" parent="base.menu_purchase_root" sequence="8"/>
    <menuitem action="action_purchase_order_report_all" id="menu_action_purchase_order_report_all" parent="base.next_id_73" sequence="3"/>

    <record id="action_stock_move_report_po" model="ir.actions.act_window">
        <field name="name">Receptions Analysis</field>
        <field name="res_model">report.stock.move</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,graph</field>
        <field name="context">{'search_default_month':1, 'search_default_group_product':1, 'search_default_group_partner':1, 'search_default_done':1, 'search_default_in': 1, 'group_by':[], 'group_by_no_leaf':1}</field>
    </record>
    <menuitem action="action_stock_move_report_po" id="menu_action_stock_move_report_po" parent="base.next_id_73" sequence="8"/>

    <record model="ir.ui.view" id="view_purchase_by_supplier_graph">
            <field name="name">purchase.by.supplier.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Purchase by supplier" type="bar">
                    <field name="partner_id"/>
                    <field name="nbr" operator="+"/>
                </graph>
            </field>
        </record>
	<record id="action_purchase_by_supplier" model="ir.actions.act_window">
        <field name="name">Purchase by supplier</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree</field>
        <field name="domain">[('state','=','done'),('date','&gt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%Y-%m-%d'))]</field>
        <field name="context">{'group_by_no_leaf':1,'group_by':['partner_id']}</field>
        <field name="view_id" ref="view_purchase_by_supplier_graph"/>
    </record>

    <record model="ir.ui.view" id="view_total_price_by_product_by_state_graph">
            <field name="name">total.price.by.product.by.state.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Total price by product by state"  type="pie">
                    <field name="product_id"/>
                    <field name="state" group="True"/>
                    <field name="price_total" operator="+"/>

                </graph>
            </field>
        </record>
	<record id="action_total_price_by_product_by_state" model="ir.actions.act_window">
        <field name="name">Total price by product by state</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,graph</field>
        <field name="context">{'group_by_no_leaf':1,'group_by':['product_id','state']}</field>
        <field name="view_id" ref="view_total_price_by_product_by_state_graph"/>
    </record>

    <record model="ir.ui.view" id="view_qty_per_product_graph">
            <field name="name">qty.per.product.graph</field>
            <field name="model">purchase.report</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Qty. per product" type="bar">
                    <field name="product_id"/>
                    <field name="quantity" operator="+"/>
                </graph>
            </field>
        </record>
	<record id="action_qty_per_product" model="ir.actions.act_window">
        <field name="name">Qty. per product</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree</field>
        <field name="domain">[('state','=','done')]</field>
        <field name="context">{'group_by_no_leaf':1,'group_by':['product_id']}</field>
        <field name="view_id" ref="view_qty_per_product_graph"/>
    </record>

   	   <record model="ir.ui.view" id="view_po_per_month_tree">
            <field name="name">qty.per.product.tree</field>
            <field name="model">purchase.report</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Purchase order per month" >
                    <field name="month"/>
                    <field name="product_id" invisible="1"/>
                    <field name="nbr" operator="+"/>
                </tree>
            </field>
        </record>
	<record id="action_po_per_month_tree" model="ir.actions.act_window">
        <field name="name">Purchase order per month</field>
        <field name="res_model">purchase.report</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree</field>
        <field name="domain">[('date','&gt;',time.strftime('%Y-01-01 00:00:00')),('date','&lt;',time.strftime('%Y-12-31 23:59:59')),('state','=','done')]</field>
		<field name="context">{'group_by_no_leaf':1,'group_by':['month','product_id']}</field>
		<field name="view_id" ref="view_po_per_month_tree"/>
    </record>

  <record id="action_current_purchases" model="ir.actions.act_window">
        <field name="name">Current purchases</field>
        <field name="res_model">purchase.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="domain">[('state','in',('draft','confirmed'))]</field>
        <field name="view_id" ref="purchase.purchase_order_tree"/>
      </record>
    </data>
</openerp>
