<?xml version="1.0"?>
<data inherit_id="stock.report_delivery_document">
        <!-- needs to be set before so elif directly follows if later on -->
        <xpath expr="//t[@name='has_packages']" position="before">
            <!-- get only the top level kits' (i.e. no subkit) move lines for easier mapping later on + we ignore subkit groupings-->
            <!-- note that move.name uses top level kit's product.template.display_name value instead of product.template.name -->
            <t t-set="has_kits" t-value="o.move_line_ids.filtered(lambda l: l.move_id.bom_line_id and l.move_id.bom_line_id.bom_id.type == 'phantom')"/>
        </xpath>
        <xpath expr="//t[@name='no_package_section']" position="before">
            <t t-set="has_kits" t-value="o.move_line_ids.filtered(lambda l: l.move_id.bom_line_id and l.move_id.bom_line_id.bom_id.type == 'phantom')"/>
            <t t-if="has_kits">
                <!-- print the products not in a package or kit first -->
                <t t-set="move_lines" t-value="move_lines.filtered(lambda m: not m.move_id.bom_line_id)"/>
            </t>
        </xpath>
        <xpath expr="//t[@name='no_package_move_lines']" position="inside">
            <t t-call="mrp.stock_report_delivery_kit_sections"/>
        </xpath>
        <xpath expr="//t[@name='has_packages']" position="after">
            <!-- Additional use case: group by kits when no packages exist and then apply use case 1. (serial/lot numbers used/printed) -->
            <t t-elif="has_kits and not has_packages">
                <t t-call="mrp.stock_report_delivery_kit_sections"/>
                <t t-call="mrp.stock_report_delivery_no_kit_section"/>
            </t>
        </xpath>
    </data>

    