<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record id="view_order_form_inherit_delivery_state" 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">
            <field name="state" position="before">
                <button
                    name="action_force_delivery_state"
                    type="object"
                    string="Force delivery done"
                    invisible="force_delivery_state or delivery_status == 'full' or state != 'sale' or not locked"
                />
                <button
                    name="action_unforce_delivery_state"
                    type="object"
                    string="Unforce delivery done"
                    invisible="not force_delivery_state or state != 'sale' or not locked"
                />
            </field>
            <group name="sale_shipping" position="inside">
                <field name="delivery_status" invisible="state != 'sale'" />
                <field name="force_delivery_state" invisible="1" />
            </group>
            <xpath expr="//field[@name='order_line']//list" position="inside">
                <field name="skip_sale_delivery_state" optional="hide" />
            </xpath>
        </field>
    </record>

    <record id="view_order_tree_inherit_delivery_status" model="ir.ui.view">
        <field name="name">sale.order.tree</field>
        <field name="inherit_id" ref="sale.view_order_tree" />
        <field name="model">sale.order</field>
        <field name="arch" type="xml">
            <field name="invoice_status" position="before">
                <field
                    name="delivery_status"
                    widget="badge"
                    optional="hide"
                    decoration-info="delivery_status == 'pending'"
                    decoration-warning="delivery_status in ('partial', 'started')"
                    decoration-success="delivery_status == 'full'"
                />
            </field>
        </field>
    </record>

    <record
        id="sale_order_view_search_inherit_sale_inherit_delivery_status"
        model="ir.ui.view"
    >
        <field name="name">sale.order.search</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.sale_order_view_search_inherit_sale" />
        <field name="arch" type="xml">
            <filter name="order_date" position="after">
                <separator />
                <filter
                    string="Pending Deliveries"
                    name="filter_delivery_status_pending"
                    domain="[('delivery_status','in',['pending', 'started', 'partial'])]"
                />
            </filter>
            <filter name="order_month" position="after">
                <filter
                    string="Delivery Status"
                    name="delivery_status"
                    context="{'group_by': 'delivery_status'}"
                />
            </filter>
        </field>
    </record>
</odoo>
