<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!--
        Add Security Deposit fields to the Rental prices tab.
        These fields are defined on product.template in fusion_claims but
        only shown inside the Loaner Settings tab (invisible unless
        x_fc_can_be_loaned).  This view makes them accessible for ALL
        rental products via the standard Rental prices page.
    -->
    <record id="product_template_form_rental_deposit" model="ir.ui.view">
        <field name="name">product.template.form.rental.deposit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="sale_renting.product_template_form_view_rental"/>
        <field name="arch" type="xml">
            <xpath expr="//page[@name='pricing']//group[@name='extra_rental']" position="after">
                <group string="Security Deposit" name="security_deposit">
                    <group>
                        <field name="x_fc_security_deposit_type"/>
                        <field name="x_fc_security_deposit_amount"
                               widget="monetary"
                               invisible="x_fc_security_deposit_type != 'fixed'"/>
                        <field name="x_fc_security_deposit_percent"
                               invisible="x_fc_security_deposit_type != 'percentage'"/>
                    </group>
                    <group>
                        <div class="text-muted" style="padding-top:8px;">
                            <p class="mb-1"><strong>Fixed:</strong> A flat dollar amount charged as deposit.</p>
                            <p class="mb-0"><strong>Percentage:</strong> Calculated from the rental line price.</p>
                        </div>
                    </group>
                </group>
            </xpath>
        </field>
    </record>

    <!--
        Show security deposit badge on sale order lines so users can
        identify which line is the auto-generated deposit.
    -->
    <record id="sale_order_line_deposit_badge" model="ir.ui.view">
        <field name="name">sale.order.line.deposit.badge</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale_renting.rental_order_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='order_line']//list//field[@name='qty_returned']" position="before">
                <field name="is_security_deposit" column_invisible="not parent.is_rental_order"
                       widget="boolean_toggle" readonly="1" optional="show"/>
            </xpath>
        </field>
    </record>

</odoo>
