<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Moduon Team S.L.
     License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
    <record id="view_order_form_inherit_customer_deposit" model="ir.ui.view">
        <field name="name">Sale Order Customer Deposits</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">
            <xpath expr="//div[@name='button_box']" position="inside">
                <button
                    name="action_view_customer_deposits"
                    type="object"
                    class="oe_stat_button"
                    icon="fa-cubes"
                    attrs="{'invisible': [('customer_deposit_count', '=', 0)]}"
                    groups="stock.group_tracking_owner"
                >
                    <field
                        name="customer_deposit_count"
                        widget="statinfo"
                        string="Deposits"
                    />
                </button>
            </xpath>
            <xpath expr="//field[@name='payment_term_id']" position="after">
                <field name="can_customer_deposit" invisible="1" />
                <field name="customer_deposit_count" invisible="1" />
                <field
                    name="customer_deposit"
                    widget="boolean_toggle"
                    attrs="{'invisible': ['|', ('partner_id', '=', False), ('can_customer_deposit', '=', False)], 'readonly': [('state', 'not in', ('draft', 'sent'))]}"
                    groups="stock.group_tracking_owner"
                />
            </xpath>
            <xpath
                expr="//field[@name='order_line']/tree//field[@name='product_uom']"
                position="before"
            >
                <field name="deposit_available_qty" invisible="1" />
                <field name="deposit_allowed_qty" invisible="1" />
                <button
                    name="action_view_customer_deposits"
                    type="object"
                    icon="fa-cubes text-primary"
                    title="Customer Deposits"
                    width="20px"
                    aria-label="Customer Deposits"
                    attrs="{'invisible': ['|', ('deposit_available_qty', '&lt;=', 0), ('deposit_allowed_qty', '&lt;', 0)], 'column_invisible': ['|', ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '=', 0)]}"
                />
                <button
                    name="action_view_customer_deposits"
                    type="object"
                    icon="fa-cubes text-danger"
                    title="Customer Deposits"
                    width="20px"
                    aria-label="Customer Deposits"
                    attrs="{'invisible': ['|', ('deposit_available_qty', '&lt;=', 0),('deposit_allowed_qty', '&gt;=', 0)], 'column_invisible': ['|', ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '=', 0)]}"
                    groups="stock.group_tracking_owner,stock.group_stock_user"
                />
            </xpath>
            <xpath
                expr="///page/field[@name='order_line']/form/group/group/field[@name='price_unit']"
                position="before"
            >

                <label
                    for="deposit_available_qty"
                    string="Deposit Available Qty"
                    attrs="{'invisible': ['|', '|', ('deposit_available_qty', '&lt;=', 0), ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '=', 0)]}"
                    groups="stock.group_tracking_owner"
                />
                <div
                    class="o_row"
                    attrs="{'invisible': ['|', '|', ('deposit_available_qty', '&lt;=', 0), ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '=', 0)]}"
                    groups="stock.group_tracking_owner"
                >
                    <field
                        name="deposit_available_qty"
                        class="oe_inline"
                        decoration-info="deposit_available_qty &gt;= product_uom_qty"
                        decoration-danger="deposit_available_qty &lt; product_uom_qty"
                        attrs="{'invisible': [('deposit_available_qty', '&lt;=', 0)], 'column_invisible': ['|', ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '=', 0)]}"
                    />
                    <field name="deposit_allowed_qty" invisible="1" />
                    <button
                        name="action_view_customer_deposits"
                        type="object"
                        class="oe_inline"
                        icon="fa-cubes"
                        title="Customer Deposits"
                        width="0.1"
                        aria-label="Customer Deposits"
                        attrs="{'invisible': ['|', ('deposit_available_qty', '&lt;=', 0), ('deposit_allowed_qty', '&lt;', 0)], 'column_invisible': ['|', ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '&lt;=', 0)]}"
                        groups="stock.group_tracking_owner"
                    />
                <button
                        name="action_view_customer_deposits"
                        type="object"
                        icon="fa-cubes"
                        class="text-danger"
                        title="Customer Deposits"
                        width="0.1"
                        aria-label="Customer Deposits"
                        attrs="{'invisible': ['|', ('deposit_available_qty', '&lt;=', 0),('deposit_allowed_qty', '&gt;=', 0)], 'column_invisible': ['|', ('parent.state', 'not in', ('draft', 'sent')), ('parent.customer_deposit_count', '&lt;=', 0)]}"
                        groups="stock.group_tracking_owner"
                    />
                </div>
            </xpath>
        </field>
    </record>
    <record
        id="view_sales_order_filter_inherit_stock_customer_deposit"
        model="ir.ui.view"
    >
        <field name="name">Sale Order Search Customer Deposit</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_sales_order_filter" />
        <field name="arch" type="xml">
            <xpath expr="//filter[@name='my_sale_orders_filter']" position="after">
                <separator />
                <filter
                    name="deposits"
                    string="Customer Deposits"
                    domain="[('customer_deposit', '=', True)]"
                />
            </xpath>
        </field>
    </record>
</odoo>
