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

    <!-- ════════════════════════════════════════════════════════
         Sale Order PDF — Shipping Information
         ════════════════════════════════════════════════════════ -->
    <template id="report_saleorder_shipping_info"
              inherit_id="sale.report_saleorder_document">
        <xpath expr="//div[@name='so_total_summary']" position="after">
            <t t-set="cp_shipments" t-value="doc.fusion_cp_shipment_ids.filtered(lambda s: s.status != 'cancelled')"/>
            <div t-if="cp_shipments" class="mt-4">
                <h5><strong>Shipping Information</strong></h5>
                <table class="table table-sm table-bordered">
                    <thead>
                        <tr>
                            <th>Tracking Number</th>
                            <th>Service</th>
                            <th class="text-end">Weight</th>
                            <th class="text-end">Cost</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr t-foreach="cp_shipments" t-as="shipment">
                            <td><span t-field="shipment.tracking_number"/></td>
                            <td><span t-field="shipment.service_type"/></td>
                            <td class="text-end">
                                <span t-field="shipment.weight"/> kg
                            </td>
                            <td class="text-end">
                                <span t-field="shipment.shipping_cost"
                                      t-options="{'widget': 'monetary', 'display_currency': shipment.currency_id}"/>
                            </td>
                            <td><span t-field="shipment.status"/></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </xpath>
    </template>

    <!-- ════════════════════════════════════════════════════════
         Invoice PDF — Shipping Information
         ════════════════════════════════════════════════════════ -->
    <template id="report_invoice_shipping_info"
              inherit_id="account.report_invoice_document">
        <xpath expr="//div[@id='payment_term']" position="before">
            <t t-set="sale_orders" t-value="o.line_ids.sale_line_ids.order_id"/>
            <t t-set="cp_shipments" t-value="sale_orders.mapped('fusion_cp_shipment_ids').filtered(lambda s: s.status != 'cancelled')" t-if="sale_orders"/>
            <div t-if="cp_shipments" class="mt-4">
                <h5><strong>Shipping Information</strong></h5>
                <table class="table table-sm table-bordered">
                    <thead>
                        <tr>
                            <th>Tracking Number</th>
                            <th>Service</th>
                            <th class="text-end">Weight</th>
                            <th class="text-end">Cost</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr t-foreach="cp_shipments" t-as="shipment">
                            <td><span t-field="shipment.tracking_number"/></td>
                            <td><span t-field="shipment.service_type"/></td>
                            <td class="text-end">
                                <span t-field="shipment.weight"/> kg
                            </td>
                            <td class="text-end">
                                <span t-field="shipment.shipping_cost"
                                      t-options="{'widget': 'monetary', 'display_currency': shipment.currency_id}"/>
                            </td>
                            <td><span t-field="shipment.status"/></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </xpath>
    </template>

</odoo>
