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

        <record id="view_sale_shop_form_inherit" model="ir.ui.view">
            <field name="name">sale.shop.inherit.form</field>
            <field name="model">sale.shop</field>
            <field name="inherit_id" ref="sale.view_shop_form"/>
            <field name="arch" type="xml">
                <xpath expr="//group[@name='shop']" position="before">
                     <label for="warehouse_id" class="oe_edit_only"/>
                     <h2><field name="warehouse_id" required="1"/></h2>
                </xpath>
            </field>
        </record>

         <record id="view_shop_tree_inherit" model="ir.ui.view">
             <field name="name">sale.shop.sale.stock</field>
             <field name="model">sale.shop</field>
             <field name="inherit_id" ref="sale.view_shop_tree"/>
             <field name="arch" type="xml">
                 <field name="name" position="after">
                     <field name="warehouse_id"/>
                 </field>
             </field>
         </record>

        <menuitem action="sale.action_shop_form" id="menu_action_shop_form" parent="base.menu_base_config" sequence="35" groups="stock.group_locations"/>

        <record id="view_order_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form.sale.stock</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <data>
                   <xpath expr="//button[@name='invoice_corrected']" position="after">
                       <button name="ship_recreate" states="shipping_except" string="Recreate Delivery Order"/>
                       <button name="ship_corrected" states="shipping_except" string="Ignore Exception"/>
                   </xpath>
                   <xpath expr="//button[@name='action_view_invoice']" position="after">
                       <field name="picking_ids" invisible="1"/>
                       <button name="action_view_delivery" string="View Delivery Order" type="object" class="oe_highlight"
                           attrs="{'invisible': ['|','|','|',('picking_ids','=',False),('picking_ids','=',[]), ('state', 'not in', ('progress','manual')),('shipped','=',True)]}" groups="base.group_user"/>
                   </xpath>
                    <xpath expr="//button[@name='action_cancel']" position="after">
                        <button name="ship_cancel" states="shipping_except" string="Cancel Order"/>
                    </xpath>
                    <field name="state" position="attributes">
                        <attribute name="statusbar_colors" t-translate="off">{"shipping_except":"red","invoice_except":"red","waiting_date":"blue"}</attribute>
                    </field>
                   <field name="shop_id" position="replace">
                        <field name="shop_id" on_change="onchange_shop_id(shop_id)" widget="selection" groups="stock.group_locations"/>
                   </field>
                   <field name="product_id" position="replace">
                       <field name="product_id"
                       context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                       groups="base.group_user" 
                       on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,False,product_uos_qty,False,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False, context)"/>
                   </field>
                   <field name="product_uom_qty" position="replace">
                       <field context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                             name="product_uom_qty" class="oe_inline"
                           on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, product_packaging, parent.fiscal_position, True, context)"/>
                   </field>

                   <field name='invoiced' position="after">
                       <field name="shipped"/>
                       <field name="invoice_exists" invisible="1"/>
                   </field>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='type']" position="before">                   
                       <label for="delay"/>
                       <div>
                           <field name="delay" class="oe_inline"/> days
                       </div>
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='address_allotment_id']" position="after">
                       <field name="property_ids" widget="many2many_tags"
                            groups="sale.group_mrp_properties"/>
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='tax_id']" position="before">
                       <field name="product_packaging" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" on_change="product_packaging_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, parent.partner_id, product_packaging, True, context)" domain="[('product_id','=',product_id)]" groups="product.group_stock_packaging"  />
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/div/field[@name='invoice_lines']" position="after">
                       <label for="move_ids"/>
                       <field name="move_ids" widget="many2many"/>
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='sequence']" position="after">
                       <field name="delay" invisible="1"/>
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='tax_id']" position="after">
                       <field name="type" invisible="1"/>
                   </xpath>
                   <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='th_weight']" position="after">
                       <field name="product_packaging" invisible="1"/>
                   </xpath>
                   <xpath expr="//group[@name='sales_person']" position="before">
                        <group name="logistics">
                            <field name="incoterm" widget="selection" groups="base.group_user"/>
                            <field name="picking_policy" required="True"/>
                            <field name="order_policy" on_change="shipping_policy_change(order_policy)"/>
                            <field name="invoice_quantity" invisible="True"/>
                        </group>
                   </xpath>
                </data>
           </field>
        </record>

        <record id="view_res_partner_tree_type" model="ir.ui.view">
            <field name="name">res.partner.tree.inherit.type</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_tree"/>
            <field name="arch" type="xml">
                <field name="parent_id" position="after">
                    <field name="type" invisible="context.get('hide_type', 1)"/>
                </field>
            </field>
        </record>

        <!-- On the customer/supplier form if "Allow a different address for
        delivery and invoicing" is set add "Contact Details" in the more menu
        showing the list of contact with their types -->
        <act_window
            id="res_partner_rule_children"
            name="Contact Details"
            context="{'default_parent_id': active_id, 'hide_type': 0}"
            domain="[('parent_id','=',active_id)]"
            res_model="res.partner"
            src_model="res.partner"
            view_mode="tree,form,kanban"
            view_type="form"
            groups="sale.group_delivery_invoice_address"
            />

    </data>
</openerp>
