<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="name">sale.order.form</field>
        <field name="model">sale.order</field>
        <field name='inherit_id' ref="sale.view_order_form" />
        <field name='arch' type="xml">
            <button name="action_quotation_send" position="before">
                <button
                    type="object"
                    name="action_manual_delivery_wizard"
                    class="btn btn-primary"
                    string="Create Delivery"
                    context="{'active_model': 'sale.order', 'active_id': id, 'active_ids': [id]}"
                    invisible="not has_pending_delivery or not manual_delivery or state != 'sale'"
                />
            </button>
            <group name="sale_shipping" position="inside">
                <field name="manual_delivery" widget="boolean_toggle" />
                <field name="has_pending_delivery" invisible="0" />
            </group>
        </field>
    </record>
    <record id="view_order_line_tree" model="ir.ui.view">
        <field name="name">sale.order.line.tree</field>
        <field name="model">sale.order.line</field>
        <field name="inherit_id" ref="sale.view_order_line_tree" />
        <field name="arch" type="xml">
            <field name="qty_delivered" position="before">
                <field name="qty_procured" />
                <field name="qty_to_procure" />
            </field>
        </field>
    </record>
    <record id="view_sales_order_undelivered_line_filter" model="ir.ui.view">
        <field name="name">sale.order.undelivered.line</field>
        <field name="model">sale.order.line</field>
        <field name="arch" type="xml">
            <search string="Search Undelivered Lines">
                <field name="order_id" />
                <separator />
                <filter
                    string="Unplanned delivery"
                    name="filter_unplanned"
                    domain="[('qty_to_procure', '!=', 0), ('state', '=', 'sale')]"
                    help="Sales Order Lines that are confirmed, done or in exception state and no delivery is created to satisfy them"
                />
            </search>
        </field>
    </record>
    <record id="action_order_line_delivery_tree" model="ir.actions.act_window">
        <field name="name">Sale Lines to Deliver</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">sale.order.line</field>
        <field name="view_mode">list</field>
        <field name="search_view_id" ref="view_sales_order_undelivered_line_filter" />
        <field name="context">{"search_default_filter_unplanned":1}</field>
        <field name="filter" eval="True" />
        <field name="help" type="html">
            <p>Here is a list of each sales order line to be invoiced.</p>
        </field>
    </record>
    <menuitem
        id="menu_delivery_sales_order_lines"
        parent="stock.menu_stock_warehouse_mgmt"
        action="action_order_line_delivery_tree"
        sequence="99"
        groups="stock.group_stock_user"
    />
</odoo>
