<openerp>
   <data>

        <menuitem id="menu_sale_journal_config" name="Sale Journals"
            parent="base.menu_base_config" sequence="5" groups="base.group_system"/>

   <!--  sale journal invoice Type's Form  view -->

        <record model="ir.ui.view" id="view_sale_journal_invoice_type_form">
            <field name="name">sale_journal.invoice.type.form</field>
            <field name="model">sale_journal.invoice.type</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Invoice Type">
                    <group colspan="4" col="6">
                    <field name="name" select="1"/>
                    <field name="invoicing_method" select="1"/>
                    <field name="active" select="1"/>
                    </group>
                    <separator string="Notes" colspan="3"/>
                    <newline/>
                    <field name="note" colspan="3" nolabel="1"/>
                </form>
            </field>
        </record>

      <!--  sale journal invoice Type's tree  view -->

        <record model="ir.ui.view" id="view_sale_journal_invoice_type_tree">
            <field name="name">sale_journal.invoice.type.tree</field>
            <field name="model">sale_journal.invoice.type</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Invoice Type">
                    <field name="name"/>
                    <field name="invoicing_method"/>
                </tree>
            </field>
        </record>

      <!-- Action for sale journal invoice Type -->

        <record model="ir.actions.act_window" id="action_definition_journal_invoice_type">
            <field name="res_model">sale_journal.invoice.type</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

     <menuitem name="Invoicing Methods" id="menu_definition_journal_invoice_type" parent="menu_sale_journal_config" action="action_definition_journal_invoice_type"/>

    <!-- sale journal Form view  -->

        <record model="ir.ui.view" id="view_sale_journal_form">
            <field name="name">sale_journal.sale.journal.form</field>
            <field name="model">sale_journal.sale.journal</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Sales Journals">
                    <group colspan="4"    col="6">
                        <field name="name" select="1"/>
                        <field name="code" select="1"/>
                        <field name="user_id" select="1"/>
                        <field name="date" select="1"/>
                        <field name="date_created" select="1"/>
                        <field name="date_close" select="1"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Sales">
                            <field name="sale_stats_ids" colspan="4" nolabel="1">
                                <tree string="Sales">
                                    <field name="name"/>
                                    <field name="quantity"/>
                                    <field name="price_total"/>
                                    <field name="price_average"/>
                                    <field name="count"/>
                                    <field name="state"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Notes">
                            <field name="note" colspan="4" nolabel="1"/>
                        </page>
                    </notebook>
                    <field name="state"/>
                        <group col="6" colspan="2">
                            <button name="button_open" string="Open Journal" states="draft" type="object" icon="terp-check"/>
                            <button string="Confirm Sales" name="button_sale_confirm" states="open" type="object" icon="terp-camera_test"/>
                            <button name="button_close" string="Close Journal" states="confirm,open" type="object" icon="terp-dialog-close"/>
                            <button name="button_draft" string="Set to Draft" states="cancel" type="object" icon="gtk-convert"/>
                            <button string="Cancel Sales" name="button_sale_cancel" states="close,draft,open,confirm" type="object" icon="gtk-cancel"/>
                        </group>
                </form>
            </field>
        </record>

  <!-- Sale journal tree view -->

        <record model="ir.ui.view" id="view_sale_journal_tree">
            <field name="name">sale_journal.sale.journal.tree</field>
            <field name="model">sale_journal.sale.journal</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Sales Journals">
                    <field name="name" select="1"/>
                    <field name="code" select="1"/>
                    <field name="user_id" select="1"/>
                    <field name="date" select="1"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

    <!-- Sale journal search view -->

        <record model="ir.ui.view" id="view_sale_journal_search">
            <field name="name">sale_journal.sale.journal.search</field>
            <field name="model">sale_journal.sale.journal</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Sales by Journal">
                    <group col="8" colspan="4">
						<filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Sales Journal which are in draft state"/>
                        <filter icon="terp-check" string="Open" domain="[('state','=','open')]" help="Open Sales Journal"/>
                        <filter icon="terp-camera_test" string="Confirm" domain="[('state','=','confirm')]" help="Confirmed Sales Journal"/>
                        <filter icon="gtk-cancel" string="Cancel" domain="[('state','=','cancel')]" help="Sales Journal which are cancelled"/>
                        <filter icon="terp-dialog-close" string="Close" domain="[('state','=','done')]" help="Sales Journal which are closed"/>
                       <separator orientation="vertical"/>
                        <field name="name"/>
                        <field name="code"/>
                        <field name="user_id"/>
                        <field name="date"/>
                    </group>
                </search>
            </field>
        </record>

      <!-- Action for sale journal view -->

        <record model="ir.actions.act_window" id="action_definition_journal">
            <field name="res_model">sale_journal.sale.journal</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'search_default_user_id':uid}</field>
            <field name="search_view_id" ref="view_sale_journal_search"/>
        </record>


        <menuitem id="menu_definition_journal" name="Sales Journals" parent="menu_sale_journal_config"  action="action_definition_journal" sequence="70"/>

    <!-- Inherit sales order form view -->

        <record model="ir.ui.view" id="sale_journal_sale_order">
            <field name="name">sale.order.journal.view.form</field>
            <field name="type">form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                	<group colspan="2" col="2">
	                    <separator string="Journal" colspan="4"/>
	                    <field name="journal_id" select="1" widget="selection" domain="[('state','in', ('draft', 'open'))]"/>
	                    <field name="invoice_type_id" select="1" widget="selection"/>
                    </group>
                </field>
            </field>
        </record>

        <!-- Inherit sales order tree view-->

        <record model="ir.ui.view" id="sale_journal_sale_order_tree">
            <field name="name">sale.order.journal.view.tree</field>
            <field name="type">tree</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_tree" />
            <field name="arch" type="xml">
                <field name="state" position="after">
                    <field name="invoice_type_id"/>
                    <field name="journal_id"/>
                </field>
            </field>
        </record>

<!--  Inherit stock picking's form view  -->

        <record model="ir.ui.view" id="sale_journal_picking_order">
            <field name="name">stock.picking.journal.view.form</field>
            <field name="type">form</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_form" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                </field>
            </field>
        </record>

<!--  Inherit stock picking's tree view  -->

        <record model="ir.ui.view" id="sale_journal_picking_order_tree">
            <field name="name">stock.picking.journal.view.tree</field>
            <field name="type">tree</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.vpicktree" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                </field>
            </field>
        </record>

    <!--  Inherit stock picking delivery's form  view.-->

        <record model="ir.ui.view" id="sale_journal_picking_order_del">
            <field name="name">stock.picking.journal.view.form</field>
            <field name="type">form</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_delivery_form" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                </field>
            </field>
        </record>

    <!--  Inherit stock picking delivery's tree  view.-->

        <record model="ir.ui.view" id="sale_journal_picking_order_tree_del">
            <field name="name">stock.picking.journal.view.tree</field>
            <field name="type">tree</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_delivery_tree" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                </field>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_journal_picking_order_in">
            <field name="name">stock.picking.journal.view.form</field>
            <field name="type">form</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_in_form" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                </field>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_journal_picking_order_tree_in">
            <field name="name">stock.picking.journal.view.tree</field>
            <field name="type">tree</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_in_tree" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                </field>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_journal_picking_order_out">
            <field name="name">stock.picking.journal.view.form</field>
            <field name="type">form</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_out_form" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                </field>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_journal_picking_order_tree_out">
            <field name="name">stock.picking.journal.view.tree</field>
            <field name="type">tree</field>
            <field name="model">stock.picking</field>
            <field name="inherit_id" ref="stock.view_picking_out_tree" />
            <field name="arch" type="xml">
                <field name="origin" position="after">
                    <field name="journal_id" select="1"/>
                    <field name="invoice_type_id" select="1"/>
                    <field name="sale_journal_id" select="1"/>
                </field>
            </field>
        </record>

        <!-- Action of sale journal report in sale journal  -->

        <act_window name="Monthly sales"
            domain="[('journal_id', '=', active_id)]"
            res_model="sale.journal.report"
            src_model="sale_journal.sale.journal"
            id="act_sale_journal_sale_journal_2_sale_journal_sale_stats"/>

       <!-- Action  of stock picking  in picking journal  -->

        <act_window name="Assigned picking"
            domain="[('journal_id', '=', active_id),('state', '=', 'assigned')]"
            res_model="stock.picking"
            src_model="sale_journal.picking.journal"
            id="act_sale_journal_picking_journal_2_stock_picking_assigned"/>

      <!-- Action  of stock picking  in picking journal  -->

        <act_window name="Confirmed picking"
            domain="[('journal_id', '=', active_id),('state', '=', 'confirmed')]"
            res_model="stock.picking"
            src_model="sale_journal.picking.journal"
            id="act_sale_journal_picking_journal_2_stock_picking_confirmed"/>

     <!-- Action  of stock picking  in sale journal  -->

        <act_window name="Assigned picking"
            domain="[('sale_journal_id', '=', active_id),('state', '=', 'assigned')]"
            res_model="stock.picking"
            src_model="sale_journal.sale.journal"
            id="act_sale_journal_sale_journal_2_stock_picking_assigned"/>

    <!-- Action  of stock picking in sale journal -->

        <act_window name="Confirmed picking"
            domain="[('sale_journal_id', '=', active_id),('state', '=', 'confirmed')]"
            res_model="stock.picking"
            src_model="sale_journal.sale.journal"
            id="act_sale_journal_sale_journal_2_stock_picking_confirmed"/>

    <!-- Action of sale order in sale journal -->

        <act_window name="Draft sales"
            domain="[('journal_id', '=', active_id),('state', '=', 'draft')]"
            res_model="sale.order"
            src_model="sale_journal.sale.journal"
            id="act_sale_journal_sale_journal_2_sale_order_draft"/>

      <!-- Action  of sale order in sale journal -->

        <act_window name="Approved sales"
            domain="[('journal_id', '=', active_id),('state', '=', 'approved')]"
            res_model="sale.order"
            src_model="sale_journal.sale.journal"
            id="act_sale_journal_sale_journal_2_sale_order_approved"/>

        <record id="view_partner_property_form" model="ir.ui.view">
            <field name="name">res.partner.journal.property.form.inherit</field>
            <field name="model">res.partner</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <page string="Sales &amp; Purchases" position="inside">
                    <field name="property_invoice_type"/>
                </page>
            </field>
        </record>

    <!--=====================================================-->
    <!-- picking journal view-->
    <!--=====================================================    -->

        <record model="ir.ui.view" id="view_picking_journal_form">
            <field name="name">sale_journal.picking.journal.form</field>
            <field name="model">sale_journal.picking.journal</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Picking Journal">
                    <group colspan="4" col="6">
                        <field name="name" select="1"/>
                        <field name="code" select="1"/>
                        <field name="user_id" select="1"/>
                        <newline/>
                        <field name="date" select="1"/>
                        <field name="date_created" select="1"/>
                        <field name="date_close" select="1"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Picking">
                            <field name="picking_stats_ids" colspan="4" nolabel="1"/>
                        </page>
                        <page string="Notes">
                            <field name="note" colspan="4" nolabel="1"/>
                        </page>
                    </notebook>
                    <field name="state"/>
                        <group col="6" colspan="2">
                            <button name="button_open" string="Open Journal" states="draft" type="object" icon="terp-check"/>
                            <button string="Confirm Picking" name="button_picking_confirm" states="open" type="object" icon="terp-camera_test"/>
                            <button name="button_reset" string="Set to Draft" states="cancel" type="object" icon="gtk-convert"/>
                            <button name="button_close" string="Close Journal" states="confirm,open" type="object" icon="terp-dialog-close"/>
                            <button string="Cancel Picking" name="button_picking_cancel" states="close,draft,open,confirm" type="object" icon="gtk-cancel"/>
                        </group>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_picking_journal_tree">
            <field name="name">sale_journal.picking.journal.tree</field>
            <field name="model">sale_journal.picking.journal</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Picking Journal">
                    <field name="name"/>
                    <field name="code"/>
                    <field name="user_id"/>
                    <field name="date"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

       <!-- Picking journal tree view  -->

        <record model="ir.ui.view" id="view_picking_journal_search">
            <field name="name">sale_journal.picking.journal.search</field>
            <field name="model">sale_journal.picking.journal</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Picking Journals">
                    <group col="8" colspan="4">
                        <filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Picking Journals which are in draft state"/>
					   	<filter icon="terp-check" string="Open" domain="[('state','=','open')]" help="Open Picking Journals"/>
					   	<filter icon="gtk-cancel" string="Cancel" domain="[('state','=','cancel')]" help="Picking Journals which are cancelled"/>
					   	<filter icon="terp-dialog-close" string="Close" domain="[('state','=','done')]" help="Picking Journals which are closed"/>
                        <separator orientation="vertical"/>
                        <field name="name"/>
                        <field name="code"/>
                        <field name="user_id"/>
                        <field name="date"/>
                    </group>
                </search>
            </field>
        </record>

<!-- Action of Picking journals -->

        <record model="ir.actions.act_window" id="action_definition_picking_journal">
            <field name="name">Picking Journals</field>
            <field name="res_model">sale_journal.picking.journal</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'search_default_user_id':uid}</field>
            <field name="search_view_id" ref="view_picking_journal_search"/>
        </record>

        <menuitem name="Picking Journals" id="menu_definition_journal_picking" parent="stock.menu_warehouse_config" action="action_definition_picking_journal" groups="base.group_system"/>

        <record model="ir.actions.act_window" id="action_invoice_type_tree">
            <field name="name">Picking by invoice_method</field>
            <field name="res_model">sale_journal.invoice.type</field>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">tree</field>
        </record>

        <record model="ir.actions.act_window" id="action_invoice_type_picking_open">
            <field name="name">Picking to invoice</field>
            <field name="res_model">stock.picking</field>
            <field name="type">ir.actions.act_window</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('state','=','done'),('invoice_state','=','2binvoiced'),('invoice_type_id','=',active_id)]</field>
        </record>

        <record model="ir.values" id="ir_open_invoice_type">
            <field name="key2">tree_but_open</field>
            <field name="model">sale_journal.invoice.type</field>
            <field name="name">Picking to invoice</field>
            <field name="value" eval="'ir.actions.act_window,%d'%action_invoice_type_picking_open"/>
            <field name="object" eval="True"/>
        </record>

        <record id="view_picking_delivery_jorunal_search_form" model="ir.ui.view">
            <field name="name">stock.picking.journal.search</field>
            <field name="model">stock.picking</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="stock.view_stock_delivery_filter"/>
            <field name="arch" type="xml">
                <xpath expr="/search/group[@string='Group By...']/filter[@string='Partner']" position="after">
                   	<filter string="Picking Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                </xpath>
            </field>
        </record>

        <record id="view_picking_out_jorunal_search_form" model="ir.ui.view">
            <field name="name">stock.picking.journal.search</field>
            <field name="model">stock.picking</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="stock.view_picking_out_search"/>
            <field name="arch" type="xml">
                <xpath expr="/search/group[@string='Group By...']/filter[@string='Partner']" position="after">
                   	<filter string="Picking Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                </xpath>
            </field>
        </record>

        <record id="view_picking_in_jorunal_search_form" model="ir.ui.view">
            <field name="name">stock.picking.journal.search</field>
            <field name="model">stock.picking</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="stock.view_picking_in_search"/>
            <field name="arch" type="xml">
                <xpath expr="/search/group[@string='Group By...']/filter[@string='Partner']" position="after">
                   	<filter string="Picking Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                </xpath>
            </field>
        </record>

        <record id="view_picking_internal_jorunal_search_form" model="ir.ui.view">
            <field name="name">stock.picking.journal.search</field>
            <field name="model">stock.picking</field>
            <field name="type">search</field>
            <field name="inherit_id" ref="stock.view_picking_internal_search"/>
            <field name="arch" type="xml">
                <xpath expr="/search/group[@string='Group By...']/filter[@string='Origin']" position="after">
                   	<filter string="Picking Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                </xpath>
            </field>
        </record>


   </data>
</openerp>
