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

    <!-- Brand Form View -->
    <record id="view_product_brand_form" model="ir.ui.view">
        <field name="name">product.brand.form</field>
        <field name="model">product.brand</field>
        <field name="arch" type="xml">
            <form string="Brand">
                <sheet>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger"
                            invisible="active"/>
                    <field name="active" invisible="1"/>
                    <div class="oe_button_box" name="button_box">
                        <button class="oe_stat_button" name="action_view_products"
                                type="object" icon="fa-cube">
                            <field string="Products" name="product_count" widget="statinfo"/>
                        </button>
                        <button class="oe_stat_button" name="action_view_sub_brands"
                                type="object" icon="fa-sitemap"
                                invisible="child_count == 0">
                            <field string="Sub-Brands" name="child_count" widget="statinfo"/>
                        </button>
                    </div>
                    <field name="logo" widget="image" class="oe_avatar"
                           options="{'convert_to_webp': True, 'preview_image': 'logo'}"/>
                    <div class="oe_title">
                        <label for="name" string="Brand Name"/>
                        <h1><field name="name" placeholder="e.g. Invacare"/></h1>
                    </div>
                    <group>
                        <group string="Manufacturer / Vendor">
                            <field name="partner_id"/>
                            <field name="parent_id"
                                   options="{'no_create': True}"
                                   domain="[('id', '!=', id)]"/>
                        </group>
                        <group string="Default Pricing">
                            <label for="primary_discount_pct" string="Primary Discount"/>
                            <div class="d-flex align-items-center">
                                <field name="primary_discount_pct" class="oe_inline"
                                       style="max-width: 80px;"/>
                                <span class="ms-1 text-muted">%</span>
                            </div>
                            <label for="secondary_discount_pct" string="Secondary Discount"/>
                            <div class="d-flex align-items-center">
                                <field name="secondary_discount_pct" class="oe_inline"
                                       style="max-width: 80px;"/>
                                <span class="ms-1 text-muted">%</span>
                            </div>
                            <label for="net_discount_pct" string="Effective Discount"/>
                            <div class="d-flex align-items-center">
                                <field name="net_discount_pct" class="oe_inline fw-bold"
                                       style="max-width: 80px;"/>
                                <span class="ms-1 text-muted">%</span>
                            </div>
                        </group>
                    </group>
                    <notebook>
                        <page string="Pricing Rules" name="pricing_rules">
                            <field name="pricing_rule_ids">
                                <list editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="name"/>
                                    <field name="apply_on"/>
                                    <field name="categ_id"
                                           column_invisible="True"
                                           invisible="apply_on != 'category'"/>
                                    <field name="product_tmpl_id"
                                           column_invisible="True"
                                           invisible="apply_on != 'product'"/>
                                    <field name="pricing_method"/>
                                    <field name="primary_discount_pct" string="Primary %"
                                           invisible="pricing_method != 'tiered_pct'"/>
                                    <field name="secondary_discount_pct" string="Secondary %"
                                           invisible="pricing_method != 'tiered_pct'"/>
                                    <field name="flat_discount_pct" string="Discount %"
                                           invisible="pricing_method != 'flat_pct'"/>
                                    <field name="fixed_rebate_amount" string="Rebate $"
                                           invisible="pricing_method != 'fixed_rebate'"/>
                                    <field name="fixed_cost_price" string="Cost $"
                                           invisible="pricing_method != 'fixed_cost'"/>
                                    <field name="net_discount_pct" string="Effective %"/>
                                </list>
                            </field>
                        </page>
                        <page string="Sub-Brands" name="sub_brands">
                            <field name="child_ids">
                                <list>
                                    <field name="logo" widget="image"
                                           options="{'size': [32, 32]}" class="p-0"/>
                                    <field name="name"/>
                                    <field name="partner_id"/>
                                    <field name="primary_discount_pct" string="Primary %"/>
                                    <field name="secondary_discount_pct" string="Secondary %"/>
                                    <field name="net_discount_pct" string="Effective %"/>
                                    <field name="product_count" string="Products"/>
                                </list>
                            </field>
                        </page>
                        <page string="Notes" name="notes">
                            <field name="notes" nolabel="1"
                                   placeholder="Internal notes about the pricing arrangement with this brand..."/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Brand List View -->
    <record id="view_product_brand_list" model="ir.ui.view">
        <field name="name">product.brand.list</field>
        <field name="model">product.brand</field>
        <field name="arch" type="xml">
            <list string="Brands">
                <field name="logo" widget="image" options="{'size': [32, 32]}" class="p-0"/>
                <field name="name"/>
                <field name="parent_id" optional="show"/>
                <field name="partner_id"/>
                <field name="primary_discount_pct" string="Primary %"/>
                <field name="secondary_discount_pct" string="Secondary %"/>
                <field name="net_discount_pct" string="Effective %"/>
                <field name="product_count" string="Products"/>
            </list>
        </field>
    </record>

    <!-- Brand Search View -->
    <record id="view_product_brand_search" model="ir.ui.view">
        <field name="name">product.brand.search</field>
        <field name="model">product.brand</field>
        <field name="arch" type="xml">
            <search string="Brands">
                <field name="name" string="Brand Name"/>
                <field name="partner_id" string="Vendor"/>
                <field name="parent_id" string="Parent Brand"/>
                <separator/>
                <filter string="Top-Level Brands" name="top_level"
                        domain="[('parent_id', '=', False)]"/>
                <filter string="Sub-Brands" name="sub_brands"
                        domain="[('parent_id', '!=', False)]"/>
                <filter string="Has Pricing Rules" name="has_rules"
                        domain="[('pricing_rule_ids', '!=', False)]"/>
                <filter string="Has Pricing" name="has_pricing"
                        domain="[('primary_discount_pct', '&gt;', 0)]"/>
                <filter string="Archived" name="archived"
                        domain="[('active', '=', False)]"/>
                <separator/>
                <filter string="Parent Brand" name="group_parent"
                        context="{'group_by': 'parent_id'}"/>
                <filter string="Vendor" name="group_vendor"
                        context="{'group_by': 'partner_id'}"/>
            </search>
        </field>
    </record>

    <!-- Brand Action -->
    <record id="action_product_brand" model="ir.actions.act_window">
        <field name="name">Brands / Vendors</field>
        <field name="res_model">product.brand</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first brand
            </p>
            <p>
                Brands link products to manufacturers and define tiered pricing
                structures. Use pricing rules for category-specific or
                product-specific overrides.
            </p>
        </field>
    </record>

</odoo>
