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

    <!-- Add remote stock + brand columns to product list view -->
    <record id="view_product_template_list_inherit_sync" model="ir.ui.view">
        <field name="name">product.template.list.sync</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_tree_view"/>
        <field name="arch" type="xml">
            <xpath expr="//list" position="inside">
                <field name="x_fi_brand_ids" widget="many2many_tags" string="Brand(s)" optional="show"/>
                <field name="x_fi_margin_pct" string="Margin %" optional="show"/>
                <field name="remote_qty_available" string="Remote Stock" optional="show"
                       decoration-danger="remote_qty_available == 0 and has_remote_mapping"
                       decoration-success="remote_qty_available > 0"/>
                <field name="has_remote_mapping" column_invisible="1"/>
            </xpath>
        </field>
    </record>

    <!-- Add brand search/filter/group-by to product search view -->
    <record id="view_product_template_search_inherit_fi" model="ir.ui.view">
        <field name="name">product.template.search.fusion.inventory</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_search_view"/>
        <field name="arch" type="xml">
            <xpath expr="//search" position="inside">
                <field name="x_fi_brand_ids" string="Brand"/>
                <separator/>
                <filter string="Has Brand" name="has_brand"
                        domain="[('x_fi_brand_ids', '!=', False)]"/>
                <filter string="No Brand" name="no_brand"
                        domain="[('x_fi_brand_ids', '=', False)]"/>
                <separator/>
                <filter string="Brand" name="group_brand"
                        context="{'group_by': 'x_fi_brand_ids'}"/>
            </xpath>
        </field>
    </record>

    <!-- ═══════════════════════════════════════════════════════════
         Variant Form: margin, profit, override
         ═══════════════════════════════════════════════════════════ -->
    <record id="view_product_product_form_fi" model="ir.ui.view">
        <field name="name">product.product.form.fusion.inventory</field>
        <field name="model">product.product</field>
        <field name="inherit_id" ref="product.product_variant_easy_edit_view"/>
        <field name="arch" type="xml">

            <!-- Make Sale Price always read-only on variant form -->
            <xpath expr="//group[@name='pricing']//field[@name='lst_price']" position="attributes">
                <attribute name="readonly">1</attribute>
            </xpath>

            <xpath expr="//group[@name='pricing']//field[@name='cost_currency_id']" position="after">
                <label for="x_fi_shipping_cost" string="Shipping Cost"/>
                <div>
                    <field name="x_fi_shipping_cost" class="oe_inline"
                           widget="monetary"
                           options="{'currency_field': 'currency_id'}"/>
                </div>
                <label for="x_fi_variant_margin_pct" string="Margin"/>
                <div class="d-flex align-items-center">
                    <field name="x_fi_variant_margin_pct" class="oe_inline"
                           style="max-width: 80px;"/>
                    <span class="ms-1 text-muted">%</span>
                    <field name="x_fi_margin_override" class="ms-3"/>
                    <label for="x_fi_margin_override" string="Override"
                           class="ms-1 text-muted"/>
                </div>
                <label for="x_fi_variant_profit" string="Profit"/>
                <div>
                    <field name="x_fi_variant_profit" class="oe_inline"
                           widget="monetary" readonly="1"
                           options="{'currency_field': 'currency_id'}"/>
                </div>
            </xpath>
        </field>
    </record>

</odoo>
