<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- CRM Lead Form View Inheritance -->
    <record id="crm_lead_view_form_inherit_adf" model="ir.ui.view">
        <field name="name">crm.lead.form.inherit.adf</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_lead_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//notebook" position="inside">
                
                <!-- Credit Application Tab -->
                <page string="Credit Application" name="credit_application" invisible="x_lead_type != 'credit_app'">
                    
                    <group string="Applicant Information">
                        <group string="Personal Details">
                            <field name="x_first_name"/>
                            <field name="x_last_name"/>
                            <field name="x_date_of_birth"/>
                            <field name="x_ssn"/>
                            <field name="x_dl_number"/>
                            <field name="x_dl_state"/>
                            <field name="x_dl_exp_date"/>
                        </group>
                        <group string="Contact Information">
                            <field name="x_email_address"/>
                            <field name="x_home_phone"/>
                            <field name="x_mobile_phone"/>
                        </group>
                    </group>
                    
                    <group string="Address &amp; Housing">
                        <group string="Address">
                            <field name="x_address"/>
                            <field name="x_city"/>
                            <field name="x_state"/>
                            <field name="x_zip"/>
                        </group>
                        <group string="Housing Details">
                            <field name="x_residence_type"/>
                            <field name="x_time_at_residence"/>
                            <field name="x_rent_mortgage"/>
                        </group>
                    </group>
                    
                    <group string="Employment Information">
                        <group string="Employer Details">
                            <field name="x_employer"/>
                            <field name="x_occupation"/>
                            <field name="x_work_phone"/>
                            <field name="x_time_on_job"/>
                            <field name="x_employer_address"/>
                            <field name="x_employer_city"/>
                        </group>
                        <group string="Income Details">
                            <field name="x_monthly_income" string="Stated Monthly Income"/>
                            <field name="x_hours_per_week"/>
                            <field name="x_hourly_pay"/>
                            <field name="x_regular_income" string="Regular Income" readonly="1"/>
                            <field name="x_overtime_income" string="Overtime Income" readonly="1"/>
                            <field name="x_calculated_income" string="Total Calculated" readonly="1"/>
                        </group>
                    </group>
                </page>
                
                <!-- Co-Applicant Tab -->
                <page string="Co-Applicant" name="co_applicant" invisible="x_lead_type != 'credit_app'">
                    <group string="Co-Applicant Information">
                        <group string="Personal Details">
                            <field name="x_co_applicant_first_name"/>
                            <field name="x_co_applicant_last_name"/>
                            <field name="x_co_applicant_dob"/>
                            <field name="x_co_applicant_ssn"/>
                            <field name="x_co_applicant_dl_number"/>
                            <field name="x_co_applicant_dl_state"/>
                            <field name="x_co_applicant_dl_exp_date"/>
                        </group>
                        <group string="Contact Information">
                            <field name="x_co_applicant_email"/>
                            <field name="x_co_applicant_home_phone"/>
                            <field name="x_co_applicant_mobile_phone"/>
                        </group>
                    </group>
                    
                    <group string="Address &amp; Housing">
                        <group string="Address">
                            <field name="x_co_applicant_address"/>
                            <field name="x_co_applicant_city"/>
                            <field name="x_co_applicant_state"/>
                            <field name="x_co_applicant_zip"/>
                        </group>
                        <group string="Housing Details">
                            <field name="x_co_applicant_residence_type"/>
                            <field name="x_co_applicant_time_at_residence"/>
                            <field name="x_co_applicant_rent_mortgage"/>
                        </group>
                    </group>
                    
                    <group string="Employment Information">
                        <group string="Employer Details">
                            <field name="x_co_applicant_employer"/>
                            <field name="x_co_applicant_occupation"/>
                            <field name="x_co_applicant_work_phone"/>
                            <field name="x_co_applicant_time_on_job"/>
                            <field name="x_co_applicant_employer_address"/>
                            <field name="x_co_applicant_employer_city"/>
                        </group>
                        <group string="Income Details">
                            <field name="x_co_applicant_monthly_income" string="Stated Monthly Income"/>
                            <field name="x_co_applicant_hours_per_week"/>
                            <field name="x_co_applicant_hourly_pay"/>
                            <field name="x_co_applicant_regular_income" string="Regular Income" readonly="1"/>
                            <field name="x_co_applicant_overtime_income" string="Overtime Income" readonly="1"/>
                            <field name="x_co_applicant_calculated_income" string="Total Calculated" readonly="1"/>
                        </group>
                    </group>
                </page>
                
                <!-- Enhanced Vehicle Information Tab -->
                <page string="Vehicle Information" name="vehicle_info">
                    <group>
                        <group string="Lead Classification">
                            <field name="x_lead_type"/>
                            <field name="x_lead_source"/>
                            <field name="x_customer_name"/>
                            <field name="x_preferred_contact"/>
                            <field name="x_request_date"/>
                        </group>
                        <group string="Vehicle Details">
                            <field name="x_vehicle_year"/>
                            <field name="x_vehicle_make"/>
                            <field name="x_vehicle_model"/>
                            <field name="x_vehicle_trim"/>
                            <field name="x_vehicle_vin"/>
                            <field name="x_vehicle_stock"/>
                            <field name="x_vehicle_mileage"/>
                            <field name="x_vehicle_color"/>
                        </group>
                    </group>
                    
                    <group string="Pricing Information">
                        <group string="Pricing">
                            <field name="x_vehicle_price"/>
                            <field name="x_vehicle_sale_price"/>
                            <field name="x_vehicle_down_total"/>
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <!-- Internal Notes Tab Enhancement for Credit Applications -->
    <record id="crm_lead_view_form_internal_notes_inherit" model="ir.ui.view">
        <field name="name">crm.lead.form.internal.notes.inherit</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_lead_view_form"/>
        <field name="arch" type="xml">
            <!-- Add lead classification after description -->
            <xpath expr="//field[@name='description']" position="after">
                <!-- Lead Classification (only visible for credit apps) -->
                <group string="Lead Classification" invisible="x_lead_type != 'credit_app'">
                    <field name="x_lead_type" string="Lead Type" readonly="1"/>
                    <field name="x_lead_source" string="Lead Source" readonly="1"/>
                    <field name="x_preferred_contact" string="Preferred Contact" readonly="1"/>
                    <field name="x_request_date" string="Request Date" readonly="1"/>
                </group>
            </xpath>
            
            <!-- Hide Extra Information tab for credit applications -->
            <xpath expr="//page[@name='extra']" position="attributes">
                <attribute name="invisible">x_lead_type == 'credit_app'</attribute>
            </xpath>
        </field>
    </record>

    <!-- CRM Lead Tree View Inheritance -->
    <record id="crm_lead_view_tree_inherit_adf" model="ir.ui.view">
        <field name="name">crm.lead.tree.inherit.adf</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_tree_view_leads"/>
        <field name="arch" type="xml">
            <field name="name" position="after">
                <field name="x_lead_type"/>
                <field name="x_customer_name"/>
                <field name="x_vehicle_year"/>
                <field name="x_vehicle_make"/>
                <field name="x_vehicle_model"/>
            </field>
        </field>
    </record>

	<!-- Search View Inheritance -->
<record id="crm_lead_view_search_inherit_adf" model="ir.ui.view">
    <field name="name">crm.lead.search.inherit.adf</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.view_crm_case_leads_filter"/>
    <field name="arch" type="xml">
        <field name="name" position="after">
            <field name="x_lead_type"/>
            <field name="x_customer_name"/>
            <field name="x_vehicle_vin"/>
            <field name="x_vehicle_stock"/>
        </field>
        <filter name="salesperson" position="after">
            <filter string="Lead Type" name="group_lead_type" context="{'group_by': 'x_lead_type'}"/>
            <filter string="Vehicle Make" name="group_vehicle_make" context="{'group_by': 'x_vehicle_make'}"/>
        </filter>
    </field>
</record>
</odoo>