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

<record model="ir.ui.view" id="crm_case_form_view_leads">
    <field name="name">Add NUTS fields</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.crm_lead_view_form" />
    <field name="arch" type="xml">
        <field name="website" position="before">
            <field
                    name="nuts1_id"
                    placeholder="NUTS L1"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts2_id"
                    placeholder="NUTS L2"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts3_id"
                    placeholder="NUTS L3"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts4_id"
                    placeholder="NUTS L4"
                    options='{"no_open": True, "no_create": True}'
                />
        </field>
        <xpath expr="//page[@name='lead']//field[@name='website']" position="before">
            <field
                    name="nuts1_id"
                    placeholder="NUTS L1"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts2_id"
                    placeholder="NUTS L2"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts3_id"
                    placeholder="NUTS L3"
                    options='{"no_open": True, "no_create": True}'
                />
            <field
                    name="nuts4_id"
                    placeholder="NUTS L4"
                    options='{"no_open": True, "no_create": True}'
                />
        </xpath>
    </field>
</record>

<record model="ir.ui.view" id="view_crm_case_leads_filter">
    <field name="name">Add NUTS fields for searching and grouping</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="country_id" position="after">
            <field name="nuts1_id" />
            <field name="nuts2_id" />
            <field name="nuts3_id" />
            <field name="nuts4_id" />
        </field>
        <group position="inside">
            <filter
                    name="nuts_l1"
                    string="NUTS L1"
                    domain="[]"
                    context="{'group_by': 'nuts1_id'}"
                />
            <filter
                    name="nuts_l2"
                    string="NUTS L2"
                    domain="[]"
                    context="{'group_by': 'nuts2_id'}"
                />
            <filter
                    name="nuts_l3"
                    string="NUTS L3"
                    domain="[]"
                    context="{'group_by': 'nuts3_id'}"
                />
            <filter
                    name="nuts_l4"
                    string="NUTS L4"
                    domain="[]"
                    context="{'group_by': 'nuts4_id'}"
                />
        </group>
    </field>
</record>

<record model="ir.ui.view" id="view_crm_case_opportunities_filter">
    <field name="name">Add NUTS fields for searching and grouping</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.view_crm_case_opportunities_filter" />
    <field name="arch" type="xml">
        <field name="team_id" position="after">
            <field name="nuts1_id" />
            <field name="nuts2_id" />
            <field name="nuts3_id" />
            <field name="nuts4_id" />
        </field>
        <group position="inside">
            <filter
                    name="nuts_l1"
                    string="NUTS L1"
                    domain="[]"
                    context="{'group_by': 'nuts1_id'}"
                />
            <filter
                    name="nuts_l2"
                    string="NUTS L2"
                    domain="[]"
                    context="{'group_by': 'nuts2_id'}"
                />
            <filter
                    name="nuts_l3"
                    string="NUTS L3"
                    domain="[]"
                    context="{'group_by': 'nuts3_id'}"
                />
            <filter
                    name="nuts_l4"
                    string="NUTS L4"
                    domain="[]"
                    context="{'group_by': 'nuts4_id'}"
                />
        </group>
    </field>
</record>

</odoo>
