<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Extend stock.picking search view to add consumer group filters -->
    <record id="view_picking_internal_search_extended" model="ir.ui.view">
        <field name="name">stock.picking.search.extended</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_internal_search"/>
        <field name="arch" type="xml">
            <!-- Add consumer group search fields -->
            <field name="partner_id" position="after">
                <field name="consumer_group_id" string="Consumer Group"/>
                <field name="group_order_id" string="Group Order"/>
            </field>

            <!-- Add consumer group filters -->
            <filter name="internal" position="after">
                <separator/>
                <filter string="Home Delivery" name="filter_home_delivery"
                        domain="[('home_delivery', '=', True)]"/>
            </filter>

            <!-- Add group-by options for consumer groups -->
            <filter name="picking_type" position="after">
                <filter string="Consumer Group" name="group_by_consumer_group"
                        domain="[]" context="{'group_by': 'consumer_group_id'}"/>
                <filter string="Group Order" name="group_by_group_order"
                        domain="[]" context="{'group_by': 'group_order_id'}"/>
                <filter string="Pickup Date" name="group_by_pickup_date"
                        domain="[]" context="{'group_by': 'pickup_date'}"/>
            </filter>
        </field>
    </record>

    <!-- Extend stock.picking tree view to add hidden columns -->
    <record id="view_picking_tree_extended" model="ir.ui.view">
        <field name="name">stock.picking.tree.extended</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.vpicktree"/>
        <field name="arch" type="xml">
            <!-- Add consumer group and home delivery fields as optional columns -->
            <field name="partner_id" position="after">
                <field name="consumer_group_id" string="Consumer Group"
                       optional="hide"/>
                <field name="group_order_id" string="Group Order"
                       optional="hide"/>
                <field name="pickup_date" string="Pickup Date"
                       optional="hide"/>
                <field name="home_delivery" string="Home Delivery"
                       optional="hide" widget="boolean_toggle"/>
            </field>
        </field>
    </record>

    <!-- Extend stock.picking form view to show consumer group info -->
    <record id="view_picking_form_extended" model="ir.ui.view">
        <field name="name">stock.picking.form.extended</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_form"/>
        <field name="arch" type="xml">
            <!-- Add consumer group info in header after partner -->
            <field name="partner_id" position="after">
                <field name="consumer_group_id"
                       invisible="not consumer_group_id"
                       readonly="1"/>
                <field name="group_order_id"
                       invisible="not group_order_id"
                       readonly="1"/>
            </field>

            <!-- Add home delivery and pickup date in notebook page -->
            <xpath expr="//page[@name='note']" position="after">
                <page string="Consumer Group Info"
                      name="consumer_group_info"
                      invisible="not group_order_id">
                    <group>
                        <group>
                            <field name="home_delivery" readonly="1"/>
                            <field name="pickup_date" readonly="1"/>
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

</odoo>
