<data priority="50">
    <xpath expr="//h2" position="before">
        <!-- Get all pickings without duplicates -->
        <t t-set="pickings" t-value="list(set(o.invoice_line_ids.picking_ids.filtered(lambda p: p.state != 'cancel')))"/>
        <!--<t t-set="pickings" t-value="list(set(o.invoice_line_ids.picking_ids))"/>-->
        <t t-set="pickings" t-value="sorted(pickings, key=lambda p: p.scheduled_date)"/>
        <!-- Store if has pickings -->
        <t t-set="has_pickings" t-value="len(pickings) &gt; 0"/>
        <!-- Store if has multiple pickings -->
        <t t-set="has_multiple_pickings" t-value="len(pickings) &gt; 1"/>
        <!-- Store if has lines without pickings -->
        <t t-set="has_lines_without_pickings" t-value="len(o.invoice_line_ids.filtered(lambda l: not l.picking_ids)) &gt; 0"/>
    </xpath>
    <xpath expr="//h2/span[1]" position="replace">
        <span t-if="o.move_type == 'out_invoice' and o.state == 'posted' and not has_multiple_pickings">Rechnung</span>
        <span t-if="o.move_type == 'out_invoice' and o.state == 'posted' and has_multiple_pickings">Sammelrechnung</span>
    </xpath>
    <xpath expr="//t[@t-foreach='lines']" position="replace">
        <!-- Add empty picking if there are lines without pickings -->
        <t t-if="not has_pickings or has_lines_without_pickings">
            <t t-set="null" t-value="pickings.append(False)"/>
        </t>
        <!--<p t-esc="pickings"/>-->
        <!-- <p t-esc="has_pickings"/> -->
        <!-- <p t-esc="has_multiple_pickings"/> -->
        <!-- <p t-esc="has_lines_without_pickings"/> -->
        <t t-foreach="pickings" t-as="picking">
            <tr t-if="has_pickings and picking" class="o_line_note">
                <td colspan="99" style="padding-top: 1rem;">
                    <strong>
                        <span>Lieferung </span>
                        <span t-esc="picking.name.replace('WH/OUT/','')"/>
                    </strong>
                    <!--<strong><span>Lieferung </span><span t-esc="picking.name.replace('WH/OUT/','')"/><span> / Bestellung </span><span t-esc="picking.group_id.name"/></strong>-->
                    <span> vom </span>
                    <span t-esc="picking.scheduled_date" t-options="{'widget': 'date'}"/>
                    <span>:</span>
                </td>
            </tr>
            <tr t-if="not picking" class="o_line_note">
                <td colspan="99" style="padding-top: 1rem;">
                    <strong>
                        <span>Weitere Positionen: </span>
                    </strong>
                </td>
            </tr>
            <t t-foreach="lines" t-as="line">
                <!-- Show line if picking is set and linked or not picking is set and line is unlinked  -->
                <t t-if="(picking and picking in line.picking_ids) or (not line.picking_ids and not picking)">
                    <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
                    <t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
                    <tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
                        <t t-if="not line.display_type" name="account_invoice_line_accountable">
                            <td name="account_invoice_line_name">
                                <span t-field="line.name" t-options="{'widget': 'text'}"/>
                            </td>
                            <td class="text-right">
                                <span t-field="line.quantity"/>
                                <span t-field="line.product_uom_id" groups="uom.group_uom"/>
                            </td>
                            <td t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                <span class="text-nowrap" t-field="line.price_unit"/>
                            </td>
                            <td t-if="display_discount" t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                <span class="text-nowrap" t-field="line.discount"/>
                            </td>
                            <td t-attf-class="text-left {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                                <span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))" id="line_tax_ids"/>
                            </td>
                            <td class="text-right o_price_total">
                                <span class="text-nowrap" t-field="line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
                                <span class="text-nowrap" t-field="line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
                            </td>
                        </t>
                        <t t-if="line.display_type == 'line_section'">
                            <td colspan="99">
                                <span t-field="line.name" t-options="{'widget': 'text'}"/>
                            </td>
                            <t t-set="current_section" t-value="line"/>
                            <t t-set="current_subtotal" t-value="0"/>
                        </t>
                        <t t-if="line.display_type == 'line_note'">
                            <td colspan="99">
                                <span t-field="line.name" t-options="{'widget': 'text'}"/>
                            </td>
                        </t>
                    </tr>
                    <t t-if="current_section and (line_last or lines[line_index+1].display_type == 'line_section')">
                        <tr class="is-subtotal text-right">
                            <td colspan="99">
                                <strong class="mr16">Subtotal</strong>
                                <span t-esc="current_subtotal" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: o.currency_id}"/>
                            </td>
                        </tr>
                    </t>
                </t>
            </t>
            <tr t-if="picking and picking.sale_id.note" class="o_line_note">
                <td colspan="99" style="padding-bottom: 1rem;">
                    <span t-esc="picking.sale_id.note"/>
                </td>
            </tr>
        </t>
    </xpath>
</data>
